pbt 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +117 -80
  4. data/lib/pbt/arbitrary/arbitrary.rb +63 -10
  5. data/lib/pbt/arbitrary/arbitrary_methods.rb +51 -24
  6. data/lib/pbt/arbitrary/array_arbitrary.rb +45 -11
  7. data/lib/pbt/arbitrary/choose_arbitrary.rb +27 -0
  8. data/lib/pbt/arbitrary/constant.rb +0 -1
  9. data/lib/pbt/arbitrary/constant_arbitrary.rb +5 -0
  10. data/lib/pbt/arbitrary/constant_from_arbitrary.rb +39 -0
  11. data/lib/pbt/arbitrary/filter_arbitrary.rb +40 -2
  12. data/lib/pbt/arbitrary/fixed_hash_arbitrary.rb +16 -0
  13. data/lib/pbt/arbitrary/float_arbitrary.rb +31 -0
  14. data/lib/pbt/arbitrary/frequency_arbitrary.rb +61 -0
  15. data/lib/pbt/arbitrary/integer_arbitrary.rb +11 -0
  16. data/lib/pbt/arbitrary/map_arbitrary.rb +40 -2
  17. data/lib/pbt/arbitrary/one_of_arbitrary.rb +46 -13
  18. data/lib/pbt/arbitrary/sample.rb +97 -0
  19. data/lib/pbt/arbitrary/tuple_arbitrary.rb +22 -0
  20. data/lib/pbt/check/case.rb +1 -1
  21. data/lib/pbt/check/configuration.rb +5 -3
  22. data/lib/pbt/check/property.rb +23 -4
  23. data/lib/pbt/check/runner_iterator.rb +84 -10
  24. data/lib/pbt/check/runner_methods.rb +53 -19
  25. data/lib/pbt/check/tosser.rb +1 -1
  26. data/lib/pbt/reporter/run_details.rb +2 -2
  27. data/lib/pbt/reporter/run_details_reporter.rb +46 -4
  28. data/lib/pbt/reporter/run_execution.rb +47 -4
  29. data/lib/pbt/stateful/command.rb +215 -0
  30. data/lib/pbt/stateful/errors.rb +58 -0
  31. data/lib/pbt/stateful/property.rb +276 -276
  32. data/lib/pbt/stateful/shrinker.rb +295 -0
  33. data/lib/pbt/stateful/spec.rb +299 -0
  34. data/lib/pbt/stateful/types.rb +308 -0
  35. data/lib/pbt/statistics.rb +28 -0
  36. data/lib/pbt/version.rb +1 -1
  37. data/lib/pbt.rb +62 -26
  38. data/sig/manifest.yaml +2 -0
  39. data/sig/pbt/arbitrary.rbs +139 -0
  40. data/sig/pbt/check.rbs +74 -0
  41. data/sig/pbt/reporter.rbs +44 -0
  42. data/sig/pbt/stateful.rbs +241 -0
  43. data/sig/pbt.rbs +40 -1
  44. metadata +18 -13
  45. data/.rspec +0 -3
  46. data/.standard.yml +0 -3
  47. data/CLAUDE.md +0 -104
  48. data/Rakefile +0 -70
  49. data/benchmark/README.md +0 -103
  50. data/benchmark/example.txt +0 -299
  51. data/benchmark/failure_simple.rb +0 -29
  52. data/benchmark/success_cpu_bound.rb +0 -35
  53. data/benchmark/success_io_bound.rb +0 -28
  54. data/benchmark/success_simple.rb +0 -24
