Skip to content
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

[WIP] Tests: Skip failing tests on windows #8210

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions Sources/_InternalTestSupport/XCTSkipHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import XCTest
import class Basics.AsyncProcess
import struct TSCBasic.StringError

public func skipOnWindowsAsTestCurrentlyFails(because reason: String? = nil) throws {
#if os(Windows)
let failureCause: String
if reason == nil {
bkhouri marked this conversation as resolved.
Show resolved Hide resolved
failureCause = ""
} else {
failureCause = " because \(reason!.description)"
}
throw XCTSkip("Test fails on windows\(failureCause)")
#endif
}

extension Toolchain {
package func skipUnlessAtLeastSwift6(
file: StaticString = #file,
Expand Down
5 changes: 5 additions & 0 deletions Tests/BasicsTests/AsyncProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import func TSCBasic.withTemporaryFile
import func TSCTestSupport.withCustomEnv

final class AsyncProcessTests: XCTestCase {

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

func testBasics() throws {
do {
let process = AsyncProcess(args: "echo", "hello")
Expand Down
6 changes: 6 additions & 0 deletions Tests/BasicsTests/ConcurrencyHelpersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
import TSCTestSupport
import XCTest

import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails

final class ConcurrencyHelpersTest: XCTestCase {
let queue = DispatchQueue(label: "ConcurrencyHelpersTest", attributes: .concurrent)

override func setUpWithError() throws {
try skipOnWindowsAsTestCurrentlyFails()
}

func testThreadSafeKeyValueStore() {
for _ in 0 ..< 100 {
let sync = DispatchGroup()
Expand Down
12 changes: 9 additions & 3 deletions Tests/BasicsTests/Environment/EnvironmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import Basics

import XCTest
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails()

final class EnvironmentTests: XCTestCase {
func test_init() {
Expand All @@ -35,10 +36,11 @@ final class EnvironmentTests: XCTestCase {
"testKey": "TestValue2",
]
let environment = Environment(dictionary)
XCTAssertEqual(environment["TestKey"], "TestValue")
#if os(Windows)
XCTAssertEqual(environment["TestKey"], "TestValue2")
XCTAssertEqual(environment.count, 1)
#else
XCTAssertEqual(environment["TestKey"], "TestValue")
XCTAssertEqual(environment.count, 2)
#endif
}
Expand All @@ -47,6 +49,7 @@ final class EnvironmentTests: XCTestCase {
let dictionary = ["TestKey": "TestValue"]
let environment = Environment(dictionary)
XCTAssertEqual(environment["TestKey"], "TestValue")
XCTAssertEqual(environment.count, 1)
}

func path(_ components: String...) -> String {
Expand Down Expand Up @@ -99,10 +102,13 @@ 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() {
func test_current() throws {
try skipOnWindowsAsTestCurrentlyFails(because: "ProcessInfo.processInfo.environment[\"PATH\"] return nil")
Copy link
Member

Choose a reason for hiding this comment

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

It should return nil as the variable is spelt Path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. The test has been updated to run and pass on Windows.


XCTAssertEqual(
Environment.current["PATH"],
ProcessInfo.processInfo.environment["PATH"])
ProcessInfo.processInfo.environment["PATH"]
)
}

/// Important: This test is inherently race-prone, if it is proven to be
Expand Down
64 changes: 49 additions & 15 deletions Tests/BasicsTests/FileSystem/PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Basics
import Foundation
import XCTest

import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails()

#if os(Windows)
private var windows: Bool { true }
#else
Expand Down Expand Up @@ -54,28 +56,36 @@ class PathTests: XCTestCase {
XCTAssertEqual(rel2.pathString, "~") // `~` is not special
}

func testRepeatedPathSeparators() {
func testRepeatedPathSeparators() throws {
try skipOnWindowsAsTestCurrentlyFails(because: "all assertions fail")

XCTAssertEqual(AbsolutePath("/ab//cd//ef").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
XCTAssertEqual(AbsolutePath("/ab///cd//ef").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
XCTAssertEqual(RelativePath("ab//cd//ef").pathString, windows ? #"ab\cd\ef"# : "ab/cd/ef")
XCTAssertEqual(RelativePath("ab//cd///ef").pathString, windows ? #"ab\cd\ef"# : "ab/cd/ef")
}

func testTrailingPathSeparators() {
func testTrailingPathSeparators() throws {
try skipOnWindowsAsTestCurrentlyFails(because: "trailing path seperator is not removed from pathString")

XCTAssertEqual(AbsolutePath("/ab/cd/ef/").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
XCTAssertEqual(AbsolutePath("/ab/cd/ef//").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
XCTAssertEqual(RelativePath("ab/cd/ef/").pathString, windows ? #"ab\cd\ef"# : "ab/cd/ef")
XCTAssertEqual(RelativePath("ab/cd/ef//").pathString, windows ? #"ab\cd\ef"# : "ab/cd/ef")
}

func testDotPathComponents() {
func testDotPathComponents() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/ab/././cd//ef").pathString, "/ab/cd/ef")
XCTAssertEqual(AbsolutePath("/ab/./cd//ef/.").pathString, "/ab/cd/ef")
XCTAssertEqual(RelativePath("ab/./cd/././ef").pathString, "ab/cd/ef")
XCTAssertEqual(RelativePath("ab/./cd/ef/.").pathString, "ab/cd/ef")
}

func testDotDotPathComponents() {
func testDotDotPathComponents() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/..").pathString, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/../../../../..").pathString, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/abc/..").pathString, windows ? #"\"# : "/")
Expand All @@ -91,7 +101,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath("abc/..").pathString, ".")
}

func testCombinationsAndEdgeCases() {
func testCombinationsAndEdgeCases() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("///").pathString, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/./").pathString, windows ? #"\"# : "/")
XCTAssertEqual(RelativePath("").pathString, ".")
Expand Down Expand Up @@ -120,7 +132,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath("a/../////../////./////").pathString, "..")
}

func testDirectoryNameExtraction() {
func testDirectoryNameExtraction() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/").dirname, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/a").dirname, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/./a").dirname, windows ? #"\"# : "/")
Expand All @@ -137,7 +151,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath(".").dirname, ".")
}

func testBaseNameExtraction() {
func testBaseNameExtraction() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/").basename, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/a").basename, "a")
XCTAssertEqual(AbsolutePath("/./a").basename, "a")
Expand All @@ -153,7 +169,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath(".").basename, ".")
}

func testBaseNameWithoutExt() {
func testBaseNameWithoutExt() throws{
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/").basenameWithoutExt, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath("/a").basenameWithoutExt, "a")
XCTAssertEqual(AbsolutePath("/./a").basenameWithoutExt, "a")
Expand All @@ -176,7 +194,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath("abc.xyz.123").basenameWithoutExt, "abc.xyz")
}

func testSuffixExtraction() {
func testSuffixExtraction() throws {
try skipOnWindowsAsTestCurrentlyFails(because: "expected nil is not the actual")

XCTAssertEqual(RelativePath("a").suffix, nil)
XCTAssertEqual(RelativePath("a").extension, nil)
XCTAssertEqual(RelativePath("a.").suffix, nil)
Expand All @@ -201,7 +221,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath(".a.foo.bar.baz").extension, "baz")
}

func testParentDirectory() {
func testParentDirectory() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/").parentDirectory, AbsolutePath("/"))
XCTAssertEqual(AbsolutePath("/").parentDirectory.parentDirectory, AbsolutePath("/"))
XCTAssertEqual(AbsolutePath("/bar").parentDirectory, AbsolutePath("/"))
Expand All @@ -210,7 +232,9 @@ class PathTests: XCTestCase {
}

@available(*, deprecated)
func testConcatenation() {
func testConcatenation() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath(AbsolutePath("/"), RelativePath("")).pathString, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath(AbsolutePath("/"), RelativePath(".")).pathString, windows ? #"\"# : "/")
XCTAssertEqual(AbsolutePath(AbsolutePath("/"), RelativePath("..")).pathString, windows ? #"\"# : "/")
Expand Down Expand Up @@ -247,7 +271,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath("hello").appending(RelativePath("a/b/../c/d")).pathString, windows ? #"hello\a\c\d"# : "hello/a/c/d")
}

func testPathComponents() {
func testPathComponents() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/").components, ["/"])
XCTAssertEqual(AbsolutePath("/.").components, ["/"])
XCTAssertEqual(AbsolutePath("/..").components, ["/"])
Expand Down Expand Up @@ -275,7 +301,9 @@ class PathTests: XCTestCase {
XCTAssertEqual(RelativePath("abc").components, ["abc"])
}

func testRelativePathFromAbsolutePaths() {
func testRelativePathFromAbsolutePaths() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertEqual(AbsolutePath("/").relative(to: AbsolutePath("/")), RelativePath("."));
XCTAssertEqual(AbsolutePath("/a/b/c/d").relative(to: AbsolutePath("/")), RelativePath("a/b/c/d"));
XCTAssertEqual(AbsolutePath("/").relative(to: AbsolutePath("/a/b/c")), RelativePath("../../.."));
Expand Down Expand Up @@ -316,7 +344,9 @@ class PathTests: XCTestCase {
XCTAssertTrue(AbsolutePath("/foo").isAncestor(of: AbsolutePath("/foo/bar")))
}

func testAbsolutePathValidation() {
func testAbsolutePathValidation() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertNoThrow(try AbsolutePath(validating: "/a/b/c/d"))

XCTAssertThrowsError(try AbsolutePath(validating: "~/a/b/d")) { error in
Expand All @@ -328,7 +358,9 @@ class PathTests: XCTestCase {
}
}

func testRelativePathValidation() {
func testRelativePathValidation() throws {
try skipOnWindowsAsTestCurrentlyFails()

XCTAssertNoThrow(try RelativePath(validating: "a/b/c/d"))

XCTAssertThrowsError(try RelativePath(validating: "/a/b/d")) { error in
Expand All @@ -342,6 +374,8 @@ class PathTests: XCTestCase {
}

func testCodable() throws {
try skipOnWindowsAsTestCurrentlyFails()

struct Foo: Codable, Equatable {
var path: AbsolutePath
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/BasicsTests/FileSystem/VFSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import XCTest

import struct TSCBasic.ByteString

import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails

func testWithTemporaryDirectory(
function: StaticString = #function,
body: @escaping (AbsolutePath) async throws -> Void
Expand All @@ -36,6 +38,8 @@ func testWithTemporaryDirectory(

class VFSTests: XCTestCase {
func testLocalBasics() throws {
try skipOnWindowsAsTestCurrentlyFails()

// tiny PE binary from: https://archive.is/w01DO
let contents: [UInt8] = [
0x4d, 0x5a, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4c, 0x01, 0x01, 0x00,
Expand Down
2 changes: 2 additions & 0 deletions Tests/BasicsTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ final class HTTPClientTests: XCTestCase {
}

func testExponentialBackoff() async throws {
try skipOnWindowsAsTestCurrentlyFails()

let counter = SendableBox(0)
let lastCall = SendableBox<Date>()
let maxAttempts = 5
Expand Down
3 changes: 3 additions & 0 deletions Tests/BasicsTests/Serialization/SerializedJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

@testable import Basics
import XCTest
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails

final class SerializedJSONTests: XCTestCase {
func testPathInterpolation() throws {
try skipOnWindowsAsTestCurrentlyFails()

var path = try AbsolutePath(validating: #"/test\backslashes"#)
var json: SerializedJSON = "\(path)"

Expand Down
8 changes: 8 additions & 0 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,8 @@ final class BuildPlanTests: XCTestCase {
}

func test_symbolGraphExtract_arguments() async throws {
try skipOnWindowsAsTestCurrentlyFails()

// ModuleGraph:
// .
// ├── A (Swift)
Expand Down Expand Up @@ -4619,6 +4621,8 @@ final class BuildPlanTests: XCTestCase {
}

func testUserToolchainCompileFlags() async throws {
try skipOnWindowsAsTestCurrentlyFails()

let fs = InMemoryFileSystem(
emptyFiles:
"/Pkg/Sources/exe/main.swift",
Expand Down Expand Up @@ -4882,6 +4886,8 @@ final class BuildPlanTests: XCTestCase {
}

func testUserToolchainWithToolsetCompileFlags() async throws {
try skipOnWindowsAsTestCurrentlyFails()

let fileSystem = InMemoryFileSystem(
emptyFiles:
"/Pkg/Sources/exe/main.swift",
Expand Down Expand Up @@ -5050,6 +5056,8 @@ final class BuildPlanTests: XCTestCase {
}

func testUserToolchainWithSDKSearchPaths() async throws {
try skipOnWindowsAsTestCurrentlyFails()

let fileSystem = InMemoryFileSystem(
emptyFiles:
"/Pkg/Sources/exe/main.swift",
Expand Down
2 changes: 2 additions & 0 deletions Tests/BuildTests/BuildSystemDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ final class BuildSystemDelegateTests: XCTestCase {
}

func testFilterNonFatalCodesignMessages() async throws {
try skipOnWindowsAsTestCurrentlyFails()

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.
try await fixture(name: "Miscellaneous/TestableExe") { fixturePath in
Expand Down
2 changes: 2 additions & 0 deletions Tests/BuildTests/LLBuildManifestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ 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 Down
2 changes: 2 additions & 0 deletions Tests/BuildTests/PluginsBuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import PackageModel

final class PluginsBuildPlanTests: XCTestCase {
func testBuildToolsDatabasePath() async throws {
try skipOnWindowsAsTestCurrentlyFails()

try await fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in
let (stdout, _) = try await executeSwiftBuild(fixturePath)
XCTAssertMatch(stdout, .contains("Build complete!"))
Expand Down
Loading