Skip to content

Commit 8fb4851

Browse files
committed
Tests: adjust flag computation for Windows
Windows isolates XCTest/Testing from the platform SDK as they are not part of the redistributable components. We adjust the flags by querying the partial path information and computing the location for the `XCTest` module for the tests. Additionally, enable the ObjC interop on the test cases to allow parsing `@objc` modifiers on declarations. This allows us to pass the GeneratedTests test suite.
1 parent 91e3ea4 commit 8fb4851

File tree

1 file changed

+59
-4
lines changed

1 file changed

+59
-4
lines changed

Tests/TestHelpers/TestHelpers.swift

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,44 @@ import XCTest
44

55
import SwiftLintFramework
66

7+
#if os(Windows)
8+
private struct PlatformInfo {
9+
public struct DefaultProperties {
10+
public let XCTestVersion: String
11+
public let SwiftTestingVersion: String
12+
public let SwiftFlags: [String]?
13+
}
14+
public let defaults: DefaultProperties
15+
}
16+
17+
extension PlatformInfo.DefaultProperties: Decodable {
18+
enum CodingKeys: String, CodingKey {
19+
case XCTestVersion = "XCTEST_VERSION"
20+
case SwiftTestingVersion = "SWIFT_TESTING_VERSION"
21+
case SwiftFlags = "SWIFTC_FLAGS"
22+
}
23+
}
24+
25+
extension PlatformInfo: Decodable {
26+
enum CodingKeys: String, CodingKey {
27+
case defaults = "DefaultProperties"
28+
}
29+
}
30+
31+
private let info: PlatformInfo = {
32+
let sdk = URL(fileURLWithPath: sdkPath(), isDirectory: true)
33+
.deletingLastPathComponent()
34+
.deletingLastPathComponent()
35+
.deletingLastPathComponent()
36+
.appendingPathComponent("Info.plist")
37+
guard let data = try? Data(contentsOf: sdk),
38+
let info = try? PropertyListDecoder().decode(PlatformInfo.self, from: data) else {
39+
fatalError("invalid platorm SDK - couldn't decode \(sdk.path)")
40+
}
41+
return info
42+
}()
43+
#endif
44+
745
// swiftlint:disable file_length
846

947
private let violationMarker = ""
@@ -28,12 +66,29 @@ private extension SwiftLintFile {
2866
.appendingPathComponent("Library")
2967
.appendingPathComponent("Frameworks")
3068
.path
31-
return [
32-
"-F",
33-
frameworks,
69+
70+
let arguments = [
71+
"-F", frameworks,
3472
"-sdk", sdk,
35-
"-j4", path!,
73+
"-Xfrontend", "-enable-objc-interop",
74+
"-j4",
75+
path!,
3676
]
77+
#if os(Windows)
78+
let XCTestPath = URL(fileURLWithPath: sdk, isDirectory: true)
79+
.deletingLastPathComponent()
80+
.deletingLastPathComponent()
81+
.appendingPathComponent("Library")
82+
.appendingPathComponent("XCTest-\(info.defaults.XCTestVersion)")
83+
.appendingPathComponent("usr")
84+
.appendingPathComponent("lib")
85+
.appendingPathComponent("swift")
86+
.appendingPathComponent("windows")
87+
.path
88+
return ["-I", XCTestPath] + arguments
89+
#else
90+
return arguments
91+
#endif
3792
}
3893
}
3994

0 commit comments

Comments
 (0)