I'm trying to test an API I'm writing with Structured Concurrency. I prefer to run my tests with continueAfterFailure = false so that I may establish preconditions on my tests. At the moment my test is:
func testRssUrl() async throws {
self.continueAfterFailure = false
let xml = PodcastXml.url(url)
let feed = try await xml.feed
let rssFeed: RSSFeed? = feed.rssFeed
XCTAssertNil(rssFeed) // Included for this sample
XCTAssertNotNil(rssFeed)
validate(zebraFeed: rssFeed!)
}
My expectation of Swift Concurrency is that the try await should hold the method, until xml.feed resolves to a value or throws. Either of the XCTAssertNil or XCTAssertNotNil should fail (in the actual test, I'm not using NotNil). As written, between the two asserts and the try, validate(zebraFeed: ) should never be called because of continueAfterFailure.
Yet it is. The test still fails because XCTAssertNil is failing, which is my actual expectation. Test execution should also be stopping there.
What am I missing?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm looking to construct a custom logger API. For example:
log.verbose(Date(), "Begun process")
(That's contrived example, the point being some object and a message. I will then be manipulating both.)
Within my Log object I then want to transform the date value and the message into a final log message. "Nanoseconds: 9790324:: Begun process". If I was working with strings, it would be a pretty simple issue. But I'm not. It looks like Logger, which actually does the logging takes in a OSLogMessage which I cannot instantiate and cannot pass by value or reference. Even if I had just:
func verbose(_ date: Date, _ message: OSLogInterpolation) {
log(date: Date, level: .info, message: message)
}
func info(_ date: Date, _ message: OSLogInterpolation) {
log(date: Date, level: .default, message: message)
}
private func log(date: Date, level: OSLogType, message: OSLogInterpolation) {
// Neither of these work
log.log(level: level, message)
log.log(level: level, OSLogMessage(interpolation: message))
}
Ideally what I'd like is:
private func log(date: Date, level: OSLogType, message: OSLogInterpolation) {
let interpolation = "Nanoseconds: \(date.getNanoseconds):: " + message
log.log(level: level, OSLogMessage(interpolation: interpolation))
}
With the idea being that OSLogMessage is still respecting any privacy notices on the interpolation.