Skip to content

Fix issues building when using Xcode Command Line Tools (no XCTest.) #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions Sources/Testing/Running/XCTestScaffold.swift
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 0 additions & 2 deletions Tests/TestingTests/Traits/TimeLimitTraitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ struct TimeLimitTraitTests {
}
}

#if !SWT_NO_XCTEST_SCAFFOLDING && SWT_TARGET_OS_APPLE
@Test("TimeoutError.description property")
func timeoutErrorDescription() async throws {
let timeLimit = TimeValue((0, 0))
#expect(String(describing: TimeoutError(timeLimit: timeLimit)).contains("0.000"))
}
#endif

@Test("Issue.Kind.timeLimitExceeded.description property",
arguments: [
Expand Down