Skip to content

Fixes many tests (plus skips) to get more tests running on windows #8609

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
merged 1 commit into from
May 15, 2025
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
#if os(macOS) || os(iOS)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Bionic)
import Bionic
#endif

public extension Collection {
func shuffle() -> [Iterator.Element] {
Expand All @@ -24,15 +15,13 @@ public extension MutableCollection {
guard c > 1 else { return }

for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
#if os(macOS) || os(iOS)
let d = arc4random_uniform(numericCast(unshuffledCount))
#else
let d = numericCast(random()) % unshuffledCount
#endif
let i = index(firstUnshuffled, offsetBy: numericCast(d))
var g = SystemRandomNumberGenerator()
let d = Int.random(in: 1...unshuffledCount, using: &g)
let i = index(firstUnshuffled, offsetBy: d)
swapAt(firstUnshuffled, i)
}
}
}


public let shuffle = false
5 changes: 4 additions & 1 deletion Fixtures/Miscellaneous/AtMainSupport/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ let package = Package(
.executable(name: "SwiftExecMultiFile", targets: ["SwiftExecMultiFile"]),
],
targets: [
.executableTarget(name: "ClangExecSingleFile"),
.executableTarget(name: "ClangExecSingleFile",
linkerSettings: [
.linkedLibrary("swiftCore", .when(platforms: [.windows])), // for swift_addNewDSOImage
]),
.executableTarget(name: "SwiftExecSingleFile"),
.executableTarget(name: "SwiftExecMultiFile"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import Musl
#elseif canImport(Android)
import Android
#else
#elseif canImport(Darwin.C)
import Darwin.C
#elseif canImport(ucrt)
import ucrt
let PATH_MAX = 260
typealias Int = Int32
#endif

let cwd = getcwd(nil, Int(PATH_MAX))
Expand Down
2 changes: 2 additions & 0 deletions Fixtures/Miscellaneous/EchoExecutable/echo.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo sentinel
echo %*
6 changes: 6 additions & 0 deletions Fixtures/Miscellaneous/EchoExecutable/toolset.win32.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"debugger": { "path": "echo.bat" },
"testRunner": { "path": "echo.bat" },
"schemaVersion" : "1.0",
"rootPath" : "."
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 6.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (possibly-blocking): Although this seems like a very simple change, I fear this might introduce regression as the swift-tools-version for the test package was set for 5.7 for a reason.

What is the purpose of updating this? Can we revert this back to 5.7 and maybe disable (or mark the test as expected failure)?

Copy link
Contributor Author

@daveinglis daveinglis May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating the plugin to use URL API instead of Path requires this.


import PackageDescription

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import PackagePlugin
import Foundation

#if os(Android)
let touchExe = "/system/bin/touch"
let touchArgs: [String] = []
#elseif os(Windows)
let touchExe = "C:/Windows/System32/cmd.exe"
let touchArgs = ["/c", "copy", "NUL"]
#else
let touchExe = "/usr/bin/touch"
let touchArgs: [String] = []
#endif

@main
Expand All @@ -12,9 +18,9 @@ struct GeneratorPlugin: BuildToolPlugin {
return [
.prebuildCommand(
displayName: "Generating empty file",
executable: .init(touchExe),
arguments: [context.pluginWorkDirectory.appending("best.txt")],
outputFilesDirectory: context.pluginWorkDirectory
executable: .init(fileURLWithPath: touchExe),
arguments: touchArgs + [String(cString: (context.pluginWorkDirectoryURL.appending(path: "best.txt") as NSURL).fileSystemRepresentation)],
outputFilesDirectory: context.pluginWorkDirectoryURL
)
]
}
Expand Down
16 changes: 13 additions & 3 deletions Fixtures/Miscellaneous/TestableExe/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ let package = Package(
name: "TestableExe",
targets: [
.executableTarget(
name: "TestableExe1"
name: "TestableExe1",
linkerSettings: [
.linkedLibrary("swiftCore", .when(platforms: [.windows])), // for swift_addNewDSOImage
]
),
.executableTarget(
name: "TestableExe2"
name: "TestableExe2",
linkerSettings: [
.linkedLibrary("swiftCore", .when(platforms: [.windows])), // for swift_addNewDSOImage
]

),
.executableTarget(
name: "TestableExe3"
name: "TestableExe3",
linkerSettings: [
.linkedLibrary("swiftCore", .when(platforms: [.windows])), // for swift_addNewDSOImage
]
),
.testTarget(
name: "TestableExeTests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import XCTest
import class Foundation.Bundle

final class TestableExeTests: XCTestCase {

#if os(Windows)
let eol = "\r\n"
#else
let eol = "\n"
#endif

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
Expand All @@ -30,7 +37,7 @@ final class TestableExeTests: XCTestCase {
process.waitUntilExit()
var data = pipe.fileHandleForReading.readDataToEndOfFile()
var output = String(data: data, encoding: .utf8)
XCTAssertEqual(output, "Hello, world!\n")
XCTAssertEqual(output, "Hello, world!\(eol)")

execPath = productsDirectory.appendingPathComponent("TestableExe2")
process = Process()
Expand All @@ -41,7 +48,7 @@ final class TestableExeTests: XCTestCase {
process.waitUntilExit()
data = pipe.fileHandleForReading.readDataToEndOfFile()
output = String(data: data, encoding: .utf8)
XCTAssertEqual(output, "Hello, planet!\n")
XCTAssertEqual(output, "Hello, planet!\(eol)")

execPath = productsDirectory.appendingPathComponent("TestableExe3")
process = Process()
Expand All @@ -52,7 +59,7 @@ final class TestableExeTests: XCTestCase {
process.waitUntilExit()
data = pipe.fileHandleForReading.readDataToEndOfFile()
output = String(data: data, encoding: .utf8)
XCTAssertEqual(output, "Hello, universe!\n")
XCTAssertEqual(output, "Hello, universe!\(eol)")
}

/// Returns path to the built products directory.
Expand Down
22 changes: 7 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,13 @@ let package = Package(
dependencies: ["XCBuildSupport", "_InternalTestSupport", "_InternalBuildTestSupport"],
exclude: ["Inputs/Foo.pc"]
),
.testTarget(
name: "FunctionalPerformanceTests",
dependencies: [
"swift-package-manager",
"_InternalTestSupport",
]
),
// Examples (These are built to ensure they stay up to date with the API.)
.executableTarget(
name: "package-info",
Expand All @@ -964,19 +971,6 @@ package.targets.append(contentsOf: [
])
#endif

// Workaround SwiftPM's attempt to link in executables which does not work on all
// platforms.
#if !os(Windows)
package.targets.append(contentsOf: [
.testTarget(
name: "FunctionalPerformanceTests",
dependencies: [
"swift-package-manager",
"_InternalTestSupport",
]
),
])

// rdar://101868275 "error: cannot find 'XCTAssertEqual' in scope" can affect almost any functional test, so we flat out
// disable them all until we know what is going on
if ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] == nil {
Expand All @@ -989,7 +983,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] ==
"_InternalTestSupport",
]
),

.executableTarget(
name: "dummy-swiftc",
dependencies: [
Expand Down Expand Up @@ -1020,7 +1013,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] ==
),
])
}
#endif


func swiftSyntaxDependencies(_ names: [String]) -> [Target.Dependency] {
Expand Down
7 changes: 6 additions & 1 deletion Sources/Build/LLBuildProgressTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,14 @@ private struct CommandTaskTracker {
}

private func progressText(of command: SPMLLBuild.Command, targetName: String?) -> String {
#if os(Windows)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): can we define the path separator in a common location so we don't have to redefine it multiple times whenever a test requires it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something to consider maybe if we ever vender in the TSC Path stuff into swift pm to remove that dependency... some day...

let pathSep: Character = "\\"
#else
let pathSep: Character = "/"
#endif
// Transforms descriptions like "Linking ./.build/x86_64-apple-macosx/debug/foo" into "Linking foo".
if let firstSpaceIndex = command.description.firstIndex(of: " "),
let lastDirectorySeparatorIndex = command.description.lastIndex(of: "/")
let lastDirectorySeparatorIndex = command.description.lastIndex(of: pathSep)
{
let action = command.description[..<firstSpaceIndex]
let fileNameStartIndex = command.description.index(after: lastDirectorySeparatorIndex)
Expand Down
6 changes: 3 additions & 3 deletions Sources/_InternalTestSupport/SwiftPMProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ extension SwiftPM {
packagePath: packagePath,
env: env
)

let stdout = try result.utf8Output()
let stderr = try result.utf8stderrOutput()
//Remove /r from stdout/stderr so that tests do not have to deal with them
let stdout = try String(decoding: result.output.get().filter( { $0 != 13 }), as: Unicode.UTF8.self)
let stderr = try String(decoding: result.stderrOutput.get().filter( { $0 != 13 }), as: Unicode.UTF8.self)

let returnValue = (stdout: stdout, stderr: stderr)
if (!throwIfCommandFails) { return returnValue }
Expand Down
17 changes: 17 additions & 0 deletions Sources/_InternalTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,20 @@ public func getNumberOfMatches(of match: String, in value: String) -> Int {
guard match.count != 0 else { return 0 }
return value.ranges(of: match).count
}

public extension String {
var withSwiftLineEnding: String {
return replacingOccurrences(of: "\r\n", with: "\n")
}
}

public func executableName(_ name: String) -> String {
#if os(Windows)
if name.count > 4, name.suffix(from: name.index(name.endIndex, offsetBy: -4)) == ProcessInfo.exeSuffix {
return name
}
return "\(name)\(ProcessInfo.exeSuffix)"
#else
return name
#endif
}
6 changes: 4 additions & 2 deletions Tests/BasicsTests/AsyncProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ final class AsyncProcessTests: XCTestCase {
}

func testFindExecutable() throws {
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: Assertion failure when trying to find ls executable")

try testWithTemporaryDirectory { tmpdir in
// This process should always work.
#if os(Windows)
XCTAssertTrue(AsyncProcess.findExecutable("cmd.exe") != nil)
#else
XCTAssertTrue(AsyncProcess.findExecutable("ls") != nil)
#endif

XCTAssertEqual(AsyncProcess.findExecutable("nonExistantProgram"), nil)
XCTAssertEqual(AsyncProcess.findExecutable(""), nil)
Expand Down
2 changes: 0 additions & 2 deletions Tests/BasicsTests/FileSystem/VFSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import Testing

import struct TSCBasic.ByteString

import _InternalTestSupport // for XCTSkipOnWindows

func testWithTemporaryDirectory(
function: StaticString = #function,
body: @escaping (AbsolutePath) async throws -> Void
Expand Down
5 changes: 2 additions & 3 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {

func testPackageNameFlag() async throws {
try XCTSkipIfPlatformCI() // test is disabled because it isn't stable, see rdar://118239206
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: 'swift test' was hanging.")
let isFlagSupportedInDriver = try DriverSupport.checkToolchainDriverFlags(
flags: ["package-name"],
toolchain: UserToolchain.default,
Expand Down Expand Up @@ -7279,9 +7280,7 @@ class BuildPlanSwiftBuildTests: BuildPlanTestCase {

override func testPackageNameFlag() async throws {
try XCTSkipIfWorkingDirectoryUnsupported()
#if os(Windows)
throw XCTSkip("Skip until there is a resolution to the partial linking with Windows that results in a 'subsystem must be defined' error.")
#endif
try XCTSkipOnWindows(because: "Skip until there is a resolution to the partial linking with Windows that results in a 'subsystem must be defined' error.")
#if os(Linux)
// Linking error: "/usr/bin/ld.gold: fatal error: -pie and -static are incompatible".
// Tracked by GitHub issue: https://github.com/swiftlang/swift-package-manager/issues/8499
Expand Down
Loading