Skip to content

Commit ac8806f

Browse files
authored
Filter superfluous diagnostics (#7003)
A bit similar to #6930, we need to filter some superfluous diagnostics to get passing tests in certain configurations.
1 parent 5fc46c7 commit ac8806f

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

Sources/SPMTestSupport/Observability.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public struct TestingObservability {
7272

7373
// TODO: do something useful with scope
7474
func handleDiagnostic(scope: ObservabilityScope, diagnostic: Basics.Diagnostic) {
75+
// Filter superfluous diagnostics.
76+
guard !diagnostic.message.hasPrefix("<unknown>:0: warning: annotation implies no releases") else {
77+
return
78+
}
79+
guard !diagnostic.message.hasPrefix("<unknown>:0: note: add explicit") else {
80+
return
81+
}
82+
7583
if self.verbose {
7684
print(diagnostic.description)
7785
}

Sources/SPMTestSupport/Toolchain.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ extension UserToolchain {
134134
}
135135
}
136136

137+
// This builds a trivial program with `-warnings-as-errors`, if it fails, the compiler in use generates warnings by default and is not suitable for testing warnings as errors behaviors.
138+
public func supportsWarningsAsErrors() -> Bool {
139+
do {
140+
try testWithTemporaryDirectory { tmpPath in
141+
let inputPath = tmpPath.appending("best.swift")
142+
try localFileSystem.writeFileContents(inputPath, string: "print(\"hello\")")
143+
let outputPath = tmpPath.appending("foo")
144+
let toolchainPath = self.swiftCompilerPath.parentDirectory.parentDirectory
145+
try Process.checkNonZeroExit(arguments: ["/usr/bin/xcrun", "--toolchain", toolchainPath.pathString, "swiftc", inputPath.pathString, "-o", outputPath.pathString, "-warnings-as-errors"])
146+
}
147+
return true
148+
} catch {
149+
return false
150+
}
151+
}
152+
137153
/// Helper function to determine whether we should run SDK-dependent tests.
138154
public func supportsSDKDependentTests() -> Bool {
139155
return ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] == nil

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,10 @@ final class PackageToolTests: CommandsTestCase {
21592159
do {
21602160
let (stdout, stderr) = try SwiftPM.Package.execute(["plugin", "MyPlugin", "--foo", "--help", "--version", "--verbose"], packagePath: packageDir)
21612161
XCTAssertMatch(stdout, .contains("success"))
2162-
XCTAssertEqual(stderr, "")
2162+
let filteredStderr = stderr.components(separatedBy: "\n").filter {
2163+
!$0.contains("annotation implies no releases") && !$0.contains("note: add explicit")
2164+
}.joined(separator: "\n")
2165+
XCTAssertEqual(filteredStderr, "")
21632166
}
21642167

21652168
// Check default command arguments

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class MiscellaneousTestCase: XCTestCase {
667667
func testRootPackageWithConditionals() throws {
668668
try fixture(name: "Miscellaneous/RootPackageWithConditionals") { path in
669669
let (_, stderr) = try SwiftPM.Build.execute(packagePath: path)
670-
let errors = stderr.components(separatedBy: .newlines).filter { !$0.contains("[logging] misuse") && !$0.isEmpty }
670+
let errors = stderr.components(separatedBy: .newlines).filter { !$0.contains("[logging] misuse") && !$0.contains("annotation implies no releases") && !$0.contains("note: add explicit") && !$0.isEmpty }
671671
XCTAssertEqual(errors, [], "unexpected errors: \(errors)")
672672
}
673673
}

Tests/FunctionalTests/ResourcesTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
import PackageModel
1415
import SPMTestSupport
1516
import XCTest
1617

@@ -114,6 +115,8 @@ class ResourcesTests: XCTestCase {
114115
}
115116

116117
func testSwiftResourceAccessorDoesNotCauseInconsistentImportWarning() throws {
118+
try XCTSkipIf(!UserToolchain.default.supportsWarningsAsErrors(), "skipping because test environment doesn't support warnings as errors")
119+
117120
try fixture(name: "Resources/FoundationlessClient/UtilsWithFoundationPkg") { fixturePath in
118121
XCTAssertBuilds(
119122
fixturePath,

0 commit comments

Comments
 (0)