Skip to content

Commit

Permalink
tests: silence debug output, simplify and tighten checks
Browse files Browse the repository at this point in the history
Use the `assertDriverDiagnostics` helper to ensure that all the emitted
diagnostics are verified. Remove the debug printing and output to the
logs. This is no longer necessary as we will verify that any additional
diagnostics emitted are checked and the helper will render the missed or
non-matching diagnostics allowing easy triaging of the failures in CI.
  • Loading branch information
compnerd committed Jan 17, 2025
1 parent 9d33dc3 commit 7f5c25b
Showing 1 changed file with 39 additions and 43 deletions.
82 changes: 39 additions & 43 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2216,55 +2216,51 @@ final class ExplicitModuleBuildTests: XCTestCase {

// Detailed explain (all possible paths)
do {
var driver = try Driver(args: ["swiftc",
"-I", cHeadersPath.nativePathString(escaped: true),
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
"-explicit-module-build",
"-module-cache-path", moduleCachePath.nativePathString(escaped: true),
"-working-directory", path.nativePathString(escaped: true),
"-explain-module-dependency-detailed", "A",
main.nativePathString(escaped: true)] + sdkArgumentsForTesting)
let jobs = try driver.planBuild()
try driver.run(jobs: jobs)
XCTAssertTrue(!driver.diagnosticEngine.diagnostics.isEmpty)
XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .remark &&
$0.message.text == "Module 'testTraceDependency' depends on 'A'"})

for diag in driver.diagnosticEngine.diagnostics {
print(diag.behavior)
print(diag.message)
try assertDriverDiagnostics(args: [
"swiftc",
"-I", cHeadersPath.nativePathString(escaped: true),
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
"-explicit-module-build",
"-module-cache-path", moduleCachePath.nativePathString(escaped: true),
"-working-directory", path.nativePathString(escaped: true),
"-explain-module-dependency-detailed", "A",
main.nativePathString(escaped: true)
] + sdkArgumentsForTesting) { driver, diagnostics in
diagnostics.forbidUnexpected(.error, .warning, .note, .remark)

let jobs = try driver.planBuild()
try driver.run(jobs: jobs)

diagnostics.expect(.remark("Module 'testTraceDependency' depends on 'A'"))
diagnostics.expect(.note("[testTraceDependency] -> [A] -> [A](ObjC)"))
diagnostics.expect(.note("[testTraceDependency] -> [C](ObjC) -> [B](ObjC) -> [A](ObjC)"))
}
XCTAssertEqual(driver.diagnosticEngine.diagnostics.filter { $0.behavior == .note}.count, 2)
XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .note &&
$0.message.text == "[testTraceDependency] -> [A] -> [A](ObjC)"})
XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .note &&
$0.message.text == "[testTraceDependency] -> [C](ObjC) -> [B](ObjC) -> [A](ObjC)"})
}

// Simple explain (first available path)
do {
var driver = try Driver(args: ["swiftc",
"-I", cHeadersPath.nativePathString(escaped: true),
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
"-explicit-module-build",
"-module-cache-path", moduleCachePath.nativePathString(escaped: true),
"-working-directory", path.nativePathString(escaped: true),
"-explain-module-dependency", "A",
main.nativePathString(escaped: true)] + sdkArgumentsForTesting)
let jobs = try driver.planBuild()
try driver.run(jobs: jobs)
XCTAssertTrue(!driver.diagnosticEngine.diagnostics.isEmpty)
XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .remark &&
$0.message.text == "Module 'testTraceDependency' depends on 'A'"})

for diag in driver.diagnosticEngine.diagnostics {
print(diag.behavior)
print(diag.message)
try assertDriverDiagnostics(args:[
"swiftc",
"-I", cHeadersPath.nativePathString(escaped: true),
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
"-explicit-module-build",
"-module-cache-path", moduleCachePath.nativePathString(escaped: true),
"-working-directory", path.nativePathString(escaped: true),
"-explain-module-dependency", "A",
main.nativePathString(escaped: true)
] + sdkArgumentsForTesting) { driver, diagnostics in
diagnostics.forbidUnexpected(.error, .warning, .note, .remark)

let jobs = try driver.planBuild()
try driver.run(jobs: jobs)

diagnostics.expect(.remark("Module 'testTraceDependency' depends on 'A'"))
#if os(macOS)
diagnostics.expect(.note("[testTraceDependency] -> [A] -> [A](ObjC)"))
#else
diagnostics.expect(.note("[testTraceDependency] -> [C](ObjC) -> [B](ObjC) -> [A](ObjC)"))
#endif
}
XCTAssertEqual(driver.diagnosticEngine.diagnostics.filter { $0.behavior == .note}.count, 1)
XCTAssertTrue(driver.diagnosticEngine.diagnostics.contains { $0.behavior == .note &&
($0.message.text == "[testTraceDependency] -> [A] -> [A](ObjC)" ||
$0.message.text == "[testTraceDependency] -> [C](ObjC) -> [B](ObjC) -> [A](ObjC)")})
}
}
}
Expand Down

0 comments on commit 7f5c25b

Please sign in to comment.