Skip to content

Commit 7ad725f

Browse files
committed
Add an expectation of a warning diagnostic to tests that hide libSwiftScan.
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 f55fbef commit 7ad725f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Tests/CommandsTests/PackageCommandTests.swift

+11-5
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,8 @@ final class PackageCommandTests: CommandsTestCase {
22672267
let containsRemark = StringPattern.contains("command plugin: Diagnostics.remark")
22682268
let containsWarning = StringPattern.contains("command plugin: Diagnostics.warning")
22692269
let containsError = StringPattern.contains("command plugin: Diagnostics.error")
2270+
let hiddenLibSwiftScanWarnPattern = StringPattern.equal(
2271+
"warning: \'miscellaneous_plugins_commandpluginteststub\': warning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.\nwarning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.\nwarning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.")
22702272

22712273
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
22722274
func runPlugin(flags: [String], diagnostics: [String], completion: (String, String) -> Void) async throws {
@@ -2290,7 +2292,7 @@ final class PackageCommandTests: CommandsTestCase {
22902292

22912293
try await runPlugin(flags: [], diagnostics: ["print"]) { stdout, stderr in
22922294
XCTAssertMatch(stdout, isOnlyPrint)
2293-
XCTAssertMatch(stderr, isEmpty)
2295+
XCTAssertMatch(stderr, hiddenLibSwiftScanWarnPattern)
22942296
}
22952297

22962298
try await runPlugin(flags: [], diagnostics: ["print", "progress"]) { stdout, stderr in
@@ -2322,7 +2324,7 @@ 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+
XCTAssertMatch(stderr, hiddenLibSwiftScanWarnPattern)
23262328
}
23272329

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

24632465
// Echoed logs have no prefix
2464-
let containsLogecho = StringPattern.regex("^Building for debugging...\n")
2466+
let containsLogecho = StringPattern.contains("Building for debugging...\n")
2467+
2468+
// Hides the libSwiftScan library from the driver
2469+
let hiddenLibSwiftScanWarnPattern = StringPattern.equal(
2470+
"warning: \'miscellaneous_plugins_commandpluginteststub\': warning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.\nwarning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.\nwarning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.")
24652471

24662472
// These tests involve building a target, so each test must run with a fresh copy of the fixture
24672473
// otherwise the logs may be different in subsequent tests.
@@ -2470,14 +2476,14 @@ final class PackageCommandTests: CommandsTestCase {
24702476
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
24712477
let (stdout, stderr) = try await SwiftPM.Package.execute(["print-diagnostics", "build"], packagePath: fixturePath, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
24722478
XCTAssertMatch(stdout, isEmpty)
2473-
XCTAssertMatch(stderr, isEmpty)
2479+
XCTAssertMatch(stderr, hiddenLibSwiftScanWarnPattern)
24742480
}
24752481

24762482
// Check that logs are returned to the plugin when echoLogs is false
24772483
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
24782484
let (stdout, stderr) = try await SwiftPM.Package.execute(["print-diagnostics", "build", "printlogs"], packagePath: fixturePath, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"])
24792485
XCTAssertMatch(stdout, containsLogtext)
2480-
XCTAssertMatch(stderr, isEmpty)
2486+
XCTAssertMatch(stderr, hiddenLibSwiftScanWarnPattern)
24812487
}
24822488

24832489
// Check that logs echoed to the console (on stderr) when echoLogs is true

0 commit comments

Comments
 (0)