@@ -0,0 +1,44 @@
1
+ module Pbt
2
+ module Reporter
3
+ class RunDetails < Struct[untyped]
4
+ attr_accessor failed: bool
5
+ attr_accessor num_runs: Integer
6
+ attr_accessor num_skips: Integer
7
+ attr_accessor num_shrinks: Integer
8
+ attr_accessor seed: Integer
9
+ attr_accessor counterexample: untyped
10
+ attr_accessor counterexample_path: String?
11
+ attr_accessor error_message: String?
12
+ attr_accessor error_instance: Exception?
13
+ attr_accessor failures: Array[Check::Case]
14
+ attr_accessor verbose: bool
15
+ attr_accessor execution_summary: Array[RunExecution::ExecutionTreeNode]
16
+ attr_accessor run_configuration: Hash[Symbol, untyped]
17
+ end
18
+
19
+ class RunExecution
20
+ class ExecutionTreeNode < Struct[untyped]
21
+ attr_accessor result: :success | :failure
22
+ attr_accessor value: untyped
23
+ attr_accessor children: Array[ExecutionTreeNode]
24
+ end
25
+
26
+ attr_reader num_successes: Integer
27
+ attr_reader num_skips: Integer
28
+
29
+ def initialize: (bool verbose) -> void
30
+ def record_failure: (Check::Case c) -> void
31
+ def record_success: (Check::Case c) -> void
32
+ def record_skip: () -> void
33
+ def record_too_many_skips: (TooManySkipsError error) -> void
34
+ def too_many_skips?: () -> bool
35
+ def success?: () -> bool
36
+ def to_run_details: (Hash[Symbol, untyped] config) -> RunDetails
37
+ end
38
+
39
+ class RunDetailsReporter
40
+ def initialize: (RunDetails run_details) -> void
41
+ def report_run_details: () -> void
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,241 @@
1
+ module Pbt
2
+ module Stateful
3
+ type failure_stage = :sut | :run | :verify | :invariant | :teardown
4
+
5
+ class InvalidSpec < InvalidConfiguration
6
+ end
7
+
8
+ class GenerationError < StandardError
9
+ end
10
+
11
+ class ModelError < StandardError
12
+ end
13
+
14
+ class FailureSignature < Data
15
+ attr_reader stage: failure_stage
16
+ attr_reader target: Symbol | String | nil
17
+ attr_reader exception_class: singleton(Exception)
18
+
19
+ def initialize: (stage: failure_stage, target: Symbol | String | nil, exception_class: singleton(Exception)) -> void
20
+ def with: (?stage: failure_stage, ?target: Symbol | String | nil, ?exception_class: singleton(Exception)) -> FailureSignature
21
+ end
22
+
23
+ class StepFailure < StandardError
24
+ attr_reader step_index: Integer?
25
+ attr_reader step: Step?
26
+ attr_reader stage: failure_stage
27
+ attr_reader target: Symbol | String | nil
28
+ attr_reader signature: FailureSignature
29
+ attr_reader teardown_error: Exception?
30
+
31
+ def initialize: (
32
+ String message,
33
+ step_index: Integer?,
34
+ step: Step?,
35
+ stage: failure_stage,
36
+ target: Symbol | String | nil,
37
+ exception_class: singleton(Exception),
38
+ ?teardown_error: Exception?
39
+ ) -> void
40
+
41
+ def attach_teardown_error: (Exception error) -> self
42
+ def message: () -> String
43
+ end
44
+
45
+ class Ref < Data
46
+ attr_reader step_id: Integer
47
+
48
+ def initialize: (step_id: Integer) -> void
49
+ def with: (?step_id: Integer) -> Ref
50
+ def to_s: () -> String
51
+ alias inspect to_s
52
+ end
53
+
54
+ class Step < Data
55
+ attr_reader id: Integer
56
+ attr_reader command: Symbol
57
+ attr_reader args: untyped
58
+
59
+ def initialize: (id: Integer, command: Symbol, args: untyped) -> void
60
+ def with: (?id: Integer, ?command: Symbol, ?args: untyped) -> Step
61
+ def format: (?assign: bool) -> String
62
+ def to_s: () -> String
63
+ end
64
+
65
+ class Run < Data
66
+ attr_reader initial_state: untyped
67
+ attr_reader steps: Array[Step]
68
+
69
+ def initialize: (initial_state: untyped, steps: Array[Step]) -> void
70
+ def with: (?initial_state: untyped, ?steps: Array[Step]) -> Run
71
+ def size: () -> Integer
72
+ def empty?: () -> bool
73
+ def command_names: () -> Array[Symbol]
74
+ def format: (?failed_step_index: Integer?, ?failed_stage: failure_stage?) -> String
75
+ def to_s: () -> String
76
+ alias inspect to_s
77
+ end
78
+
79
+ class Context < Data
80
+ attr_reader step: Step
81
+ attr_reader before: untyped
82
+ attr_reader after: untyped
83
+ attr_reader args: untyped
84
+ attr_reader result: untyped
85
+ attr_reader sut: untyped
86
+
87
+ def initialize: (
88
+ step: Step,
89
+ before: untyped,
90
+ after: untyped,
91
+ args: untyped,
92
+ result: untyped,
93
+ sut: untyped
94
+ ) -> void
95
+
96
+ def with: (
97
+ ?step: Step,
98
+ ?before: untyped,
99
+ ?after: untyped,
100
+ ?args: untyped,
101
+ ?result: untyped,
102
+ ?sut: untyped
103
+ ) -> Context
104
+ end
105
+
106
+ module Resolver
107
+ def self.arbitrary?: (untyped obj) -> bool
108
+ def self.deep_dup: (untyped obj, ?Hash[untyped, untyped] cache) -> untyped
109
+ def self.resolve: (untyped obj, Hash[Integer, untyped] env, ?detach: bool, ?cache: Hash[untyped, untyped]) -> untyped
110
+ def self.collect_ref_ids: (untyped obj, ?Set[Integer] ids, ?Hash[untyped, bool] visited) -> Set[Integer]
111
+ def self.referenced_step_ids: (Array[Step] steps) -> Set[Integer]
112
+ def self.format_value: (untyped obj, ?Hash[untyped, bool] visited) -> String
113
+ def self.deep_freeze: (untyped obj) -> untyped
114
+ def self.invoke_with_arity: (untyped callable, *untyped args) -> untyped
115
+ end
116
+
117
+ class Command
118
+ attr_reader name: Symbol
119
+ attr_reader weight: Integer
120
+
121
+ def initialize: (
122
+ name: Symbol,
123
+ weight: Integer,
124
+ guard_block: Proc?,
125
+ arguments_source: untyped,
126
+ precondition_block: Proc?,
127
+ next_state_block: Proc?,
128
+ run_block: Proc,
129
+ verify_block: Proc?
130
+ ) -> void
131
+
132
+ def guard?: (untyped state) -> bool
133
+ def arguments_for: (untyped state) -> Arbitrary::_Arbitrary[untyped]
134
+ def precondition?: (untyped state, untyped args) -> bool
135
+ def next_state: (untyped state, untyped args, Ref ref) -> untyped
136
+ def run!: (untyped sut, untyped concrete_args) -> untyped
137
+ def verify!: (Context context) -> void
138
+ end
139
+
140
+ class CommandBuilder
141
+ def initialize: (name: Symbol, weight: Integer) -> void
142
+ def guard: () { (untyped state) -> boolish } -> void
143
+ def arguments: (Arbitrary::_Arbitrary[untyped] arb) -> void
144
+ | (**Arbitrary::_Arbitrary[untyped] kwargs) -> void
145
+ | () { (untyped state) -> Arbitrary::_Arbitrary[untyped] } -> void
146
+ def precondition: () { (untyped state, untyped args) -> boolish } -> void
147
+ def next_state: () { (untyped state, untyped args, Ref ref) -> untyped } -> void
148
+ def run: () { (untyped sut, untyped args) -> untyped } -> void
149
+ def verify: () { (Context ctx) -> untyped } -> void
150
+ def build: () -> Command
151
+ end
152
+
153
+ class Invariant < Data
154
+ attr_reader name: Symbol | String | nil
155
+ attr_reader block: Proc
156
+
157
+ def initialize: (name: Symbol | String | nil, block: Proc) -> void
158
+ def with: (?name: Symbol | String | nil, ?block: Proc) -> Invariant
159
+ end
160
+
161
+ class Spec
162
+ attr_reader commands: Array[Command]
163
+ attr_reader invariants: Array[Invariant]
164
+
165
+ def initialize: (
166
+ initial_state_kind: :constant | :block | :arbitrary,
167
+ initial_state_source: untyped,
168
+ lifecycle: Proc,
169
+ commands: Array[Command],
170
+ invariants: Array[Invariant]
171
+ ) -> void
172
+
173
+ def arbitrary_initial_state?: () -> bool
174
+ def sample_initial_state: (Random rng) -> [untyped, Arbitrary::Sample[untyped]?]
175
+ def command_by_name: (Symbol name) -> Command
176
+ def with_sut: (untyped initial_state) { (untyped sut) -> untyped } -> void
177
+ end
178
+
179
+ class SpecBuilder
180
+ def initialize: () -> void
181
+ def initial_state: (untyped value_or_arb) -> void
182
+ | () { () -> untyped } -> void
183
+ def sut: () { (untyped initial_state) -> untyped } -> void
184
+ def teardown: () { (untyped sut) -> untyped } -> void
185
+ def around: () { (untyped initial_state, ^(untyped) -> void run) -> untyped } -> void
186
+ def command: (Symbol name, ?weight: Integer) { (CommandBuilder) -> untyped } -> void
187
+ def invariant: (?Symbol | String | nil name) { (untyped state, untyped sut) -> untyped } -> void
188
+ def build: () -> Spec
189
+ end
190
+
191
+ class ShrinkSession
192
+ attr_reader attempts: Integer
193
+ attr_reader max_attempts: Integer
194
+
195
+ def initialize: (max_attempts: Integer) -> void
196
+ def exhausted?: () -> bool
197
+ def seen?: (Run run) -> bool
198
+ def mark_seen: (Run run) -> void
199
+ def consume_attempt!: () -> Integer
200
+ end
201
+
202
+ class RunSample < Arbitrary::Sample[Run]
203
+ attr_reader initial_state_sample: Arbitrary::Sample[untyped]?
204
+ attr_reader step_samples: Hash[Integer, Arbitrary::Sample[untyped]]
205
+ attr_reader session: ShrinkSession
206
+
207
+ def initialize: (
208
+ Run run,
209
+ initial_state_sample: Arbitrary::Sample[untyped]?,
210
+ step_samples: Hash[Integer, Arbitrary::Sample[untyped]],
211
+ session: ShrinkSession
212
+ ) -> void
213
+
214
+ def run: () -> Run
215
+ end
216
+
217
+ class Shrinker
218
+ def initialize: (Spec spec) -> void
219
+ def shrink: (RunSample run_sample, failure: Exception?) -> Enumerator[RunSample, untyped]
220
+ def valid_run?: (Run run) -> bool
221
+ end
222
+
223
+ class Property
224
+ attr_reader spec: Spec
225
+ attr_reader max_steps: Integer
226
+ attr_reader min_steps: Integer
227
+ attr_reader max_shrink_attempts: Integer
228
+
229
+ def initialize: (spec: Spec, ?max_steps: Integer, ?min_steps: Integer, ?max_shrink_attempts: Integer) -> void
230
+ def stateful?: () -> true
231
+ def generate: (?Random rng) -> Run
232
+ def generate_for_check: (?Random rng) -> RunSample
233
+ def run: (Run run) -> void
234
+ def replay: (Run run) -> void
235
+ def same_failure?: (Exception initial_err, Exception candidate_err) -> bool
236
+ def shrink_case: (Check::Case test_case) -> Enumerator[RunSample, untyped]
237
+ def shrink: (Run run) -> Enumerator[Run, untyped]
238
+ def run_in_ractor: (untyped run) -> bot
239
+ end
240
+ end
241
+ end
data/sig/pbt.rbs CHANGED
@@ -1,4 +1,43 @@
1
1
  module Pbt
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+
4
+ class PropertyFailure < StandardError
5
+ end
6
+
7
+ class TooManySkipsError < PropertyFailure
8
+ end
9
+
10
+ class PreconditionNotMet < StandardError
11
+ end
12
+
13
+ class InvalidConfiguration < StandardError
14
+ end
15
+
16
+ extend Arbitrary::ArbitraryMethods
17
+ extend Check::RunnerMethods
18
+ extend Check::ConfigurationMethods
19
+
20
+ def self.assume: (untyped condition) -> void
21
+
22
+ def self.property: [T] (Arbitrary::_Arbitrary[T] arb) { (T) -> untyped } -> Check::Property
23
+ | [T1, T2] (Arbitrary::_Arbitrary[T1] arb1, Arbitrary::_Arbitrary[T2] arb2) { (T1, T2) -> untyped } -> Check::Property
24
+ | [T1, T2, T3] (Arbitrary::_Arbitrary[T1] arb1, Arbitrary::_Arbitrary[T2] arb2, Arbitrary::_Arbitrary[T3] arb3) { (T1, T2, T3) -> untyped } -> Check::Property
25
+ | (*Arbitrary::_Arbitrary[untyped] args) { (*untyped) -> untyped } -> Check::Property
26
+ | (**Arbitrary::_Arbitrary[untyped] kwargs) { (**untyped) -> untyped } -> Check::Property
27
+
28
+ def self.stateful: (?max_steps: Integer, ?min_steps: Integer, ?max_shrink_attempts: Integer) { (Stateful::SpecBuilder) -> untyped } -> Stateful::Property
29
+
30
+ def self.statistics: [T] (Arbitrary::_Generatable[T] arbitrary, ?num_runs: Integer, ?seed: Integer) -> Statistics[T]
31
+ | [T, L] (Arbitrary::_Generatable[T] arbitrary, ?num_runs: Integer, ?seed: Integer) { (T) -> L } -> Statistics[L]
32
+
33
+ class Statistics[out L = untyped]
34
+ attr_reader seed: Integer
35
+ attr_reader num_runs: Integer
36
+ attr_reader counts: Hash[L, Integer]
37
+
38
+ def initialize: (Arbitrary::_Generatable[L] arbitrary, num_runs: Integer, seed: Integer) -> void
39
+ | [T] (Arbitrary::_Generatable[T] arbitrary, num_runs: Integer, seed: Integer) { (T) -> L } -> void
40
+
41
+ def percentages: () -> Hash[L, Float]
42
+ end
4
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ohbarye
@@ -15,20 +15,10 @@ executables: []
15
15
  extensions: []
