Skip to content

Commit e08708e

Browse files
authored
Add an expectation of a warning diagnostic to tests that hide libSwiftScan. (#7995)
Such tests cause the driver to take a code-path that results in a warning: `warning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.` This needs to be taken into account.
1 parent 6ad5efb commit e08708e

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

Tests/CommandsTests/PackageCommandTests.swift

+18-8
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,9 @@ final class PackageCommandTests: CommandsTestCase {
22902290

22912291
try await runPlugin(flags: [], diagnostics: ["print"]) { stdout, stderr in
22922292
XCTAssertMatch(stdout, isOnlyPrint)
2293-
XCTAssertMatch(stderr, isEmpty)
2293+
let filteredStderr = stderr.components(separatedBy: "\n")
2294+
.filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n")
2295+
XCTAssertMatch(filteredStderr, isEmpty)
22942296
}
22952297

22962298
try await runPlugin(flags: [], diagnostics: ["print", "progress"]) { stdout, stderr in
@@ -2309,7 +2311,7 @@ final class PackageCommandTests: CommandsTestCase {
23092311
XCTAssertMatch(stderr, containsWarning)
23102312
}
23112313

2312-
try await runPluginWithError(flags: [], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in
2314+
try await runPluginWithError(flags: [], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in
23132315
XCTAssertMatch(stdout, isOnlyPrint)
23142316
XCTAssertMatch(stderr, containsProgress)
23152317
XCTAssertMatch(stderr, containsWarning)
@@ -2322,7 +2324,9 @@ final class PackageCommandTests: CommandsTestCase {
23222324

23232325
try await runPlugin(flags: ["-q"], diagnostics: ["print"]) { stdout, stderr in
23242326
XCTAssertMatch(stdout, isOnlyPrint)
2325-
XCTAssertMatch(stderr, isEmpty)
2327+
let filteredStderr = stderr.components(separatedBy: "\n")
2328+
.filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n")
2329+
XCTAssertMatch(filteredStderr, isEmpty)
23262330
}
23272331

23282332
try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress"]) { stdout, stderr in
@@ -2461,7 +2465,7 @@ final class PackageCommandTests: CommandsTestCase {
24612465
let containsLogtext = StringPattern.contains("command plugin: packageManager.build logtext: Building for debugging...")
24622466

24632467
// Echoed logs have no prefix
2464-
let containsLogecho = StringPattern.regex("^Building for debugging...\n")
2468+
let containsLogecho = StringPattern.contains("Building for debugging...\n")
24652469

24662470
// These tests involve building a target, so each test must run with a fresh copy of the fixture
24672471
// otherwise the logs may be different in subsequent tests.
@@ -2470,14 +2474,20 @@ final class PackageCommandTests: CommandsTestCase {
24702474
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
24712475
let (stdout, stderr) = try await SwiftPM.Package.execute(["print-diagnostics", "build"], packagePath: fixturePath, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
24722476
XCTAssertMatch(stdout, isEmpty)
2473-
XCTAssertMatch(stderr, isEmpty)
2477+
// Filter some unrelated output that could show up on stderr.
2478+
let filteredStderr = stderr.components(separatedBy: "\n")
2479+
.filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n")
2480+
XCTAssertMatch(filteredStderr, isEmpty)
24742481
}
24752482

24762483
// Check that logs are returned to the plugin when echoLogs is false
24772484
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
24782485
let (stdout, stderr) = try await SwiftPM.Package.execute(["print-diagnostics", "build", "printlogs"], packagePath: fixturePath, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
24792486
XCTAssertMatch(stdout, containsLogtext)
2480-
XCTAssertMatch(stderr, isEmpty)
2487+
// Filter some unrelated output that could show up on stderr.
2488+
let filteredStderr = stderr.components(separatedBy: "\n")
2489+
.filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n")
2490+
XCTAssertMatch(filteredStderr, isEmpty)
24812491
}
24822492

24832493
// Check that logs echoed to the console (on stderr) when echoLogs is true
@@ -2784,14 +2794,14 @@ final class PackageCommandTests: CommandsTestCase {
27842794
do {
27852795
let (stdout, stderr) = try await SwiftPM.Package.execute(["plugin", "MyPlugin", "--foo", "--help", "--version", "--verbose"], packagePath: packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
27862796
XCTAssertMatch(stdout, .contains("success"))
2787-
XCTAssertEqual(stderr, "")
2797+
XCTAssertFalse(stderr.contains("error:"))
27882798
}
27892799

27902800
// Check default command arguments
27912801
do {
27922802
let (stdout, stderr) = try await SwiftPM.Package.execute(["MyPlugin", "--foo", "--help", "--version", "--verbose"], packagePath: packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
27932803
XCTAssertMatch(stdout, .contains("success"))
2794-
XCTAssertEqual(stderr, "")
2804+
XCTAssertFalse(stderr.contains("error:"))
27952805
}
27962806
}
27972807
}

Tests/FunctionalTests/MiscellaneousTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ final class MiscellaneousTestCase: XCTestCase {
662662
try await fixture(name: "Miscellaneous/RootPackageWithConditionals") { path in
663663
let (_, stderr) = try await SwiftPM.Build.execute(packagePath: path, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
664664
let errors = stderr.components(separatedBy: .newlines).filter { !$0.contains("[logging] misuse") && !$0.isEmpty }
665+
.filter { !$0.contains("Unable to locate libSwiftScan") }
665666
XCTAssertEqual(errors, [], "unexpected errors: \(errors)")
666667
}
667668
}

Tests/FunctionalTests/PluginTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ final class PluginTests: XCTestCase {
236236

237237
try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v6_0)
238238
let (_, stderr2) = try await executeSwiftBuild(packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
239-
XCTAssertEqual("", stderr2)
239+
XCTAssertFalse(stderr2.contains("error:"))
240240
XCTAssertTrue(localFileSystem.exists(pathOfGeneratedFile), "plugin did not run, generated file does not exist at \(pathOfGeneratedFile.pathString)")
241241
}
242242
}

Tests/FunctionalTests/ResourcesTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ final class ResourcesTests: XCTestCase {
177177

178178
let (_, stderr) = try await executeSwiftBuild(packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
179179
// Filter some unrelated output that could show up on stderr.
180-
let filteredStderr = stderr.components(separatedBy: "\n").filter { !$0.contains("[logging]") }.joined(separator: "\n")
180+
let filteredStderr = stderr.components(separatedBy: "\n").filter { !$0.contains("[logging]") }
181+
.filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n")
181182
XCTAssertEqual(filteredStderr, "", "unexpectedly received error output: \(stderr)")
182183

183184
let builtProductsDir = packageDir.appending(components: [".build", "debug"])

0 commit comments

Comments
 (0)