Problem getting Expectation objects (AI slop)

This is from an Xcode generated file.

var values: [String] = []
let exp = Expectation()
let c = pub.filter { $0 != nil }.map { $0! }.sink(

The second line gives an error: "'Expectation' cannot be constructed because it has no accessible initializers". My best guess that Expectation objects come from some other Apple Swift Testing function, but I don't know where.

Answered by DTS Engineer in 872560022

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

So I have to convert the Expectation initializers with #expect calls, right.

Honestly, I’m not sure what you’re actually trying to do here. In general:

  • If you want to test synchronous and asynchronous Swift routines, use the #expect macro. For example:

    @Test func example() async throws {
        #expect(calculateAnswer() == 42)
        #expect(await calculateAnswerAsync() == 42)
    }
    

    See Expectations and confirmations for more on that.

  • If you want to test asynchronous stuff that’s not a simple async routine, use a confirmation. See Testing asynchronous code.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I’m not sure what you’re asking for here. Are you trying to report a bug against Xcode? Or trying to work out how to use expectation-based tests in Swift Testing?

If it’s the former, I recommend that you do that officially, as explained in Bug Reporting: How and Why? And please post your bug number, just for the record.

If it’s the latter, see Expectations and confirmations.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

So I have to convert the Expectation initializers with #expect calls, right.

Honestly, I’m not sure what you’re actually trying to do here. In general:

  • If you want to test synchronous and asynchronous Swift routines, use the #expect macro. For example:

    @Test func example() async throws {
        #expect(calculateAnswer() == 42)
        #expect(await calculateAnswerAsync() == 42)
    }
    

    See Expectations and confirmations for more on that.

  • If you want to test asynchronous stuff that’s not a simple async routine, use a confirmation. See Testing asynchronous code.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Problem getting Expectation objects (AI slop)
 
 
Q