Skip to content

Commit 09eeadf

Browse files
committed
Fix issues building when using Xcode Command Line Tools (no XCTest.)
This PR removes some stray dependencies on XCTest that prevent building the testing library and its test target when XCTest is not available on Darwin. This can occur if the Xcode Command Line Tools are installed instead of the full IDE. Automated testing for this change is difficult because it relies on a build environment that is not supported in CI (namely the presence of the CL tools but not Xcode nor XCTest.framework.) I have manually tested the change against swift-testing's own test target. For more information about this change, see swiftlang/swift-package-manager#7426 Resolves rdar://125371899.
1 parent 0112a46 commit 09eeadf

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

Sources/Testing/Running/XCTestScaffold.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if !SWT_NO_XCTEST_SCAFFOLDING
11+
#if !SWT_NO_XCTEST_SCAFFOLDING && canImport(XCTest)
1212
private import TestingInternals
1313
public import XCTest
1414

@@ -25,19 +25,6 @@ extension XCTSourceCodeContext {
2525
self.init(callStackAddresses: addresses, location: sourceLocation)
2626
}
2727
}
28-
29-
/// An error that is reported by ``XCTestScaffold`` when a test times out.
30-
///
31-
/// This type is not part of the public interface of the testing library.
32-
struct TimeoutError: Error, CustomStringConvertible {
33-
/// The time limit exceeded by the test that timed out.
34-
var timeLimit: TimeValue
35-
36-
var description: String {
37-
"Timed out after \(timeLimit) seconds."
38-
}
39-
}
40-
4128
extension XCTIssue {
4229
init(_ issue: Issue, processLaunchedByXcode: Bool) {
4330
var error = issue.error

Sources/Testing/Traits/TimeLimitTrait.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ extension Test {
108108

109109
// MARK: -
110110

111+
/// An error that is reported by ``XCTestScaffold`` when a test times out.
112+
///
113+
/// This type is not part of the public interface of the testing library.
114+
struct TimeoutError: Error, CustomStringConvertible {
115+
/// The time limit exceeded by the test that timed out.
116+
var timeLimit: TimeValue
117+
118+
var description: String {
119+
"Timed out after \(timeLimit) seconds."
120+
}
121+
}
122+
111123
#if !SWT_NO_UNSTRUCTURED_TASKS
112124
/// Invoke a function with a timeout.
113125
///

Tests/TestingMacrosTests/TestSupport/Scaffolding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING
11+
#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING && canImport(XCTest)
1212
import XCTest
1313
import Testing
1414

Tests/TestingTests/IssueTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212
private import TestingInternals
13+
import Foundation
1314

1415
#if canImport(XCTest)
1516
import XCTest

Tests/TestingTests/ObjCInteropTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
#if canImport(XCTest)
1112
import XCTest
1213
@testable @_spi(ForToolsIntegrationOnly) import Testing
1314

@@ -106,3 +107,4 @@ struct ObjCAndXCTestInteropTests {
106107
}
107108
}
108109
}
110+
#endif

Tests/TestingTests/RunnerTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#if canImport(XCTest)
1212
import XCTest
13+
#endif
1314
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1415

1516
struct MyError: Error, Equatable {
@@ -35,6 +36,7 @@ private let randomNumber = Int.random(in: 0 ..< .max)
3536
throw MyParameterizedError(index: i)
3637
}
3738

39+
#if canImport(XCTest)
3840
@Suite(.hidden, .disabled())
3941
struct NeverRunTests {
4042
private static var someCondition: Bool {

Tests/TestingTests/TestSupport/Scaffolding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING
11+
#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING && canImport(XCTest)
1212
import XCTest
1313
import Testing
1414

0 commit comments

Comments
 (0)