Skip to content

Tests: Enable tests on Windows #8466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 81 additions & 25 deletions Tests/BasicsTests/AsyncProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ import func TSCBasic.withTemporaryFile
import func TSCTestSupport.withCustomEnv

final class AsyncProcessTests: XCTestCase {
#if os(Windows)
let executableExt = ".exe"
#else
let executableExt = ""
#endif

override func setUp() async throws {
try skipOnWindowsAsTestCurrentlyFails()
}

func testBasics() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "echo.exe")"
""")

do {
let process = AsyncProcess(args: "echo", "hello")
let process = AsyncProcess(args: "echo\(executableExt)", "hello")
try process.launch()
let result = try process.waitUntilExit()
XCTAssertEqual(try result.utf8Output(), "hello\n")
Expand All @@ -46,27 +51,26 @@ final class AsyncProcessTests: XCTestCase {
}
}

func testPopen() throws {
#if os(Windows)
let echo = "echo.exe"
#else
let echo = "echo"
#endif
func testPopenBasic() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "echo.exe")"
""")

// Test basic echo.
XCTAssertEqual(try AsyncProcess.popen(arguments: [echo, "hello"]).utf8Output(), "hello\n")
XCTAssertEqual(try AsyncProcess.popen(arguments: ["echo\(executableExt)", "hello"]).utf8Output(), "hello\n")
}

func testPopenWithBufferLargerThanAllocated() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "cat.exe")"
""")
// Test buffer larger than that allocated.
try withTemporaryFile { file in
let count = 10000
let stream = BufferedOutputByteStream()
stream.send(Format.asRepeating(string: "a", count: count))
try localFileSystem.writeFileContents(file.path, bytes: stream.bytes)
#if os(Windows)
let cat = "cat.exe"
#else
let cat = "cat"
#endif
let outputCount = try AsyncProcess.popen(args: cat, file.path.pathString).utf8Output().count
let outputCount = try AsyncProcess.popen(args: "cat\(executableExt)", file.path.pathString).utf8Output().count
XCTAssert(outputCount == count)
}
}
Expand Down Expand Up @@ -119,8 +123,12 @@ final class AsyncProcessTests: XCTestCase {
}

func testCheckNonZeroExit() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "echo.exe")"
""")

do {
let output = try AsyncProcess.checkNonZeroExit(args: "echo", "hello")
let output = try AsyncProcess.checkNonZeroExit(args: "echo\(executableExt)", "hello")
XCTAssertEqual(output, "hello\n")
}

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

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testCheckNonZeroExitAsync() async throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "echo.exe")"
""")

do {
let output = try await AsyncProcess.checkNonZeroExit(args: "echo", "hello")
let output = try await AsyncProcess.checkNonZeroExit(args: "echo\(executableExt)", "hello")
XCTAssertEqual(output, "hello\n")
}

Expand All @@ -148,6 +160,8 @@ final class AsyncProcessTests: XCTestCase {
}

func testFindExecutable() throws {
try skipOnWindowsAsTestCurrentlyFails(because: "Assertion failure when trying to find ls executable")

try testWithTemporaryDirectory { tmpdir in
// This process should always work.
XCTAssertTrue(AsyncProcess.findExecutable("ls") != nil)
Expand Down Expand Up @@ -192,7 +206,11 @@ final class AsyncProcessTests: XCTestCase {
}

func testThreadSafetyOnWaitUntilExit() throws {
let process = AsyncProcess(args: "echo", "hello")
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "echo.exe")"
""")

let process = AsyncProcess(args: "echo\(executableExt)", "hello")
try process.launch()

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

