Skip to content

Commit 499d7bc

Browse files
committed
Make tests run on Windows.
1 parent 3b3b779 commit 499d7bc

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ public struct AbsolutePath: Path {
204204
self.filepath = filepath.lexicallyNormalized()
205205
return
206206
}
207-
var filepath = filepath.lexicallyNormalized()
207+
var normalizedFilePath = filepath.lexicallyNormalized()
208208
guard filepath.root?.string == "\\" else {
209-
preconditionFailure()
209+
preconditionFailure("\(filepath) is not a valid absolute path")
210210
}
211-
self.filepath = AbsolutePath.root.filepath.pushing(filepath)
211+
normalizedFilePath.root = AbsolutePath.root.filepath.root
212+
self.filepath = normalizedFilePath.lexicallyNormalized()
212213
#else
213214
precondition(filepath.isAbsolute)
214215
self.filepath = filepath.lexicallyNormalized()

Sources/TSCTestSupport/misc.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import func XCTest.XCTFail
12+
import struct XCTest.XCTSkip
1213
import class Foundation.NSDate
1314
import class Foundation.Thread
1415

@@ -61,6 +62,9 @@ public func systemQuietly(_ args: String...) throws {
6162
/// from different threads, the environment will neither be setup nor restored
6263
/// correctly.
6364
public func withCustomEnv(_ env: [String: String], body: () throws -> Void) throws {
65+
#if os(Windows)
66+
throw XCTSkip("'withCustomEnv(_:body:)' is broken on Windows")
67+
#endif
6468
let state = Array(env.keys).map({ ($0, ProcessEnv.vars[$0]) })
6569
let restore = {
6670
for (key, value) in state {

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ class FileSystemTests: XCTestCase {
8787
}
8888
}
8989

90-
func testResolvingSymlinks() {
90+
func testResolvingSymlinks() throws {
91+
#if os(Windows)
92+
throw XCTSkip("Symlink resolving on Windows often crashes due to some Foundation bugs.")
93+
#endif
9194
// Make sure the root path resolves to itself.
9295
XCTAssertEqual(resolveSymlinks(AbsolutePath.root), AbsolutePath.root)
9396

@@ -186,6 +189,7 @@ class FileSystemTests: XCTestCase {
186189
}
187190
}
188191

192+
#if !os(Windows)
189193
func testLocalReadableWritable() throws {
190194
try testWithTemporaryDirectory { tmpdir in
191195
let fs = localFileSystem
@@ -253,6 +257,7 @@ class FileSystemTests: XCTestCase {
253257
}
254258
}
255259
}
260+
#endif
256261

257262
func testLocalCreateDirectory() throws {
258263
let fs = TSCBasic.localFileSystem

Tests/TSCBasicTests/PathTests.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ class PathTests: XCTestCase {
151151
}
152152

153153
func testBaseNameWithoutExt() {
154-
XCTAssertEqual(AbsolutePath("/").basenameWithoutExt, "/")
154+
XCTAssertEqual(AbsolutePath("/").basenameWithoutExt, AbsolutePath.root.pathString)
155155
XCTAssertEqual(AbsolutePath("/a").basenameWithoutExt, "a")
156156
XCTAssertEqual(AbsolutePath("/./a").basenameWithoutExt, "a")
157-
XCTAssertEqual(AbsolutePath("/../..").basenameWithoutExt, "/")
157+
XCTAssertEqual(AbsolutePath("/../..").basenameWithoutExt, AbsolutePath.root.pathString)
158158
XCTAssertEqual(RelativePath("../..").basenameWithoutExt, "..")
159159
XCTAssertEqual(RelativePath("../a").basenameWithoutExt, "a")
160160
XCTAssertEqual(RelativePath("../a/..").basenameWithoutExt, "..")
@@ -311,7 +311,12 @@ class PathTests: XCTestCase {
311311
}
312312

313313
func testAbsolutePathValidation() {
314-
XCTAssertNoThrow(try AbsolutePath(validating: "/a/b/c/d"))
314+
#if os(Windows)
315+
let pathString = #"C:\a\b\c\d"#
316+
#else
317+
let pathString = "/a/b/c/d"
318+
#endif
319+
XCTAssertNoThrow(try AbsolutePath(validating: pathString))
315320

316321
XCTAssertThrowsError(try AbsolutePath(validating: "~/a/b/d")) { error in
317322
XCTAssertEqual("\(error)", "invalid absolute path '~/a/b/d'")

Tests/TSCBasicTests/miscTests.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import TSCBasic
1515
class miscTests: XCTestCase {
1616

1717
func testExecutableLookup() throws {
18+
#if os(Windows)
19+
throw XCTSkip("TODO")
20+
#endif
1821
try testWithTemporaryDirectory { path in
19-
22+
2023
let pathEnv1 = path.appending(component: "pathEnv1")
2124
try localFileSystem.createDirectory(pathEnv1)
2225
let pathEnvClang = pathEnv1.appending(component: "clang")
@@ -28,15 +31,15 @@ class miscTests: XCTestCase {
2831
// nil and empty string should fail.
2932
XCTAssertNil(lookupExecutablePath(filename: nil, currentWorkingDirectory: path, searchPaths: pathEnv))
3033
XCTAssertNil(lookupExecutablePath(filename: "", currentWorkingDirectory: path, searchPaths: pathEnv))
31-
34+
3235
// Absolute path to a binary should return it.
3336
var exec = lookupExecutablePath(filename: pathEnvClang.pathString, currentWorkingDirectory: path, searchPaths: pathEnv)
3437
XCTAssertEqual(exec, pathEnvClang)
35-
38+
3639
// This should lookup from PATH variable since executable is not present in cwd.
3740
exec = lookupExecutablePath(filename: "clang", currentWorkingDirectory: path, searchPaths: pathEnv)
3841
XCTAssertEqual(exec, pathEnvClang)
39-
42+
4043
// Create the binary relative to cwd and make it executable.
4144
let clang = path.appending(component: "clang")
4245
try localFileSystem.writeFileContents(clang, bytes: "")
@@ -46,18 +49,23 @@ class miscTests: XCTestCase {
4649
XCTAssertEqual(exec, clang)
4750
}
4851
}
49-
52+
5053
func testEnvSearchPaths() throws {
54+
#if os(Windows)
55+
let pathString = "something;.;abc/../.build/debug;/usr/bin:/bin/"
56+
#else
57+
let pathString = "something:.:abc/../.build/debug:/usr/bin:/bin/"
58+
#endif
5159
let cwd = AbsolutePath("/dummy")
52-
let paths = getEnvSearchPaths(pathString: "something:.:abc/../.build/debug:/usr/bin:/bin/", currentWorkingDirectory: cwd)
60+
let paths = getEnvSearchPaths(pathString: pathString, currentWorkingDirectory: cwd)
5361
XCTAssertEqual(paths, ["/dummy/something", "/dummy", "/dummy/.build/debug", "/usr/bin", "/bin"].map({AbsolutePath($0)}))
5462
}
55-
63+
5664
func testEmptyEnvSearchPaths() throws {
5765
let cwd = AbsolutePath("/dummy")
5866
let paths = getEnvSearchPaths(pathString: "", currentWorkingDirectory: cwd)
5967
XCTAssertEqual(paths, [])
60-
68+
6169
let nilPaths = getEnvSearchPaths(pathString: nil, currentWorkingDirectory: cwd)
6270
XCTAssertEqual(nilPaths, [])
6371
}

Tests/TSCUtilityTests/PkgConfigParserTests.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ final class PkgConfigParserTests: XCTestCase {
107107
"/usr/lib/pkgconfig/foo.pc",
108108
"/usr/local/opt/foo/lib/pkgconfig/foo.pc",
109109
"/custom/foo.pc")
110-
XCTAssertEqual("/custom/foo.pc", try PCFileFinder(diagnostics: diagnostics, brewPrefix: nil).locatePCFile(name: "foo", customSearchPaths: [AbsolutePath("/custom")], fileSystem: fs).pathString)
111-
XCTAssertEqual("/custom/foo.pc", try PkgConfig(name: "foo", additionalSearchPaths: [AbsolutePath("/custom")], diagnostics: diagnostics, fileSystem: fs, brewPrefix: nil).pcFile.pathString)
112-
XCTAssertEqual("/usr/lib/pkgconfig/foo.pc", try PCFileFinder(diagnostics: diagnostics, brewPrefix: nil).locatePCFile(name: "foo", customSearchPaths: [], fileSystem: fs).pathString)
110+
XCTAssertEqual(AbsolutePath("/custom/foo.pc"), try PCFileFinder(diagnostics: diagnostics, brewPrefix: nil).locatePCFile(name: "foo", customSearchPaths: [AbsolutePath("/custom")], fileSystem: fs))
111+
XCTAssertEqual(AbsolutePath("/custom/foo.pc"), try PkgConfig(name: "foo", additionalSearchPaths: [AbsolutePath("/custom")], diagnostics: diagnostics, fileSystem: fs, brewPrefix: nil).pcFile)
112+
XCTAssertEqual(AbsolutePath("/usr/lib/pkgconfig/foo.pc"), try PCFileFinder(diagnostics: diagnostics, brewPrefix: nil).locatePCFile(name: "foo", customSearchPaths: [], fileSystem: fs))
113113
try withCustomEnv(["PKG_CONFIG_PATH": "/usr/local/opt/foo/lib/pkgconfig"]) {
114-
XCTAssertEqual("/usr/local/opt/foo/lib/pkgconfig/foo.pc", try PkgConfig(name: "foo", diagnostics: diagnostics, fileSystem: fs, brewPrefix: nil).pcFile.pathString)
114+
XCTAssertEqual(AbsolutePath("/usr/local/opt/foo/lib/pkgconfig/foo.pc"), try PkgConfig(name: "foo", diagnostics: diagnostics, fileSystem: fs, brewPrefix: nil).pcFile)
115115
}
116116
try withCustomEnv(["PKG_CONFIG_PATH": "/usr/local/opt/foo/lib/pkgconfig:/usr/lib/pkgconfig"]) {
117-
XCTAssertEqual("/usr/local/opt/foo/lib/pkgconfig/foo.pc", try PkgConfig(name: "foo", diagnostics: diagnostics, fileSystem: fs, brewPrefix: nil).pcFile.pathString)
117+
XCTAssertEqual(AbsolutePath("/usr/local/opt/foo/lib/pkgconfig/foo.pc"), try PkgConfig(name: "foo", diagnostics: diagnostics, fileSystem: fs, brewPrefix: nil).pcFile)
118118
}
119119
}
120120

@@ -142,6 +142,7 @@ final class PkgConfigParserTests: XCTestCase {
142142
XCTAssertEqual(PCFileFinder.pkgConfigPaths, [AbsolutePath("/Volumes/BestDrive/pkgconfig")])
143143
}
144144

145+
#if !os(Windows) // pkg-config is not compatible with Windows paths.
145146
func testAbsolutePathDependency() throws {
146147

147148
let libffiPath = "/usr/local/opt/libffi/lib/pkgconfig/libffi.pc"
@@ -171,6 +172,7 @@ final class PkgConfigParserTests: XCTestCase {
171172
fileSystem: fileSystem,
172173
brewPrefix: AbsolutePath("/usr/local")))
173174
}
175+
#endif
174176

175177
func testUnevenQuotes() throws {
176178
do {

0 commit comments

Comments
 (0)