Skip to content

Commit fece6dd

Browse files
committed
Fix tests on macOS 13
- Python is no longer installed in `/usr/bin`, so support `/usr/local` as well. In the medium term, we should not depend on Python for these tests. - Seems like the expected results for a certain file system test changed, this makes a conditional change for running the test on macOS 13.
1 parent 84449cd commit fece6dd

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,13 @@ class FileSystemTests: XCTestCase {
331331
_ = try fs.readFileContents(root)
332332

333333
}
334-
XCTAssertThrows(FileSystemError(.isDirectory, root)) {
334+
let expectedError: FileSystemError
335+
if #available(macOS 13, *) {
336+
expectedError = FileSystemError(.ioError(code: TSCLibc.EEXIST), root)
337+
} else {
338+
expectedError = FileSystemError(.isDirectory, root)
339+
}
340+
XCTAssertThrows(expectedError) {
335341
try fs.writeFileContents(root, bytes: [])
336342
}
337343
XCTAssert(fs.exists(filePath))

Tests/TSCBasicTests/ProcessTests.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ typealias ProcessID = TSCBasic.Process.ProcessID
1919
typealias Process = TSCBasic.Process
2020

2121
class ProcessTests: XCTestCase {
22+
func env() -> [String:String] {
23+
var env = ProcessEnv.vars
24+
#if os(macOS)
25+
// Many of these tests use Python which might not be in the default `PATH` when running these tests from Xcode.
26+
env["PATH"] = "\(env["PATH"] ?? ""):/usr/local/bin"
27+
#endif
28+
return env
29+
}
30+
2231
func script(_ name: String) -> String {
2332
return AbsolutePath(#file).parentDirectory.appending(components: "processInputs", name).pathString
2433
}
@@ -255,7 +264,7 @@ class ProcessTests: XCTestCase {
255264

256265
func testStdin() throws {
257266
var stdout = [UInt8]()
258-
let process = Process(args: script("in-to-out"), outputRedirection: .stream(stdout: { stdoutBytes in
267+
let process = Process(args: script("in-to-out"), environment: env(), outputRedirection: .stream(stdout: { stdoutBytes in
259268
stdout += stdoutBytes
260269
}, stderr: { _ in }))
261270
let stdinStream = try process.launch()
@@ -273,22 +282,22 @@ class ProcessTests: XCTestCase {
273282
func testStdoutStdErr() throws {
274283
// A simple script to check that stdout and stderr are captured separatly.
275284
do {
276-
let result = try Process.popen(args: script("simple-stdout-stderr"))
285+
let result = try Process.popen(args: script("simple-stdout-stderr"), environment: env())
277286
XCTAssertEqual(try result.utf8Output(), "simple output\n")
278287
XCTAssertEqual(try result.utf8stderrOutput(), "simple error\n")
279288
}
280289

281290
// A long stdout and stderr output.
282291
do {
283-
let result = try Process.popen(args: script("long-stdout-stderr"))
292+
let result = try Process.popen(args: script("long-stdout-stderr"), environment: env())
284293
let count = 16 * 1024
285294
XCTAssertEqual(try result.utf8Output(), String(repeating: "1", count: count))
286295
XCTAssertEqual(try result.utf8stderrOutput(), String(repeating: "2", count: count))
287296
}
288297

289298
// This script will block if the streams are not read.
290299
do {
291-
let result = try Process.popen(args: script("deadlock-if-blocking-io"))
300+
let result = try Process.popen(args: script("deadlock-if-blocking-io"), environment: env())
292301
let count = 16 * 1024
293302
XCTAssertEqual(try result.utf8Output(), String(repeating: "1", count: count))
294303
XCTAssertEqual(try result.utf8stderrOutput(), String(repeating: "2", count: count))
@@ -298,7 +307,7 @@ class ProcessTests: XCTestCase {
298307
func testStdoutStdErrRedirected() throws {
299308
// A simple script to check that stdout and stderr are captured in the same location.
300309
do {
301-
let process = Process(args: script("simple-stdout-stderr"), outputRedirection: .collect(redirectStderr: true))
310+
let process = Process(args: script("simple-stdout-stderr"), environment: env(), outputRedirection: .collect(redirectStderr: true))
302311
try process.launch()
303312
let result = try process.waitUntilExit()
304313
XCTAssertEqual(try result.utf8Output(), "simple error\nsimple output\n")
@@ -307,7 +316,7 @@ class ProcessTests: XCTestCase {
307316

308317
// A long stdout and stderr output.
309318
do {
310-
let process = Process(args: script("long-stdout-stderr"), outputRedirection: .collect(redirectStderr: true))
319+
let process = Process(args: script("long-stdout-stderr"), environment: env(), outputRedirection: .collect(redirectStderr: true))
311320
try process.launch()
312321
let result = try process.waitUntilExit()
313322

@@ -320,7 +329,7 @@ class ProcessTests: XCTestCase {
320329
func testStdoutStdErrStreaming() throws {
321330
var stdout = [UInt8]()
322331
var stderr = [UInt8]()
323-
let process = Process(args: script("long-stdout-stderr"), outputRedirection: .stream(stdout: { stdoutBytes in
332+
let process = Process(args: script("long-stdout-stderr"), environment: env(), outputRedirection: .stream(stdout: { stdoutBytes in
324333
stdout += stdoutBytes
325334
}, stderr: { stderrBytes in
326335
stderr += stderrBytes
@@ -336,7 +345,7 @@ class ProcessTests: XCTestCase {
336345
func testStdoutStdErrStreamingRedirected() throws {
337346
var stdout = [UInt8]()
338347
var stderr = [UInt8]()
339-
let process = Process(args: script("long-stdout-stderr"), outputRedirection: .stream(stdout: { stdoutBytes in
348+
let process = Process(args: script("long-stdout-stderr"), environment: env(), outputRedirection: .stream(stdout: { stdoutBytes in
340349
stdout += stdoutBytes
341350
}, stderr: { stderrBytes in
342351
stderr += stderrBytes

0 commit comments

Comments
 (0)