@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
func testThreadSafetyOnWaitUntilExitAsync() async throws {
let process = AsyncProcess(args: "echo", "hello")
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "echo.exe")"
""")

let process = AsyncProcess(args: "echo\(executableExt)", "hello")
try process.launch()

let t1 = Task {
Expand All @@ -236,6 +258,10 @@ final class AsyncProcessTests: XCTestCase {
}

func testStdin() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

var stdout = [UInt8]()
let process = AsyncProcess(scriptName: "in-to-out", outputRedirection: .stream(stdout: { stdoutBytes in
stdout += stdoutBytes
Expand All @@ -253,6 +279,10 @@ final class AsyncProcessTests: XCTestCase {
}

func testStdoutStdErr() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

// A simple script to check that stdout and stderr are captured separatly.
do {
let result = try AsyncProcess.popen(scriptName: "simple-stdout-stderr")
Expand All @@ -279,6 +309,10 @@ final class AsyncProcessTests: XCTestCase {

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testStdoutStdErrAsync() async throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

// A simple script to check that stdout and stderr are captured separatly.
do {
let result = try await AsyncProcess.popen(scriptName: "simple-stdout-stderr")
Expand All @@ -304,6 +338,10 @@ final class AsyncProcessTests: XCTestCase {
}

func testStdoutStdErrRedirected() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

// A simple script to check that stdout and stderr are captured in the same location.
do {
let process = AsyncProcess(
Expand Down Expand Up @@ -332,6 +370,10 @@ final class AsyncProcessTests: XCTestCase {
}

func testStdoutStdErrStreaming() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

var stdout = [UInt8]()
var stderr = [UInt8]()
let process = AsyncProcess(scriptName: "long-stdout-stderr", outputRedirection: .stream(stdout: { stdoutBytes in
Expand All @@ -348,6 +390,10 @@ final class AsyncProcessTests: XCTestCase {
}

func testStdoutStdErrStreamingRedirected() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

var stdout = [UInt8]()
var stderr = [UInt8]()
let process = AsyncProcess(scriptName: "long-stdout-stderr", outputRedirection: .stream(stdout: { stdoutBytes in
Expand All @@ -364,6 +410,10 @@ final class AsyncProcessTests: XCTestCase {
}

func testWorkingDirectory() throws {
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "missingExecutableProgram(program: "cat.exe")"
""")

