Skip to content

Commit

Permalink
Fix issues building when using Xcode Command Line Tools (no XCTest.)
Browse files Browse the repository at this point in the history
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 apple/swift-package-manager#7426

Resolves rdar://125371899.
  • Loading branch information
grynspan committed Mar 25, 2024
1 parent 0112a46 commit 09eeadf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
15 changes: 1 addition & 14 deletions Sources/Testing/Running/XCTestScaffold.swift
Expand Up @@ -8,7 +8,7 @@
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

#if !SWT_NO_XCTEST_SCAFFOLDING
#if !SWT_NO_XCTEST_SCAFFOLDING && canImport(XCTest)
private import TestingInternals
public import XCTest

Expand All @@ -25,19 +25,6 @@ extension XCTSourceCodeContext {
self.init(callStackAddresses: addresses, location: sourceLocation)
}
}

/// An error that is reported by ``XCTestScaffold`` when a test times out.
///
/// This type is not part of the public interface of the testing library.
struct TimeoutError: Error, CustomStringConvertible {
/// The time limit exceeded by the test that timed out.
var timeLimit: TimeValue

var description: String {
"Timed out after \(timeLimit) seconds."
}
}

extension XCTIssue {
init(_ issue: Issue, processLaunchedByXcode: Bool) {
var error = issue.error
Expand Down
12 changes: 12 additions & 0 deletions Sources/Testing/Traits/TimeLimitTrait.swift
Expand Up @@ -108,6 +108,18 @@ extension Test {

// MARK: -

/// An error that is reported by ``XCTestScaffold`` when a test times out.
///
/// This type is not part of the public interface of the testing library.
struct TimeoutError: Error, CustomStringConvertible {
/// The time limit exceeded by the test that timed out.
var timeLimit: TimeValue

var description: String {
"Timed out after \(timeLimit) seconds."
}
}

#if !SWT_NO_UNSTRUCTURED_TASKS
/// Invoke a function with a timeout.
///
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingMacrosTests/TestSupport/Scaffolding.swift
Expand Up @@ -8,7 +8,7 @@
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING
#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING && canImport(XCTest)
import XCTest
import Testing

Expand Down
1 change: 1 addition & 0 deletions Tests/TestingTests/IssueTests.swift
Expand Up @@ -10,6 +10,7 @@

@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
private import TestingInternals
import Foundation

#if canImport(XCTest)
import XCTest
Expand Down
2 changes: 2 additions & 0 deletions Tests/TestingTests/ObjCInteropTests.swift
Expand Up @@ -8,6 +8,7 @@
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

#if canImport(XCTest)
import XCTest
@testable @_spi(ForToolsIntegrationOnly) import Testing

Expand Down Expand Up @@ -106,3 +107,4 @@ struct ObjCAndXCTestInteropTests {
}
}
}
#endif
2 changes: 2 additions & 0 deletions Tests/TestingTests/RunnerTests.swift
Expand Up @@ -10,6 +10,7 @@

#if canImport(XCTest)
import XCTest
#endif
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing

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

#if canImport(XCTest)
@Suite(.hidden, .disabled())
struct NeverRunTests {
private static var someCondition: Bool {
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/TestSupport/Scaffolding.swift
Expand Up @@ -8,7 +8,7 @@
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
//

#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING
#if !SWT_NO_XCTEST_SCAFFOLDING && !SWIFT_PM_SUPPORTS_SWIFT_TESTING && canImport(XCTest)
import XCTest
import Testing

Expand Down

0 comments on commit 09eeadf

Please sign in to comment.