Skip to content

Commit 58f9aa4

Browse files
Tests: Fix always succeeding XCTAssertAsyncNoThrow (#8026)
The autoclosure expression `{ throw error }` just creates a closure that won't be executed. It leads to the test always succeeding even if the `expression` throws an error. Fortunately, I didn't find any issue to enable the assertion except for a single case (ab1e784)
1 parent e08708e commit 58f9aa4

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Fixtures/Miscellaneous/CheckTestLibraryEnvironmentVariable/Tests/CheckTestLibraryEnvironmentVariableTests/CheckTestLibraryEnvironmentVariableTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import XCTest
22

33
final class CheckTestLibraryEnvironmentVariableTests: XCTestCase {
44
func testEnviromentVariable() throws {
5-
let envvar = ProcessInfo.processInfo.environment["SWIFT_PM_TEST_LIBRARY"]
6-
XCTAssertEqual(envvar, "XCTest")
5+
let envvar = ProcessInfo.processInfo.environment["SWIFT_TESTING_ENABLED"]
6+
XCTAssertEqual(envvar, "0")
77
}
88
}

Sources/_InternalTestSupport/XCTAssertHelpers.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ package func XCTAssertAsyncNoThrow<T>(
7474
do {
7575
_ = try await expression()
7676
} catch {
77-
XCTAssertNoThrow({ throw error }, message(), file: file, line: line)
77+
XCTAssertNoThrow(try { throw error }(), message(), file: file, line: line)
7878
}
7979
}
8080

Tests/CommandsTests/TestCommandTests.swift

+3
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,14 @@ final class TestCommandTests: CommandsTestCase {
327327
}
328328
#endif
329329

330+
#if os(macOS)
331+
// "SWIFT_TESTING_ENABLED" is set only on macOS, skip the check on other platforms.
330332
func testLibraryEnvironmentVariable() async throws {
331333
try await fixture(name: "Miscellaneous/CheckTestLibraryEnvironmentVariable") { fixturePath in
332334
await XCTAssertAsyncNoThrow(try await SwiftPM.Test.execute(packagePath: fixturePath))
333335
}
334336
}
337+
#endif
335338

336339
func testXCTestOnlyDoesNotLogAboutNoMatchingTests() async throws {
337340
try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { fixturePath in

0 commit comments

Comments
 (0)