File tree Expand file tree Collapse file tree 3 files changed +87
-15
lines changed Expand file tree Collapse file tree 3 files changed +87
-15
lines changed Original file line number Diff line number Diff line change 6
6
//
7
7
8
8
import Testing
9
- @ testable import PropertyBased
9
+ import PropertyBased
10
10
import Gen
11
11
12
12
@Suite struct FixedSeedTests {
13
- private func gatherIssues( block: @Sendable ( ) async -> Void ) async -> [ Issue ] {
14
- let mutex = Mutex ( [ ] as [ Issue ] )
15
-
16
- // No way to stop issues from still being recorded. Ignore those for now.
17
- await withKnownIssue {
18
- await block ( )
19
- } matching: { issue in
20
- mutex. withLock { $0. append ( issue) }
21
- return true
22
- }
23
-
24
- return mutex. withLock { $0 }
25
- }
26
-
27
13
@Test ( . fixedSeed( " qwert " ) )
28
14
func testInvalidSeed( ) async {
29
15
let issues = await gatherIssues {
Original file line number Diff line number Diff line change
1
+ //
2
+ // PropertyCheckTests.swift
3
+ // PropertyBased
4
+ //
5
+ // Created by Lennard Sprong on 06/05/2025.
6
+ //
7
+
8
+ import Testing
9
+ @testable import PropertyBased
10
+
11
+ @Suite struct PropertyCheckTests {
12
+ @Test func testFunctionIsCalledWithInputs( ) async {
13
+ let mutex = Mutex ( ( a: 0 , b: 0 ) )
14
+
15
+ await propertyCheck ( input: . bool) { bool in
16
+ mutex. withLock {
17
+ if bool {
18
+ $0. a += 1
19
+ } else {
20
+ $0. b += 1
21
+ }
22
+ }
23
+ }
24
+
25
+ let counts = mutex. withLock { $0 }
26
+ #expect( counts. a > 0 && counts. b > 0 )
27
+ #expect( counts. a + counts. b == 100 )
28
+ }
29
+
30
+ @Test func testCountParameter( ) async {
31
+ await confirmation ( expectedCount: 12 ) { confirm in
32
+ await propertyCheck ( count: 12 ) {
33
+ confirm ( )
34
+ }
35
+ }
36
+
37
+ await confirmation ( expectedCount: 7 ) { confirm in
38
+ await propertyCheck ( count: 7 ) {
39
+ confirm ( )
40
+ }
41
+ }
42
+ }
43
+
44
+ @Test func testIssuesArePropagated( ) async {
45
+ let issues = await gatherIssues {
46
+ await propertyCheck ( input: . int( in: 0 ... 10 ) ) { a in
47
+ try #require( a > 20 )
48
+ #expect( a > 50 )
49
+ }
50
+ }
51
+
52
+ #expect( issues. contains ( where: {
53
+ $0. description. contains ( " > 20 " )
54
+ } ) )
55
+ #expect( issues. contains ( where: {
56
+ $0. description. contains ( " to reproduce this issue " )
57
+ } ) )
58
+
59
+ #expect( !issues. contains ( where: {
60
+ $0. description. contains ( " > 50 " )
61
+ } ) )
62
+ }
63
+ }
Original file line number Diff line number Diff line change
1
+ //
2
+ // Utils.swift
3
+ // PropertyBased
4
+ //
5
+ // Created by Lennard Sprong on 06/05/2025.
6
+ //
7
+
8
+ import Testing
9
+ @testable import PropertyBased
10
+
11
+ func gatherIssues( block: @Sendable ( ) async -> Void ) async -> [ Issue ] {
12
+ let mutex = Mutex ( [ ] as [ Issue ] )
13
+
14
+ // No way to stop issues from still being recorded. Ignore those for now.
15
+ await withKnownIssue {
16
+ await block ( )
17
+ } matching: { issue in
18
+ mutex. withLock { $0. append ( issue) }
19
+ return true
20
+ }
21
+
22
+ return mutex. withLock { $0 }
23
+ }
You can’t perform that action at this time.
0 commit comments