From 9e2afeeaa77f20abf60dbae60299287b44295714 Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Mon, 23 Sep 2024 14:02:41 -0700 Subject: [PATCH] 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. --- Tests/CommandsTests/PackageCommandTests.swift | 26 +++++++++++++------ .../FunctionalTests/MiscellaneousTests.swift | 1 + Tests/FunctionalTests/PluginTests.swift | 2 +- Tests/FunctionalTests/ResourcesTests.swift | 3 ++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index 5206142ad28..80984c28b01 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -2290,7 +2290,9 @@ final class PackageCommandTests: CommandsTestCase { try await runPlugin(flags: [], diagnostics: ["print"]) { stdout, stderr in XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, isEmpty) + let filteredStderr = stderr.components(separatedBy: "\n") + .filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n") + XCTAssertMatch(filteredStderr, isEmpty) } try await runPlugin(flags: [], diagnostics: ["print", "progress"]) { stdout, stderr in @@ -2309,7 +2311,7 @@ final class PackageCommandTests: CommandsTestCase { XCTAssertMatch(stderr, containsWarning) } - try await runPluginWithError(flags: [], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in + try await runPluginWithError(flags: [], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in XCTAssertMatch(stdout, isOnlyPrint) XCTAssertMatch(stderr, containsProgress) XCTAssertMatch(stderr, containsWarning) @@ -2322,7 +2324,9 @@ final class PackageCommandTests: CommandsTestCase { try await runPlugin(flags: ["-q"], diagnostics: ["print"]) { stdout, stderr in XCTAssertMatch(stdout, isOnlyPrint) - XCTAssertMatch(stderr, isEmpty) + let filteredStderr = stderr.components(separatedBy: "\n") + .filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n") + XCTAssertMatch(filteredStderr, isEmpty) } try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress"]) { stdout, stderr in @@ -2461,7 +2465,7 @@ final class PackageCommandTests: CommandsTestCase { let containsLogtext = StringPattern.contains("command plugin: packageManager.build logtext: Building for debugging...") // Echoed logs have no prefix - let containsLogecho = StringPattern.regex("^Building for debugging...\n") + let containsLogecho = StringPattern.contains("Building for debugging...\n") // These tests involve building a target, so each test must run with a fresh copy of the fixture // otherwise the logs may be different in subsequent tests. @@ -2470,14 +2474,20 @@ final class PackageCommandTests: CommandsTestCase { try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in let (stdout, stderr) = try await SwiftPM.Package.execute(["print-diagnostics", "build"], packagePath: fixturePath, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) XCTAssertMatch(stdout, isEmpty) - XCTAssertMatch(stderr, isEmpty) + // Filter some unrelated output that could show up on stderr. + let filteredStderr = stderr.components(separatedBy: "\n") + .filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n") + XCTAssertMatch(filteredStderr, isEmpty) } // Check that logs are returned to the plugin when echoLogs is false try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in let (stdout, stderr) = try await SwiftPM.Package.execute(["print-diagnostics", "build", "printlogs"], packagePath: fixturePath, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) XCTAssertMatch(stdout, containsLogtext) - XCTAssertMatch(stderr, isEmpty) + // Filter some unrelated output that could show up on stderr. + let filteredStderr = stderr.components(separatedBy: "\n") + .filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n") + XCTAssertMatch(filteredStderr, isEmpty) } // Check that logs echoed to the console (on stderr) when echoLogs is true @@ -2784,14 +2794,14 @@ final class PackageCommandTests: CommandsTestCase { do { 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"]) XCTAssertMatch(stdout, .contains("success")) - XCTAssertEqual(stderr, "") + XCTAssertFalse(stderr.contains("error:")) } // Check default command arguments do { 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"]) XCTAssertMatch(stdout, .contains("success")) - XCTAssertEqual(stderr, "") + XCTAssertFalse(stderr.contains("error:")) } } } diff --git a/Tests/FunctionalTests/MiscellaneousTests.swift b/Tests/FunctionalTests/MiscellaneousTests.swift index d5a16549a80..f58b784b927 100644 --- a/Tests/FunctionalTests/MiscellaneousTests.swift +++ b/Tests/FunctionalTests/MiscellaneousTests.swift @@ -662,6 +662,7 @@ final class MiscellaneousTestCase: XCTestCase { try await fixture(name: "Miscellaneous/RootPackageWithConditionals") { path in let (_, stderr) = try await SwiftPM.Build.execute(packagePath: path, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) let errors = stderr.components(separatedBy: .newlines).filter { !$0.contains("[logging] misuse") && !$0.isEmpty } + .filter { !$0.contains("Unable to locate libSwiftScan") } XCTAssertEqual(errors, [], "unexpected errors: \(errors)") } } diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index 4a5a98bd5e7..9bc95ac77a4 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -236,7 +236,7 @@ final class PluginTests: XCTestCase { try createPackageUnderTest(packageDir: packageDir, toolsVersion: .v6_0) let (_, stderr2) = try await executeSwiftBuild(packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) - XCTAssertEqual("", stderr2) + XCTAssertFalse(stderr2.contains("error:")) XCTAssertTrue(localFileSystem.exists(pathOfGeneratedFile), "plugin did not run, generated file does not exist at \(pathOfGeneratedFile.pathString)") } } diff --git a/Tests/FunctionalTests/ResourcesTests.swift b/Tests/FunctionalTests/ResourcesTests.swift index 0310b57f782..a62b331f9ba 100644 --- a/Tests/FunctionalTests/ResourcesTests.swift +++ b/Tests/FunctionalTests/ResourcesTests.swift @@ -177,7 +177,8 @@ final class ResourcesTests: XCTestCase { let (_, stderr) = try await executeSwiftBuild(packageDir, env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"]) // Filter some unrelated output that could show up on stderr. - let filteredStderr = stderr.components(separatedBy: "\n").filter { !$0.contains("[logging]") }.joined(separator: "\n") + let filteredStderr = stderr.components(separatedBy: "\n").filter { !$0.contains("[logging]") } + .filter { !$0.contains("Unable to locate libSwiftScan") }.joined(separator: "\n") XCTAssertEqual(filteredStderr, "", "unexpectedly received error output: \(stderr)") let builtProductsDir = packageDir.appending(components: [".build", "debug"])