Skip to content

Commit d1b834b

Browse files
committed
Make TestContext Equatable.
1 parent b41188c commit d1b834b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Sources/IssueReporting/TestContext.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// A type representing the context in which a test is being run, _i.e._ either in Swift's native
22
/// Testing framework, or Xcode's XCTest framework.
3-
public enum TestContext {
3+
public enum TestContext: Equatable {
44
/// The Swift Testing framework.
55
case swiftTesting(Testing)
66

@@ -12,8 +12,10 @@ public enum TestContext {
1212
/// How the test context is detected depends on the framework:
1313
///
1414
/// * If Swift Testing is running, _and_ this is called from the current test's task, this will
15-
/// return ``swiftTesting``. In this way, `TestContext.current == .swiftTesting` is equivalent
16-
/// to checking `Test.current != nil`, but safe to do from library and application code.
15+
/// return ``swiftTesting`` with an associated value of the current test. You can invoke
16+
/// ``isSwiftTesting`` to detect if the test is currently in the Swift Testing framework,
17+
/// which is equivalent to checking `Test.current != nil`, but safe to do from library and
18+
/// application code.
1719
///
1820
/// * If XCTest is running, _and_ this is called during the execution of a test _regardless_ of
1921
/// task, this will return ``xcTest``.
@@ -27,8 +29,15 @@ public enum TestContext {
2729
return .xcTest
2830
}
2931
}
32+
33+
/// Determines if the test context is Swift's native Testing framework.
34+
public var isSwiftTesting: Bool {
35+
guard case .swiftTesting = self
36+
else { return false }
37+
return true
38+
}
3039

31-
public struct Testing {
40+
public struct Testing: Equatable {
3241
public let test: Test
3342

3443
public struct Test: Hashable, Identifiable, Sendable {

0 commit comments

Comments
 (0)