1
1
/// A type representing the context in which a test is being run, _i.e._ either in Swift's native
2
2
/// Testing framework, or Xcode's XCTest framework.
3
- public enum TestContext {
3
+ public enum TestContext : Equatable {
4
4
/// The Swift Testing framework.
5
5
case swiftTesting( Testing )
6
6
@@ -12,8 +12,10 @@ public enum TestContext {
12
12
/// How the test context is detected depends on the framework:
13
13
///
14
14
/// * 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.
17
19
///
18
20
/// * If XCTest is running, _and_ this is called during the execution of a test _regardless_ of
19
21
/// task, this will return ``xcTest``.
@@ -27,8 +29,15 @@ public enum TestContext {
27
29
return . xcTest
28
30
}
29
31
}
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
+ }
30
39
31
- public struct Testing {
40
+ public struct Testing : Equatable {
32
41
public let test : Test
33
42
34
43
public struct Test : Hashable , Identifiable , Sendable {
0 commit comments