Skip to content

Add an expectation of a warning diagnostic to tests that hide libSwiftScan. #7995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions Tests/CommandsTests/PackageCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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:"))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/FunctionalTests/PluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/FunctionalTests/ResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down