Skip to content

Commit 6ba5b96

Browse files
authored
Skip tests which need -suppress-warnings to work if it doesn't work (#6930)
1 parent b08e801 commit 6ba5b96

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Sources/SPMTestSupport/Toolchain.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ extension UserToolchain {
111111
}
112112
}
113113

114+
public func supportsSuppressWarnings() -> Bool {
115+
do {
116+
try testWithTemporaryDirectory { tmpPath in
117+
let inputPath = tmpPath.appending("best.swift")
118+
try localFileSystem.writeFileContents(inputPath, string: "let foo: String? = \"bar\"\nprint(foo)\n")
119+
let outputPath = tmpPath.appending("foo")
120+
let serializedDiagnosticsPath = tmpPath.appending("out.dia")
121+
let toolchainPath = self.swiftCompilerPath.parentDirectory.parentDirectory
122+
try Process.checkNonZeroExit(arguments: ["/usr/bin/xcrun", "--toolchain", toolchainPath.pathString, "swiftc", inputPath.pathString, "-Xfrontend", "-serialize-diagnostics-path", "-Xfrontend", serializedDiagnosticsPath.pathString, "-o", outputPath.pathString, "-suppress-warnings"])
123+
124+
let diaFileContents = try localFileSystem.readFileContents(serializedDiagnosticsPath)
125+
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
126+
127+
if diagnosticsSet.diagnostics.contains(where: { $0.text.contains("warning") }) {
128+
throw StringError("does not support suppressing warnings")
129+
}
130+
}
131+
return true
132+
} catch {
133+
return false
134+
}
135+
}
136+
114137
/// Helper function to determine whether we should run SDK-dependent tests.
115138
public func supportsSDKDependentTests() -> Bool {
116139
return ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] == nil

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ class MiscellaneousTestCase: XCTestCase {
606606
}
607607

608608
func testNoWarningFromRemoteDependencies() throws {
609+
try XCTSkipIf(!UserToolchain.default.supportsSuppressWarnings(), "skipping because test environment doesn't support suppressing warnings")
610+
609611
try fixture(name: "Miscellaneous/DependenciesWarnings") { path in
610612
// prepare the deps as git sources
611613
let dependency1Path = path.appending("dep1")
@@ -623,6 +625,8 @@ class MiscellaneousTestCase: XCTestCase {
623625
}
624626

625627
func testNoWarningFromRemoteDependenciesWithWarningsAsErrors() throws {
628+
try XCTSkipIf(!UserToolchain.default.supportsSuppressWarnings(), "skipping because test environment doesn't support suppressing warnings")
629+
626630
try fixture(name: "Miscellaneous/DependenciesWarnings2") { path in
627631
// prepare the deps as git sources
628632
let dependency1Path = path.appending("dep1")

0 commit comments

Comments
 (0)