|
| 1 | +// |
| 2 | +// MaximumAttemptsTraitTest.swift |
| 3 | +// PropertyBased |
| 4 | +// |
| 5 | +// Created by Lennard Sprong on 10/08/2026. |
| 6 | +// |
| 7 | + |
| 8 | +import Testing |
| 9 | + |
| 10 | +@testable import PropertyBased |
| 11 | + |
| 12 | +@Suite struct MaximumAttemptsTraitTest { |
| 13 | + @Test func testRunUsesLimit() { |
| 14 | + let useless = Gen.always(false).filter { $0 } |
| 15 | + |
| 16 | + #expect(throws: GeneratorError.runLimitExceeded(25)) { |
| 17 | + var rng = Xoshiro() |
| 18 | + _ = try useless.run(using: &rng, limit: 25) |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + @Test func testTraitCanModifyCount() async throws { |
| 23 | + let useless = Gen.always(false).filter { $0 } |
| 24 | + |
| 25 | + let trait = MaximumAttemptsTrait.maximumAttempts(20) |
| 26 | + let scope = try #require(trait.scopeProvider(for: Test.current!, testCase: Test.Case.current)) |
| 27 | + |
| 28 | + let issues = await gatherIssues { |
| 29 | + try await scope.provideScope(for: Test.current!, testCase: Test.Case.current) { |
| 30 | + await propertyCheck(input: useless) { _ in |
| 31 | + try #require(Bool(false), "block must not be called") |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + #expect(issues.count == 1) |
| 36 | + #expect( |
| 37 | + issues.contains(where: { |
| 38 | + $0.contains("20 attempts") && !$0.contains("maximumAttempts()") |
| 39 | + })) |
| 40 | + } |
| 41 | + |
| 42 | + @Test func testTraitSuggestion() async throws { |
| 43 | + let useless = Gen.always(false).filter { $0 } |
| 44 | + let issues = await gatherIssues { |
| 45 | + await propertyCheck(input: useless) { _ in |
| 46 | + try #require(Bool(false), "block must not be called") |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + #expect(issues.count == 1) |
| 51 | + #expect( |
| 52 | + issues.contains(where: { |
| 53 | + $0.contains("maximumAttempts()") |
| 54 | + })) |
| 55 | + } |
| 56 | +} |
0 commit comments