Skip to content

Commit 0ffc59b

Browse files
authored
Merge pull request #1060 from ahoppen/ahoppen/skip-format-tests
Skip formatting tests if host toolchain doesn’t contain swift-format
2 parents 8d4449b + e184dc0 commit 0ffc59b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ public enum SkipUnless {
198198
}
199199
}
200200

201+
public static func toolchainContainsSwiftFormat(
202+
file: StaticString = #file,
203+
line: UInt = #line
204+
) async throws {
205+
try await skipUnlessSupportedByToolchain(
206+
swiftVersion: SwiftVersion(5, 11),
207+
featureName: "Toolchain contains swift-format",
208+
file: file,
209+
line: line
210+
) {
211+
return await ToolchainRegistry.forTesting.default?.swiftFormat != nil
212+
}
213+
}
214+
201215
public static func longTestsEnabled() throws {
202216
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {
203217
throw XCTSkip("Long tests disabled using the `SKIP_LONG_TESTS` environment variable")

Tests/SourceKitLSPTests/FormattingTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import XCTest
1919

2020
final class FormattingTests: XCTestCase {
2121
func testFormatting() async throws {
22+
try await SkipUnless.toolchainContainsSwiftFormat()
2223
let testClient = try await TestSourceKitLSPClient()
2324
let uri = DocumentURI.for(.swift)
2425

@@ -52,6 +53,7 @@ final class FormattingTests: XCTestCase {
5253
}
5354

5455
func testFormattingNoEdits() async throws {
56+
try await SkipUnless.toolchainContainsSwiftFormat()
5557
let testClient = try await TestSourceKitLSPClient()
5658
let uri = DocumentURI.for(.swift)
5759

@@ -77,6 +79,7 @@ final class FormattingTests: XCTestCase {
7779
}
7880

7981
func testConfigFileOnDisk() async throws {
82+
try await SkipUnless.toolchainContainsSwiftFormat()
8083
// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
8184
let ws = try await MultiFileTestWorkspace(files: [
8285
".swift-format": """
@@ -111,6 +114,7 @@ final class FormattingTests: XCTestCase {
111114
}
112115

113116
func testConfigFileInParentDirectory() async throws {
117+
try await SkipUnless.toolchainContainsSwiftFormat()
114118
// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
115119
let ws = try await MultiFileTestWorkspace(files: [
116120
".swift-format": """
@@ -145,6 +149,7 @@ final class FormattingTests: XCTestCase {
145149
}
146150

147151
func testConfigFileInNestedDirectory() async throws {
152+
try await SkipUnless.toolchainContainsSwiftFormat()
148153
// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
149154
let ws = try await MultiFileTestWorkspace(files: [
150155
".swift-format": """
@@ -187,6 +192,7 @@ final class FormattingTests: XCTestCase {
187192
}
188193

189194
func testInvalidConfigurationFile() async throws {
195+
try await SkipUnless.toolchainContainsSwiftFormat()
190196
// We pick up an invalid swift-format configuration file and thus don't set the user-provided options.
191197
// The swift-format default is 2 spaces.
192198
let ws = try await MultiFileTestWorkspace(files: [

0 commit comments

Comments
 (0)