Skip to content

Commit 91e3ea4

Browse files
committed
Tests: introduce testOnWindows to Example
Mirror the `testOnLinux` for Windows with a `testOnWindows`. This allows us to skip some tests dynamically as we do on Linux.
1 parent 339d250 commit 91e3ea4

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Source/SwiftLintBuiltInRules/Rules/Lint/UnusedImportRuleExamples.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct UnusedImportRuleExamples {
190190
"allowed_transitive_imports": ["CoreFoundation", "Dispatch"],
191191
] as [String: any Sendable],
192192
],
193-
] as [String: any Sendable], testMultiByteOffsets: false, testOnLinux: false):
193+
] as [String: any Sendable], testMultiByteOffsets: false, testOnLinux: false, testOnWindows: false):
194194
Example("""
195195
import Foundation
196196
typealias Foo = CFArray
@@ -202,7 +202,7 @@ struct UnusedImportRuleExamples {
202202
dispatchMain()
203203
""", configuration: [
204204
"require_explicit_imports": true
205-
], testMultiByteOffsets: false, testOnLinux: false):
205+
], testMultiByteOffsets: false, testOnLinux: false, testOnWindows: false):
206206
Example("""
207207
import CoreFoundation
208208
import Dispatch
@@ -236,7 +236,7 @@ struct UnusedImportRuleExamples {
236236
class A {}
237237
""", configuration: [
238238
"require_explicit_imports": true
239-
], testMultiByteOffsets: false, testOnLinux: false):
239+
], testMultiByteOffsets: false, testOnLinux: false, testOnWindows: false):
240240
Example("""
241241
import CoreFoundation
242242
import Foundation

Source/SwiftLintCore/Models/Example.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public struct Example: Sendable {
2828
package private(set) var testDisableCommand: Bool
2929
/// Whether the example should be tested on Linux
3030
public private(set) var testOnLinux: Bool
31+
/// Whether the example should be tested on Windows
32+
public private(set) var testOnWindows: Bool
3133
/// The path to the file where the example was created
3234
public private(set) var file: StaticString
3335
/// The line in the file where the example was created
@@ -68,13 +70,15 @@ public extension Example {
6870
testWrappingInString: Bool = true,
6971
testDisableCommand: Bool = true,
7072
testOnLinux: Bool = true,
73+
testOnWindows: Bool = true,
7174
file: StaticString = #filePath,
7275
line: UInt = #line,
7376
excludeFromDocumentation: Bool = false) {
7477
self.code = code
7578
self.configuration = configuration
7679
self.testMultiByteOffsets = testMultiByteOffsets
7780
self.testOnLinux = testOnLinux
81+
self.testOnWindows = testOnWindows
7882
self.file = file
7983
self.line = line
8084
self.excludeFromDocumentation = excludeFromDocumentation

Tests/TestHelpers/TestHelpers.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ private func testCorrection(_ correction: (Example, Example),
265265
guard correction.0.testOnLinux else {
266266
return
267267
}
268+
#endif
269+
#if os(Windows)
270+
guard correction.0.testOnWindows else {
271+
return
272+
}
268273
#endif
269274
var config = configuration
270275
if let correctionConfiguration = correction.0.configuration,

0 commit comments

Comments
 (0)