16
16
  extra_rdoc_files: []
17
17
  files:
18
- - ".rspec"
19
- - ".standard.yml"
20
18
  - CHANGELOG.md
21
- - CLAUDE.md
22
19
  - CODE_OF_CONDUCT.md
23
20
  - LICENSE.txt
24
21
  - README.md
25
- - Rakefile
26
- - benchmark/README.md
27
- - benchmark/example.txt
28
- - benchmark/failure_simple.rb
29
- - benchmark/success_cpu_bound.rb
30
- - benchmark/success_io_bound.rb
31
- - benchmark/success_simple.rb
32
22
  - lib/pbt.rb
33
23
  - lib/pbt/arbitrary/arbitrary.rb
34
24
  - lib/pbt/arbitrary/arbitrary_methods.rb
@@ -36,11 +26,15 @@ files:
36
26
  - lib/pbt/arbitrary/choose_arbitrary.rb
37
27
  - lib/pbt/arbitrary/constant.rb
38
28
  - lib/pbt/arbitrary/constant_arbitrary.rb
29
+ - lib/pbt/arbitrary/constant_from_arbitrary.rb
39
30
  - lib/pbt/arbitrary/filter_arbitrary.rb
40
31
  - lib/pbt/arbitrary/fixed_hash_arbitrary.rb