guard #available(macOS 10.15, *) else {
// Skip this test since it's not supported in this OS.
return
Expand All @@ -385,7 +435,7 @@ final class AsyncProcessTests: XCTestCase {
try localFileSystem.writeFileContents(childPath, bytes: ByteString("child"))

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

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

let process = AsyncProcess(
scriptName: "echo",
scriptName: "echo\(executableExt)",
outputRedirection: .stream {
stdoutContinuation.yield($0)
} stderr: {
Expand Down Expand Up @@ -460,9 +513,12 @@ final class AsyncProcessTests: XCTestCase {
func testAsyncStreamHighLevelAPI() async throws {
// rdar://133548796
try XCTSkipIfCI()
try skipOnWindowsAsTestCurrentlyFails(because: """
threw error "Error Domain=NSCocoaErrorDomain Code=3584 "(null)"UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 "(null)"}"
""")

let result = try await AsyncProcess.popen(
scriptName: "echo",
scriptName: "echo\(executableExt)",
stdout: { stdin, stdout in
var counter = 0
stdin.write("Hello \(counter)\n")
Expand Down
3 changes: 0 additions & 3 deletions Tests/BasicsTests/Environment/EnvironmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Basics

import XCTest
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails()

final class EnvironmentTests: XCTestCase {
func test_init() {
Expand Down Expand Up @@ -103,8 +102,6 @@ final class EnvironmentTests: XCTestCase {
/// Important: This test is inherently race-prone, if it is proven to be
/// flaky, it should run in a singled threaded environment/removed entirely.
func test_current() throws {
try skipOnWindowsAsTestCurrentlyFails(because: "ProcessInfo.processInfo.environment[pathEnvVarName] return nil in the docker container")

#if os(Windows)
let pathEnvVarName = "Path"
#else
Expand Down
9 changes: 7 additions & 2 deletions Tests/BuildTests/BuildSystemDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ final class BuildSystemDelegateTests: XCTestCase {
}

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

try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
// Note: we can re-use the `TestableExe` fixture here since we just need an executable.
#if os(Windows)
let executableExt = ".exe"
#else
let executableExt = ""
#endif
try await fixture(name: "Miscellaneous/TestableExe") { fixturePath in
_ = try await executeSwiftBuild(fixturePath)
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1")
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1\(executableExt)")
XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'")
try localFileSystem.removeFileTree(execPath)
let (fullLog, _) = try await executeSwiftBuild(fixturePath)
Expand Down
4 changes: 1 addition & 3 deletions Tests/BuildTests/LLBuildManifestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ final class LLBuildManifestBuilderTests: XCTestCase {

/// Verifies that two modules with the same name but different triples don't share same build manifest keys.
func testToolsBuildTriple() async throws {
try skipOnWindowsAsTestCurrentlyFails()

let (graph, fs, scope) = try macrosPackageGraph()
let productsTriple = Triple.x86_64MacOS
let toolsTriple = Triple.arm64Linux
Expand All @@ -221,6 +219,6 @@ final class LLBuildManifestBuilderTests: XCTestCase {

XCTAssertNotNil(manifest.commands["C.SwiftSyntax-aarch64-unknown-linux-gnu-debug-tool.module"])
// Ensure that Objects.LinkFileList is -tool suffixed.
XCTAssertNotNil(manifest.commands["/path/to/build/aarch64-unknown-linux-gnu/debug/MMIOMacros-tool.product/Objects.LinkFileList"])
XCTAssertNotNil(manifest.commands[AbsolutePath("/path/to/build/aarch64-unknown-linux-gnu/debug/MMIOMacros-tool.product/Objects.LinkFileList").pathString])
}
}
20 changes: 4 additions & 16 deletions Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import XCTest

final class SourceKitLSPAPITests: XCTestCase {
func testBasicSwiftPackage() async throws {
try skipOnWindowsAsTestCurrentlyFails()

let fs = InMemoryFileSystem(emptyFiles:
"/Pkg/Sources/exe/main.swift",
"/Pkg/Sources/exe/README.md",
Expand Down Expand Up @@ -89,7 +87,7 @@ final class SourceKitLSPAPITests: XCTestCase {
"-package-name", "pkg",
"-emit-dependencies",
"-emit-module",
"-emit-module-path", "/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/exe.swiftmodule"
"-emit-module-path", AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/exe.swiftmodule").pathString
],
resources: [.init(filePath: "/Pkg/Sources/exe/Resources/some_file.txt")],
ignoredFiles: [.init(filePath: "/Pkg/Sources/exe/exe.docc")],
Expand All @@ -104,7 +102,7 @@ final class SourceKitLSPAPITests: XCTestCase {
"-package-name", "pkg",
"-emit-dependencies",
"-emit-module",
"-emit-module-path", "/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule"
"-emit-module-path", AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule").pathString
],
resources: [.init(filePath: "/Pkg/Sources/lib/Resources/some_file.txt")],
ignoredFiles: [.init(filePath: "/Pkg/Sources/lib/lib.docc")],
Expand All @@ -115,7 +113,7 @@ final class SourceKitLSPAPITests: XCTestCase {
for: "plugin",
graph: graph,
partialArguments: [
"-I", "/fake/manifestLib/path"
"-I", AbsolutePath("/fake/manifestLib/path").pathString
],
isPartOfRootPackage: true,
destination: .host
Expand Down Expand Up @@ -318,7 +316,7 @@ final class SourceKitLSPAPITests: XCTestCase {
"-package-name", "pkg",
"-emit-dependencies",
"-emit-module",
"-emit-module-path", "/path/to/build/\(destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule".fixwin
"-emit-module-path", AbsolutePath("/path/to/build/\(destinationBuildParameters.triple)/debug/Modules/lib.swiftmodule").pathString
],
isPartOfRootPackage: true
)
Expand Down Expand Up @@ -402,13 +400,3 @@ extension SourceKitLSPAPI.BuildDescription {
return result
}
}

extension String {
var fixwin: String {
#if os(Windows)
return self.replacingOccurrences(of: "/", with: "\\")
#else
return self
#endif
}
}
Loading