Skip to content

Commit d017c57

Browse files
committed
Tests: Conditionally skip the Archiver tests
The Archiver tests has a dependency on a system binary being available on the host. Update the archiver test to skip the test is the required executable is not available on the system. Fixes: #8586 Issue: rdar://150414402
1 parent bdfd754 commit d017c57

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

Sources/_InternalTestSupport/XCTAssertHelpers.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ public func XCTSkipOnWindows(because reason: String? = nil, skipPlatformCi: Bool
7676
#endif
7777
}
7878

79+
public func _requiresTools(_ executable: String) throws {
80+
func getAsyncProcessArgs(_ executable: String) -> [String] {
81+
#if os(Windows)
82+
let args = ["cmd.exe", "/c", "where.exe", executable]
83+
#else
84+
let args = ["which", executable]
85+
#endif
86+
return args
87+
}
88+
try AsyncProcess.checkNonZeroExit(arguments: getAsyncProcessArgs(executable))
89+
}
90+
public func XCTRequires(
91+
executable: String,
92+
file: StaticString = #filePath,
93+
line: UInt = #line
94+
) throws {
95+
96+
do {
97+
try _requiresTools(executable)
98+
} catch (let AsyncProcessResult.Error.nonZeroExit(result)) {
99+
throw XCTSkip(
100+
"Skipping as tool \(executable) is not found in the path. (\(result.description))")
101+
}
102+
}
103+
79104
/// An `async`-friendly replacement for `XCTAssertThrowsError`.
80105
public func XCTAssertAsyncThrowsError<T>(
81106
_ expression: @autoclosure () async throws -> T,

Tests/BasicsTests/Archiver/TarArchiverTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import XCTest
1818
import struct TSCBasic.FileSystemError
1919

2020
final class TarArchiverTests: XCTestCase {
21+
override func setUp() async throws {
22+
#if os(Windows)
23+
let requiredProcess = "tar.exe"
24+
#else
25+
let requiredProcess = "tar"
26+
#endif
27+
try XCTRequires(executable: requiredProcess)
28+
}
29+
2130
func testSuccess() async throws {
2231
try await testWithTemporaryDirectory { tmpdir in
2332
let archiver = TarArchiver(fileSystem: localFileSystem)

Tests/BasicsTests/Archiver/UniversalArchiverTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ import XCTest
1818
import struct TSCBasic.FileSystemError
1919

2020
final class UniversalArchiverTests: XCTestCase {
21+
override func setUp() async throws {
22+
#if os(Windows)
23+
let requiredTarProcess = "tar.exe"
24+
let requiredZipProcess = "zip.exe"
25+
#else
26+
let requiredTarProcess = "tar"
27+
let requiredZipProcess = "zip"
28+
#endif
29+
try XCTRequires(executable: requiredTarProcess)
30+
try XCTRequires(executable: requiredZipProcess)
31+
}
32+
2133
func testSuccess() async throws {
2234
try await testWithTemporaryDirectory { tmpdir in
2335
let archiver = UniversalArchiver(localFileSystem)

Tests/BasicsTests/Archiver/ZipArchiverTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported
1818
import struct TSCBasic.FileSystemError
1919

2020
final class ZipArchiverTests: XCTestCase {
21+
override func setUp() async throws {
22+
#if os(Windows)
23+
let requiredProcess = "zip.exe"
24+
#else
25+
let requiredProcess = "zip"
26+
#endif
27+
try XCTRequires(executable: requiredProcess)
28+
}
29+
2130
func testZipArchiverSuccess() async throws {
2231
try await testWithTemporaryDirectory { tmpdir in
2332
let archiver = ZipArchiver(fileSystem: localFileSystem)

Tests/_InternalTestSupportTests/Misc.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
112
import SPMBuildCore
213
import _InternalTestSupport
314
import XCTest

0 commit comments

Comments
 (0)