32
+ - lib/pbt/arbitrary/float_arbitrary.rb
33
+ - lib/pbt/arbitrary/frequency_arbitrary.rb
41
34
  - lib/pbt/arbitrary/integer_arbitrary.rb
42
35
  - lib/pbt/arbitrary/map_arbitrary.rb
43
36
  - lib/pbt/arbitrary/one_of_arbitrary.rb
37
+ - lib/pbt/arbitrary/sample.rb
44
38
  - lib/pbt/arbitrary/tuple_arbitrary.rb
45
39
  - lib/pbt/check/case.rb
46
40
  - lib/pbt/check/configuration.rb
@@ -51,9 +45,20 @@ files:
51
45
  - lib/pbt/reporter/run_details.rb
52
46
  - lib/pbt/reporter/run_details_reporter.rb
53
47
  - lib/pbt/reporter/run_execution.rb
48
+ - lib/pbt/stateful/command.rb
49
+ - lib/pbt/stateful/errors.rb
54
50
  - lib/pbt/stateful/property.rb
51
+ - lib/pbt/stateful/shrinker.rb
52
+ - lib/pbt/stateful/spec.rb
53
+ - lib/pbt/stateful/types.rb
54
+ - lib/pbt/statistics.rb
55
55
  - lib/pbt/version.rb
