Skip to content

Commit 9703a55

Browse files
authored
Expose isParameterized and isSuite on Test.Snapshot, and Test.Case.Argument.ID.init, as SPI (#164)
Resolves rdar://119614246
1 parent ced504d commit 9703a55

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

Sources/Testing/Parameterization/Test.Case.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ extension Test {
2424
public struct ID: Sendable {
2525
/// The raw bytes of this instance's identifier.
2626
public var bytes: [UInt8]
27+
28+
@_spi(ExperimentalTestRunning)
29+
public init(bytes: [UInt8]) {
30+
self.bytes = bytes
31+
}
2732
}
2833

2934
/// The ID of this parameterized test argument, if any.

Sources/Testing/Test.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,27 @@ extension Test {
244244
testCases = test.testCases?.map(Test.Case.Snapshot.init)
245245
parameters = test.parameters
246246
}
247+
248+
/// Whether or not this test is parameterized.
249+
///
250+
/// ## See Also
251+
///
252+
/// - ``Test/isParameterized``
253+
@_spi(ExperimentalParameterizedTesting)
254+
public var isParameterized: Bool {
255+
guard let parameterCount = parameters?.count else {
256+
return false
257+
}
258+
return parameterCount != 0
259+
}
260+
261+
/// Whether or not this instance is a test suite containing other tests.
262+
///
263+
/// ## See Also
264+
///
265+
/// - ``Test/isSuite``
266+
public var isSuite: Bool {
267+
testCases == nil
268+
}
247269
}
248270
}

Tests/TestingTests/Test.SnapshotTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,42 @@ struct Test_SnapshotTests {
3131
#expect(decoded.parameters == snapshot.parameters)
3232
}
3333
#endif
34+
35+
@Test("isParameterized property")
36+
func isParameterized() async throws {
37+
do {
38+
let test = try #require(Test.current)
39+
let snapshot = Test.Snapshot(snapshotting: test)
40+
#expect(!snapshot.isParameterized)
41+
}
42+
do {
43+
let test = try #require(await testFunction(named: "parameterized(i:)", in: MainActorIsolatedTests.self))
44+
let snapshot = Test.Snapshot(snapshotting: test)
45+
#expect(snapshot.isParameterized)
46+
}
47+
do {
48+
let suite = try #require(await test(for: Self.self))
49+
let snapshot = Test.Snapshot(snapshotting: suite)
50+
#expect(!snapshot.isParameterized)
51+
}
52+
}
53+
54+
@Test("isSuite property")
55+
func isSuite() async throws {
56+
do {
57+
let test = try #require(Test.current)
58+
let snapshot = Test.Snapshot(snapshotting: test)
59+
#expect(!snapshot.isSuite)
60+
}
61+
do {
62+
let test = try #require(await testFunction(named: "parameterized(i:)", in: MainActorIsolatedTests.self))
63+
let snapshot = Test.Snapshot(snapshotting: test)
64+
#expect(!snapshot.isSuite)
65+
}
66+
do {
67+
let suite = try #require(await test(for: Self.self))
68+
let snapshot = Test.Snapshot(snapshotting: suite)
69+
#expect(snapshot.isSuite)
70+
}
71+
}
3472
}

0 commit comments

Comments
 (0)