From bc2a151366f2cd0e347274544933bc2acb00c9fe Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Wed, 11 Sep 2024 12:06:59 -0700 Subject: [PATCH] Publicize Swift Testing's underlying Test.ID (#131) * Publicize Swift Testing's underlying Test.ID This allows Issue Reporting's provided ID to be compared to the underlying Test.ID value from Swift Testing. * Add Xcode 16 to CI * Update ci.yml * fix * fix --- .github/workflows/ci.yml | 10 +++++++--- Examples/ExamplesTests/SwiftTestingTests.swift | 2 +- Sources/IssueReporting/IsTesting.swift | 6 +++++- Sources/IssueReporting/TestContext.swift | 6 +++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe4a2b1..cd60dd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,8 +20,9 @@ jobs: - debug - release xcode: - - 15.4 - 15.2 + - 15.4 + - 16_beta_6 name: macOS runs-on: macos-14 steps: @@ -47,12 +48,15 @@ jobs: config: - Debug - Release + xcode: + - 15.4 + - 16_beta_6 name: Examples runs-on: macos-14 steps: - uses: actions/checkout@v4 - name: Select Xcode - run: sudo xcode-select -s /Applications/Xcode_15.4.app + run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app - name: Run tests run: make CONFIG=${{ matrix.config }} test-examples @@ -81,7 +85,7 @@ jobs: matrix: toolchain: - wasm-5.9.2-RELEASE - - wasm-5.10.0-RELEASE + - wasm-5.10.0-RELEASE steps: - name: Cache toolchains uses: actions/cache@v3 diff --git a/Examples/ExamplesTests/SwiftTestingTests.swift b/Examples/ExamplesTests/SwiftTestingTests.swift index 827682a..d8f21fd 100644 --- a/Examples/ExamplesTests/SwiftTestingTests.swift +++ b/Examples/ExamplesTests/SwiftTestingTests.swift @@ -7,7 +7,7 @@ struct SwiftTestingTests_Debug { @Test func context() { switch TestContext.current { - case .xcTest: + case .swiftTesting: #expect(Bool(true)) default: Issue.record() diff --git a/Sources/IssueReporting/IsTesting.swift b/Sources/IssueReporting/IsTesting.swift index 756c87e..e709534 100644 --- a/Sources/IssueReporting/IsTesting.swift +++ b/Sources/IssueReporting/IsTesting.swift @@ -30,9 +30,13 @@ if environment.keys.contains("XCTestBundlePath") { return true } if environment.keys.contains("XCTestConfigurationFilePath") { return true } if environment.keys.contains("XCTestSessionIdentifier") { return true } + return arguments.contains { argument in let path = URL(fileURLWithPath: argument) - return path.lastPathComponent == "xctest" || path.pathExtension == "xctest" + return path.lastPathComponent == "swiftpm-testing-helper" + || argument == "--testing-library" + || path.lastPathComponent == "xctest" + || path.pathExtension == "xctest" } } } diff --git a/Sources/IssueReporting/TestContext.swift b/Sources/IssueReporting/TestContext.swift index 15ce8ce..9d8c612 100644 --- a/Sources/IssueReporting/TestContext.swift +++ b/Sources/IssueReporting/TestContext.swift @@ -1,6 +1,6 @@ /// A type representing the context in which a test is being run, _i.e._ either in Swift's native /// Testing framework, or Xcode's XCTest framework. -public enum TestContext: Equatable { +public enum TestContext: Equatable, Sendable { /// The Swift Testing framework. case swiftTesting(Testing?) @@ -37,14 +37,14 @@ public enum TestContext: Equatable { return true } - public struct Testing: Equatable { + public struct Testing: Equatable, Sendable { public let test: Test public struct Test: Equatable, Hashable, Identifiable, Sendable { public let id: ID public struct ID: Equatable, Hashable, @unchecked Sendable { - fileprivate let rawValue: AnyHashable + public let rawValue: AnyHashable } } }