56
+ - sig/manifest.yaml
56
57
  - sig/pbt.rbs
58
+ - sig/pbt/arbitrary.rbs
59
+ - sig/pbt/check.rbs
60
+ - sig/pbt/reporter.rbs
61
+ - sig/pbt/stateful.rbs
57
62
  homepage: https://github.com/ohbarye/pbt
58
63
  licenses:
59
64
  - MIT
@@ -68,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
73
  requirements:
69
74
  - - ">="
70
75
  - !ruby/object:Gem::Version
71
- version: '3.1'
76
+ version: '3.3'
72
77
  required_rubygems_version: !ruby/object:Gem::Requirement
73
78
  requirements:
74
79
  - - ">="
75
80
  - !ruby/object:Gem::Version
76
81
  version: '0'
77
82
  requirements: []
78
- rubygems_version: 3.6.9
83
+ rubygems_version: 4.0.20
79
84
  specification_version: 4
80
85
  summary: Property-Based Testing tool for Ruby, utilizing Ractor for parallelizing
81
86
  test cases.
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.standard.yml DELETED
@@ -1,3 +0,0 @@
1
- # For available configuration options, see:
2
- # https://github.com/standardrb/standard
3
- ruby_version: 3.1
data/CLAUDE.md DELETED
@@ -1,104 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- PBT (Property-Based Testing) is a Ruby gem that provides property-based testing capabilities with experimental features for parallel test execution using Ractor. The gem allows developers to specify properties that code should satisfy and automatically generates test cases to verify these properties.
8
-
9
- ## Development Commands
10
-
11
- ### Setup
12
- ```bash
13
- bundle install
14
- ```
15
-
16
- ### Testing
17
- ```bash
18
- # Run all tests
19
- bundle exec rspec
20
-
21
- # Run a specific test file
22
- bundle exec rspec spec/path/to/spec.rb
23
-
24
- # Run tests matching a pattern
25
- bundle exec rspec -e "pattern"
26
- ```
27
-
28
- ### Linting
29
- ```bash
30
- # Check code style
31
- bundle exec rake standard
32
-
33
- # Auto-fix code style issues
34
- bundle exec rake standard:fix
35
- ```
36
-
37
- ### Combined Testing and Linting
38
- ```bash
39
- # Default rake task runs both tests and linting
40
- bundle exec rake
41
- ```
42
-
43
- ### Benchmarking
44
- ```bash
45
- # Run all benchmarks
46
- bundle exec rake benchmark:all
47
-
48
- # Run specific benchmark categories
49
- bundle exec rake benchmark:success:simple
50
- bundle exec rake benchmark:success:cpu_bound
51
- bundle exec rake benchmark:success:io_bound
52
- bundle exec rake benchmark:failure:simple
53
- ```
54
-
55
- ### Building and Releasing
56
- ```bash
57
- # Build the gem
58
- bundle exec rake build
59
-
60
- # Install locally
61
- bundle exec rake install
62
-
63
- # Release to RubyGems (maintainers only)
64
- bundle exec rake release
65
- ```
66
-
67
- ## Architecture
68
-
69
- ### Core Components
70
-
71
- 1. **Arbitrary** (`lib/pbt/arbitrary/`)
72
- - Base classes and modules for generating random values
73
- - Implements various arbitraries: integer, array, tuple, hash, etc.
74
- - Each arbitrary knows how to generate values and shrink them
75
-
76
- 2. **Check** (`lib/pbt/check/`)
77
- - `Property`: Defines properties to test
78
- - `Runner`: Executes properties with different concurrency methods
79
- - `Configuration`: Global and per-run configuration
80
- - `Tosser`: Manages the generation and shrinking process
81
-
82
- 3. **Reporter** (`lib/pbt/reporter/`)
83
- - Handles test result reporting
84
- - Provides verbose mode for detailed output
85
-
86
- ### Key Design Patterns
87
-
88
- - **Shrinking**: When a test fails, PBT attempts to find the minimal failing case by systematically reducing the input
89
- - **Concurrency**: Supports both serial (`:none`) and parallel (`:ractor`) execution
90
- - **Configuration**: Uses both global configuration and per-assertion overrides
91
-
92
- ### Testing Approach
93
-
94
- The codebase uses RSpec for testing and follows these patterns:
95
- - Unit tests for each arbitrary type in `spec/pbt/arbitrary/`
96
- - Integration tests in `spec/e2e/`
97
- - Property-based tests are used to test the library itself
98
-
99
- ### Important Notes
100
-
101
- - Ruby 3.1+ is required due to Ractor usage
102
- - When using `:ractor` worker, be aware of Ractor limitations (no shared state, limited object sharing)
103
- - The gem uses Standard Ruby for code style (configured in `.standard.yml`)
104
- - CI runs tests against Ruby 3.1, 3.2, 3.3, and 3.4
data/Rakefile DELETED
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "standard/rake"
9
-
10
- task default: %i[spec standard]
11
-
12
- namespace :benchmark do
13
- task all: ["success:simple", "success:cpu_bound", "success:io_bound", "failure:simple"]
14
-
15
- namespace :success do
16
- task :simple do
17
- puts "### Benchmark success:simple"
18
- puts
19
- puts "This runs a script that does not do any IO or CPU bound work."
20
- puts
21
- ENV["RUBYOPT"] = "-W:no-experimental"
22
- ENV["RUBY_MN_THREADS"] = "1"
23
- puts "```"
24
- sh "ruby", "benchmark/success_simple.rb"
25
- puts "```"
26
- puts
27
- end
28
-
29
- task :cpu_bound do
30
- puts "### Benchmark success:cpu_bound"
31
- puts
32
- puts "This runs a script that does CPU bound work."
33
- puts
34
- ENV["RUBYOPT"] = "-W:no-experimental"
35
- ENV["RUBY_MN_THREADS"] = "1"
36
- puts "```"
37
- sh "ruby", "benchmark/success_cpu_bound.rb"
38
- puts "```"
39
- puts
40
- end
41
-
42
- task :io_bound do
43
- puts "### Benchmark success:io_bound"
44
- puts
45
- puts "This runs a script that does IO bound work."
46
- puts
47
- ENV["RUBYOPT"] = "-W:no-experimental"
48
- ENV["RUBY_MN_THREADS"] = "1"
49
- puts "```"
50
- sh "ruby", "benchmark/success_io_bound.rb"
51
- puts "```"
52
- puts
53
- end
54
- end
55
-
56
- namespace :failure do
57
- task :simple do
58
- puts "### Benchmark failure:simple"
59
- puts
60
- puts "This runs a script that fails and shrink happens."
61
- puts
62
- ENV["RUBYOPT"] = "-W:no-experimental"
63
- ENV["RUBY_MN_THREADS"] = "1"
64
- puts "```"
65
- sh "ruby", "benchmark/failure_simple.rb"
66
- puts "```"
67
- puts
68
- end
69
- end
70
- end