Skip to content

Commit cc0b1a5

Browse files
authored
Tests: Enable tests on Windows (#8466)
Enable additional tests on Windows host platform - Enable a few `AsyncProcessTests` - Enable the lone skipped test in `EnvironmentTests` - Enable the only skipped test in `Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift` - Enable the only skipped test in `Tests/BuildTests/BuildSystemDelegateTests.swift` - Enable the lone skipped test in `Tests/BuildTests/LLBuildManifestBuilderTests.swift` - Replace usages of `fixwin` with `AbsolutePath.pathString` Related to: #8433 rdar://148248105
1 parent 4511962 commit cc0b1a5

File tree

6 files changed

+102
-68
lines changed

6 files changed

+102
-68
lines changed

Tests/BasicsTests/AsyncProcessTests.swift

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ import func TSCBasic.withTemporaryFile
2323
import func TSCTestSupport.withCustomEnv
2424

2525
final class AsyncProcessTests: XCTestCase {
26+
#if os(Windows)
27+
let executableExt = ".exe"
28+
#else
29+
let executableExt = ""
30+
#endif
2631

27-
override func setUp() async throws {
28-
try skipOnWindowsAsTestCurrentlyFails()
29-
}
30-
3132
func testBasics() throws {
33+
try skipOnWindowsAsTestCurrentlyFails(because: """
34+
threw error "missingExecutableProgram(program: "echo.exe")"
35+
""")
36+
3237
do {
33-
let process = AsyncProcess(args: "echo", "hello")
38+
let process = AsyncProcess(args: "echo\(executableExt)", "hello")
3439
try process.launch()
3540
let result = try process.waitUntilExit()
3641
XCTAssertEqual(try result.utf8Output(), "hello\n")
@@ -46,27 +51,26 @@ final class AsyncProcessTests: XCTestCase {
4651
}
4752
}
4853

49-
func testPopen() throws {
50-
#if os(Windows)
51-
let echo = "echo.exe"
52-
#else
53-
let echo = "echo"
54-
#endif
54+
func testPopenBasic() throws {
55+
try skipOnWindowsAsTestCurrentlyFails(because: """
56+
threw error "missingExecutableProgram(program: "echo.exe")"
57+
""")
58+
5559
// Test basic echo.
56-
XCTAssertEqual(try AsyncProcess.popen(arguments: [echo, "hello"]).utf8Output(), "hello\n")
60+
XCTAssertEqual(try AsyncProcess.popen(arguments: ["echo\(executableExt)", "hello"]).utf8Output(), "hello\n")
61+
}
5762

63+
func testPopenWithBufferLargerThanAllocated() throws {
64+
try skipOnWindowsAsTestCurrentlyFails(because: """
65+
threw error "missingExecutableProgram(program: "cat.exe")"
66+
""")
5867
// Test buffer larger than that allocated.
5968
try withTemporaryFile { file in
6069
let count = 10000
6170
let stream = BufferedOutputByteStream()
6271
stream.send(Format.asRepeating(string: "a", count: count))
6372
try localFileSystem.writeFileContents(file.path, bytes: stream.bytes)
64-
#if os(Windows)
65-
let cat = "cat.exe"
66-
#else
67-
let cat = "cat"
68-
#endif
69-
let outputCount = try AsyncProcess.popen(args: cat, file.path.pathString).utf8Output().count
73+
let outputCount = try AsyncProcess.popen(args: "cat\(executableExt)", file.path.pathString).utf8Output().count
7074
XCTAssert(outputCount == count)
7175
}
7276
}
@@ -119,8 +123,12 @@ final class AsyncProcessTests: XCTestCase {
119123
}
120124

121125
func testCheckNonZeroExit() throws {
126+
try skipOnWindowsAsTestCurrentlyFails(because: """
127+
threw error "missingExecutableProgram(program: "echo.exe")"
128+
""")
129+
122130
do {
123-
let output = try AsyncProcess.checkNonZeroExit(args: "echo", "hello")
131+
let output = try AsyncProcess.checkNonZeroExit(args: "echo\(executableExt)", "hello")
124132
XCTAssertEqual(output, "hello\n")
125133
}
126134

@@ -134,8 +142,12 @@ final class AsyncProcessTests: XCTestCase {
134142

135143
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
136144
func testCheckNonZeroExitAsync() async throws {
145+
try skipOnWindowsAsTestCurrentlyFails(because: """
146+
threw error "missingExecutableProgram(program: "echo.exe")"
147+
""")
148+
137149
do {
138-
let output = try await AsyncProcess.checkNonZeroExit(args: "echo", "hello")
150+
let output = try await AsyncProcess.checkNonZeroExit(args: "echo\(executableExt)", "hello")
139151
XCTAssertEqual(output, "hello\n")
140152
}
141153

@@ -148,6 +160,8 @@ final class AsyncProcessTests: XCTestCase {
148160
}
149161

150162
func testFindExecutable() throws {
163+
try skipOnWindowsAsTestCurrentlyFails(because: "Assertion failure when trying to find ls executable")
164+
151165
try testWithTemporaryDirectory { tmpdir in
152166
// This process should always work.
153167
XCTAssertTrue(AsyncProcess.findExecutable("ls") != nil)
@@ -192,7 +206,11 @@ final class AsyncProcessTests: XCTestCase {
192206
}
193207

194208
func testThreadSafetyOnWaitUntilExit() throws {
195-
let process = AsyncProcess(args: "echo", "hello")
209+
try skipOnWindowsAsTestCurrentlyFails(because: """
210+
threw error "missingExecutableProgram(program: "echo.exe")"
211+
""")
212+
213+
let process = AsyncProcess(args: "echo\(executableExt)", "hello")
196214
try process.launch()
197215

198216
var result1 = ""
@@ -217,7 +235,11 @@ final class AsyncProcessTests: XCTestCase {
217235

218236
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
219237
func testThreadSafetyOnWaitUntilExitAsync() async throws {
220-
let process = AsyncProcess(args: "echo", "hello")
238+
try skipOnWindowsAsTestCurrentlyFails(because: """
239+
threw error "missingExecutableProgram(program: "echo.exe")"
240+
""")
241+
242+
let process = AsyncProcess(args: "echo\(executableExt)", "hello")
221243
try process.launch()
222244

223245
let t1 = Task {
@@ -236,6 +258,10 @@ final class AsyncProcessTests: XCTestCase {
236258
}
237259

238260
func testStdin() throws {
261+
try skipOnWindowsAsTestCurrentlyFails(because: """
262+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
263+
""")
264+
239265
var stdout = [UInt8]()
240266
let process = AsyncProcess(scriptName: "in-to-out", outputRedirection: .stream(stdout: { stdoutBytes in
241267
stdout += stdoutBytes
@@ -253,6 +279,10 @@ final class AsyncProcessTests: XCTestCase {
253279
}
254280

255281
func testStdoutStdErr() throws {
282+
try skipOnWindowsAsTestCurrentlyFails(because: """
283+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
284+
""")
285+
256286
// A simple script to check that stdout and stderr are captured separatly.
257287
do {
258288
let result = try AsyncProcess.popen(scriptName: "simple-stdout-stderr")
@@ -279,6 +309,10 @@ final class AsyncProcessTests: XCTestCase {
279309

280310
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
281311
func testStdoutStdErrAsync() async throws {
312+
try skipOnWindowsAsTestCurrentlyFails(because: """
313+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
314+
""")
315+
282316
// A simple script to check that stdout and stderr are captured separatly.
283317
do {
284318
let result = try await AsyncProcess.popen(scriptName: "simple-stdout-stderr")
@@ -304,6 +338,10 @@ final class AsyncProcessTests: XCTestCase {
304338
}
305339

306340
func testStdoutStdErrRedirected() throws {
341+
try skipOnWindowsAsTestCurrentlyFails(because: """
342+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
343+
""")
344+
307345
// A simple script to check that stdout and stderr are captured in the same location.
308346
do {
309347
let process = AsyncProcess(
@@ -332,6 +370,10 @@ final class AsyncProcessTests: XCTestCase {
332370
}
333371

334372
func testStdoutStdErrStreaming() throws {
373+
try skipOnWindowsAsTestCurrentlyFails(because: """
374+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
375+
""")
376+
335377
var stdout = [UInt8]()
336378
var stderr = [UInt8]()
337379
let process = AsyncProcess(scriptName: "long-stdout-stderr", outputRedirection: .stream(stdout: { stdoutBytes in
@@ -348,6 +390,10 @@ final class AsyncProcessTests: XCTestCase {
348390
}
349391

350392
func testStdoutStdErrStreamingRedirected() throws {
393+
try skipOnWindowsAsTestCurrentlyFails(because: """
394+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
395+
""")
396+
351397
var stdout = [UInt8]()
352398
var stderr = [UInt8]()
353399
let process = AsyncProcess(scriptName: "long-stdout-stderr", outputRedirection: .stream(stdout: { stdoutBytes in
@@ -364,6 +410,10 @@ final class AsyncProcessTests: XCTestCase {
364410
}
365411

366412
func testWorkingDirectory() throws {
413+
try skipOnWindowsAsTestCurrentlyFails(because: """
414+
threw error "missingExecutableProgram(program: "cat.exe")"
415+
""")
416+
367417
guard #available(macOS 10.15, *) else {
368418
// Skip this test since it's not supported in this OS.
369419
return
@@ -385,7 +435,7 @@ final class AsyncProcessTests: XCTestCase {
385435
try localFileSystem.writeFileContents(childPath, bytes: ByteString("child"))
386436

387437
do {
388-
let process = AsyncProcess(arguments: ["cat", "file"], workingDirectory: tempDirPath)
438+
let process = AsyncProcess(arguments: ["cat\(executableExt)", "file"], workingDirectory: tempDirPath)
389439
try process.launch()
390440
let result = try process.waitUntilExit()
391441
XCTAssertEqual(try result.utf8Output(), "parent")
@@ -403,12 +453,15 @@ final class AsyncProcessTests: XCTestCase {
403453
func testAsyncStream() async throws {
404454
// rdar://133548796
405455
try XCTSkipIfCI()
456+
try skipOnWindowsAsTestCurrentlyFails(because: """
457+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
458+
""")
406459

407460
let (stdoutStream, stdoutContinuation) = AsyncProcess.ReadableStream.makeStream()
408461
let (stderrStream, stderrContinuation) = AsyncProcess.ReadableStream.makeStream()
409462

410463
let process = AsyncProcess(
411-
scriptName: "echo",
464+
scriptName: "echo\(executableExt)",
412465
outputRedirection: .stream {
413466
stdoutContinuation.yield($0)
414467
} stderr: {
@@ -460,9 +513,12 @@ final class AsyncProcessTests: XCTestCase {
460513
func testAsyncStreamHighLevelAPI() async throws {
461514
// rdar://133548796
462515
try XCTSkipIfCI()
516+
try skipOnWindowsAsTestCurrentlyFails(because: """
517+
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
518+
""")
463519

464520
let result = try await AsyncProcess.popen(
465-
scriptName: "echo",
521+
scriptName: "echo\(executableExt)",
466522
stdout: { stdin, stdout in
467523
var counter = 0
468524
stdin.write("Hello \(counter)\n")

Tests/BasicsTests/Environment/EnvironmentTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import Basics
1616

1717
import XCTest
18-
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails()
1918

2019
final class EnvironmentTests: XCTestCase {
2120
func test_init() {
@@ -103,8 +102,6 @@ final class EnvironmentTests: XCTestCase {
103102
/// Important: This test is inherently race-prone, if it is proven to be
104103
/// flaky, it should run in a singled threaded environment/removed entirely.
105104
func test_current() throws {
106-
try skipOnWindowsAsTestCurrentlyFails(because: "ProcessInfo.processInfo.environment[pathEnvVarName] return nil in the docker container")
107-
108105
#if os(Windows)
109106
let pathEnvVarName = "Path"
110107
#else

Tests/BuildTests/BuildSystemDelegateTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ final class BuildSystemDelegateTests: XCTestCase {
3030
}
3131

3232
func testFilterNonFatalCodesignMessages() async throws {
33-
try skipOnWindowsAsTestCurrentlyFails()
33+
try skipOnWindowsAsTestCurrentlyFails(because: "Package fails to build when the test is being executed")
3434

3535
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
3636
// Note: we can re-use the `TestableExe` fixture here since we just need an executable.
37+
#if os(Windows)
38+
let executableExt = ".exe"
39+
#else
40+
let executableExt = ""
41+
#endif
3742
try await fixture(name: "Miscellaneous/TestableExe") { fixturePath in
3843
_ = try await executeSwiftBuild(fixturePath)
39-
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1")
44+
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1\(executableExt)")
4045
XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'")
4146
try localFileSystem.removeFileTree(execPath)
4247
let (fullLog, _) = try await executeSwiftBuild(fixturePath)

Tests/BuildTests/LLBuildManifestBuilderTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ final class LLBuildManifestBuilderTests: XCTestCase {
195195

196196
/// Verifies that two modules with the same name but different triples don't share same build manifest keys.
197197
func testToolsBuildTriple() async throws {
198-
try skipOnWindowsAsTestCurrentlyFails()
199-
200198
let (graph, fs, scope) = try macrosPackageGraph()
201199
let productsTriple = Triple.x86_64MacOS
202200
let toolsTriple = Triple.arm64Linux
@@ -221,6 +219,6 @@ final class LLBuildManifestBuilderTests: XCTestCase {
221219

222220
XCTAssertNotNil(manifest.commands["C.SwiftSyntax-aarch64-unknown-linux-gnu-debug-tool.module"])
223221
// Ensure that Objects.LinkFileList is -tool suffixed.
224-
XCTAssertNotNil(manifest.commands["/path/to/build/aarch64-unknown-linux-gnu/debug/MMIOMacros-tool.product/Objects.LinkFileList"])
222+
XCTAssertNotNil(manifest.commands[AbsolutePath("/path/to/build/aarch64-unknown-linux-gnu/debug/MMIOMacros-tool.product/Objects.LinkFileList").pathString])
225223
}
226224
}

Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import XCTest
2424

2525
final class SourceKitLSPAPITests: XCTestCase {
2626
func testBasicSwiftPackage() async throws {
27-
try skipOnWindowsAsTestCurrentlyFails()
28-
2927
let fs = InMemoryFileSystem(emptyFiles:
3028
"/Pkg/Sources/exe/main.swift",
3129
"/Pkg/Sources/exe/README.md",
@@ -89,7 +87,7 @@ final class SourceKitLSPAPITests: XCTestCase {
8987
"-package-name", "pkg",
9088
"-emit-dependencies",
9189
"-emit-module",
92-
"-emit-module-path", "/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/exe.swiftmodule"
90+
"-emit-module-path", AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/exe.swiftmodule").pathString
9391
],
9492
resources: [.init(filePath: "/Pkg/Sources/exe/Resources/some_file.txt")],
9593
ignoredFiles: [.init(filePath: "/Pkg/Sources/exe/exe.docc")],
@@ -104,7 +102,7 @@ final class SourceKitLSPAPITests: XCTestCase {
104102
"-package-name", "pkg",
105103
"-emit-dependencies",
106104
"-emit-module",
107-
"-emit-module-path", "/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule"
105+
"-emit-module-path", AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule").pathString
108106
],
109107
resources: [.init(filePath: "/Pkg/Sources/lib/Resources/some_file.txt")],
110108
ignoredFiles: [.init(filePath: "/Pkg/Sources/lib/lib.docc")],
@@ -115,7 +113,7 @@ final class SourceKitLSPAPITests: XCTestCase {
115113
for: "plugin",
116114
graph: graph,
117115
partialArguments: [
118-
"-I", "/fake/manifestLib/path"
116+
"-I", AbsolutePath("/fake/manifestLib/path").pathString
119117
],
120118
isPartOfRootPackage: true,
121119
destination: .host
@@ -318,7 +316,7 @@ final class SourceKitLSPAPITests: XCTestCase {
318316
"-package-name", "pkg",
319317
"-emit-dependencies",
320318
"-emit-module",
321-
"-emit-module-path", "/path/to/build/\(destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule".fixwin
319+
"-emit-module-path", AbsolutePath("/path/to/build/\(destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule").pathString
322320
],
323321
isPartOfRootPackage: true
324322
)
@@ -402,13 +400,3 @@ extension SourceKitLSPAPI.BuildDescription {
402400
return result
403401
}
404402
}
405-
406-
extension String {
407-
var fixwin: String {
408-
#if os(Windows)
409-
return self.replacingOccurrences(of: "/", with: "\\")
410-
#else
411-
return self
412-
#endif
413-
}
414-
}

0 commit comments

Comments
 (0)