pbt 0.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +38 -78
- data/lib/pbt/check/runner_methods.rb +6 -2
- data/lib/pbt/reporter/run_details_reporter.rb +33 -4
- data/lib/pbt/stateful/command.rb +215 -0
- data/lib/pbt/stateful/errors.rb +58 -0
- data/lib/pbt/stateful/property.rb +276 -280
- data/lib/pbt/stateful/shrinker.rb +295 -0
- data/lib/pbt/stateful/spec.rb +299 -0
- data/lib/pbt/stateful/types.rb +308 -0
- data/lib/pbt/version.rb +1 -1
- data/lib/pbt.rb +19 -19
- data/sig/manifest.yaml +2 -0
- data/sig/pbt/arbitrary.rbs +139 -0
- data/sig/pbt/check.rbs +74 -0
- data/sig/pbt/reporter.rbs +44 -0
- data/sig/pbt/stateful.rbs +241 -0
- data/sig/pbt.rbs +40 -1
- metadata +11 -19
- data/.rspec +0 -3
- data/.standard.yml +0 -3
- data/CLAUDE.md +0 -104
- data/Rakefile +0 -70
- data/benchmark/FIBER.md +0 -97
- data/benchmark/README.md +0 -103
- data/benchmark/example.txt +0 -299
- data/benchmark/failure_simple.rb +0 -29
- data/benchmark/fiber_experiment.rb +0 -39
- data/benchmark/fiber_scheduler/Gemfile +0 -7
- data/benchmark/fiber_scheduler/experiment.rb +0 -131
- data/benchmark/fiber_scheduler/spec/experiment_spec.rb +0 -38
- data/benchmark/success_cpu_bound.rb +0 -35
- data/benchmark/success_io_bound.rb +0 -28
- data/benchmark/success_simple.rb +0 -24
- data/docs/plans/fiber-experiment.md +0 -12
- data/docs/plans/generator-statistics.md +0 -16
- data/docs/plans/stateful-pbt-redesign.md +0 -415
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pbt
|
|
4
|
+
module Stateful
|
|
5
|
+
# Opaque symbolic token referencing the return value of an earlier step with `id == step_id`.
|
|
6
|
+
Ref = Data.define(:step_id) do
|
|
7
|
+
def to_s
|
|
8
|
+
"v#{step_id}"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
alias_method :inspect, :to_s
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Immutable record of a single generated command step.
|
|
15
|
+
Step = Data.define(:id, :command, :args) do
|
|
16
|
+
def format(assign: false)
|
|
17
|
+
call = args.nil? ? command.to_s : "#{command}(#{Resolver.format_value(args)})"
|
|
18
|
+
assign ? "v#{id} = #{call}" : call
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_s
|
|
22
|
+
format
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Pure, immutable representation of a generated stateful test run.
|
|
27
|
+
Run = Data.define(:initial_state, :steps) do
|
|
28
|
+
def initialize(initial_state:, steps:)
|
|
29
|
+
super(initial_state: initial_state, steps: steps.dup.freeze)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def size
|
|
33
|
+
steps.size
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def empty?
|
|
37
|
+
steps.empty?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def command_names
|
|
41
|
+
steps.map(&:command)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def format(failed_step_index: nil, failed_stage: nil)
|
|
45
|
+
referenced_ids = Resolver.referenced_step_ids(steps)
|
|
46
|
+
lines = ["initial_state: #{Resolver.format_value(initial_state)}"]
|
|
47
|
+
if steps.empty?
|
|
48
|
+
lines << "(no steps)"
|
|
49
|
+
else
|
|
50
|
+
steps.each_with_index do |step, idx|
|
|
51
|
+
line = "#{idx + 1}. #{step.format(assign: referenced_ids.include?(step.id))}"
|
|
52
|
+
if failed_step_index == idx && failed_stage
|
|
53
|
+
line = "#{line} # <- failed (#{failed_stage})"
|
|
54
|
+
end
|
|
55
|
+
lines << line
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
lines.join("\n")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_s
|
|
62
|
+
format
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
alias_method :inspect, :to_s
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Concrete execution context passed to `c.verify`.
|
|
69
|
+
Context = Data.define(:step, :before, :after, :args, :result, :sut)
|
|
70
|
+
|
|
71
|
+
# Helpers for resolving symbolic Refs, traversing containers, and deep-freezing model states.
|
|
72
|
+
module Resolver
|
|
73
|
+
module_function
|
|
74
|
+
|
|
75
|
+
# Return whether `obj` is a Pbt arbitrary (explicitly avoiding false positives like `Array#sample`).
|
|
76
|
+
#
|
|
77
|
+
# @param obj [Object]
|
|
78
|
+
# @return [Boolean]
|
|
79
|
+
def arbitrary?(obj)
|
|
80
|
+
obj.is_a?(Pbt::Arbitrary::Arbitrary) || (obj.respond_to?(:generate) && obj.respond_to?(:shrink))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Deep-duplicate standard value containers and mutable Strings while preserving cycles and opaque objects.
|
|
84
|
+
#
|
|
85
|
+
# @param obj [Object]
|
|
86
|
+
# @param cache [Hash]
|
|
87
|
+
# @return [Object]
|
|
88
|
+
def deep_dup(obj, cache = {}.compare_by_identity)
|
|
89
|
+
return cache[obj] if cache.key?(obj)
|
|
90
|
+
|
|
91
|
+
case obj
|
|
92
|
+
when String
|
|
93
|
+
obj.dup
|
|
94
|
+
when Array
|
|
95
|
+
res = []
|
|
96
|
+
cache[obj] = res
|
|
97
|
+
obj.each { |elem| res << deep_dup(elem, cache) }
|
|
98
|
+
res
|
|
99
|
+
when Hash
|
|
100
|
+
res = {}
|
|
101
|
+
cache[obj] = res
|
|
102
|
+
obj.each { |k, v| res[deep_dup(k, cache)] = deep_dup(v, cache) }
|
|
103
|
+
res
|
|
104
|
+
when Set
|
|
105
|
+
res = Set.new
|
|
106
|
+
cache[obj] = res
|
|
107
|
+
obj.each { |elem| res << deep_dup(elem, cache) }
|
|
108
|
+
res
|
|
109
|
+
when Struct
|
|
110
|
+
res = obj.dup
|
|
111
|
+
cache[obj] = res
|
|
112
|
+
obj.members.each { |member| res[member] = deep_dup(obj[member], cache) }
|
|
113
|
+
res
|
|
114
|
+
when Data
|
|
115
|
+
members = obj.to_h
|
|
116
|
+
members.empty? ? obj : obj.with(**members.transform_values { |v| deep_dup(v, cache) })
|
|
117
|
+
else
|
|
118
|
+
obj
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Resolve symbolic `Ref` tokens into concrete SUT return values inside standard value containers.
|
|
123
|
+
# When `detach: true`, mutable Strings and frozen Structs in symbolic values are duplicated so SUT
|
|
124
|
+
# mutations never corrupt immutable `Run`/`Step` values or trigger `FrozenError`, while concrete
|
|
125
|
+
# `Ref` targets from `env` retain their exact object identity.
|
|
126
|
+
#
|
|
127
|
+
# @param obj [Object]
|
|
128
|
+
# @param env [Hash{Integer => Object}]
|
|
129
|
+
# @param detach [Boolean]
|
|
130
|
+
# @param cache [Hash]
|
|
131
|
+
# @return [Object]
|
|
132
|
+
def resolve(obj, env, detach: false, cache: {}.compare_by_identity)
|
|
133
|
+
return cache[obj] if cache.key?(obj)
|
|
134
|
+
|
|
135
|
+
case obj
|
|
136
|
+
when Ref
|
|
137
|
+
env.fetch(obj.step_id)
|
|
138
|
+
when String
|
|
139
|
+
detach ? obj.dup : obj
|
|
140
|
+
when Array
|
|
141
|
+
res = []
|
|
142
|
+
cache[obj] = res
|
|
143
|
+
obj.each { |elem| res << resolve(elem, env, detach: detach, cache: cache) }
|
|
144
|
+
res
|
|
145
|
+
when Hash
|
|
146
|
+
res = {}
|
|
147
|
+
cache[obj] = res
|
|
148
|
+
obj.each do |k, v|
|
|
149
|
+
res[resolve(k, env, detach: detach, cache: cache)] = resolve(v, env, detach: detach, cache: cache)
|
|
150
|
+
end
|
|
151
|
+
res
|
|
152
|
+
when Set
|
|
153
|
+
res = Set.new
|
|
154
|
+
cache[obj] = res
|
|
155
|
+
obj.each { |elem| res << resolve(elem, env, detach: detach, cache: cache) }
|
|
156
|
+
res
|
|
157
|
+
when Struct
|
|
158
|
+
copy = obj.dup
|
|
159
|
+
cache[obj] = copy
|
|
160
|
+
obj.members.each { |member| copy[member] = resolve(obj[member], env, detach: detach, cache: cache) }
|
|
161
|
+
(!detach && obj.frozen?) ? copy.freeze : copy
|
|
162
|
+
when Data
|
|
163
|
+
members = obj.to_h
|
|
164
|
+
members.empty? ? obj : obj.with(**members.transform_values { |v| resolve(v, env, detach: detach, cache: cache) })
|
|
165
|
+
else
|
|
166
|
+
obj
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Collect all `Ref` step IDs reachable inside standard value containers.
|
|
171
|
+
#
|
|
172
|
+
# @param obj [Object]
|
|
173
|
+
# @param ids [Set<Integer>]
|
|
174
|
+
# @param visited [Hash]
|
|
175
|
+
# @return [Set<Integer>]
|
|
176
|
+
def collect_ref_ids(obj, ids = Set.new, visited = {}.compare_by_identity)
|
|
177
|
+
return ids if visited.key?(obj)
|
|
178
|
+
|
|
179
|
+
case obj
|
|
180
|
+
when Ref
|
|
181
|
+
ids << obj.step_id
|
|
182
|
+
when Array
|
|
183
|
+
visited[obj] = true
|
|
184
|
+
obj.each { |elem| collect_ref_ids(elem, ids, visited) }
|
|
185
|
+
when Hash
|
|
186
|
+
visited[obj] = true
|
|
187
|
+
obj.each do |k, v|
|
|
188
|
+
collect_ref_ids(k, ids, visited)
|
|
189
|
+
collect_ref_ids(v, ids, visited)
|
|
190
|
+
end
|
|
191
|
+
when Set
|
|
192
|
+
visited[obj] = true
|
|
193
|
+
obj.each { |elem| collect_ref_ids(elem, ids, visited) }
|
|
194
|
+
when Struct
|
|
195
|
+
visited[obj] = true
|
|
196
|
+
obj.members.each { |member| collect_ref_ids(obj[member], ids, visited) }
|
|
197
|
+
when Data
|
|
198
|
+
visited[obj] = true
|
|
199
|
+
obj.to_h.each_value { |v| collect_ref_ids(v, ids, visited) }
|
|
200
|
+
end
|
|
201
|
+
ids
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Collect all `Ref` step IDs referenced across a step array's arguments.
|
|
205
|
+
#
|
|
206
|
+
# @param steps [Array<Step>]
|
|
207
|
+
# @return [Set<Integer>]
|
|
208
|
+
def referenced_step_ids(steps)
|
|
209
|
+
ids = Set.new
|
|
210
|
+
steps.each { |step| collect_ref_ids(step.args, ids) }
|
|
211
|
+
ids
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Format a value for counterexample traces, rendering `Ref` as `v<id>`.
|
|
215
|
+
#
|
|
216
|
+
# @param obj [Object]
|
|
217
|
+
# @param visited [Hash]
|
|
218
|
+
# @return [String]
|
|
219
|
+
def format_value(obj, visited = {}.compare_by_identity)
|
|
220
|
+
case obj
|
|
221
|
+
when Ref
|
|
222
|
+
obj.to_s
|
|
223
|
+
when Array
|
|
224
|
+
return "[...]" if visited.key?(obj)
|
|
225
|
+
|
|
226
|
+
visited[obj] = true
|
|
227
|
+
begin
|
|
228
|
+
"[#{obj.map { |e| format_value(e, visited) }.join(", ")}]"
|
|
229
|
+
ensure
|
|
230
|
+
visited.delete(obj)
|
|
231
|
+
end
|
|
232
|
+
when Hash
|
|
233
|
+
return "{...}" if visited.key?(obj)
|
|
234
|
+
|
|
235
|
+
visited[obj] = true
|
|
236
|
+
begin
|
|
237
|
+
pairs = obj.map do |k, v|
|
|
238
|
+
key_str = k.is_a?(Symbol) ? "#{k}:" : "#{format_value(k, visited)} =>"
|
|
239
|
+
"#{key_str} #{format_value(v, visited)}"
|
|
240
|
+
end
|
|
241
|
+
"{#{pairs.join(", ")}}"
|
|
242
|
+
ensure
|
|
243
|
+
visited.delete(obj)
|
|
244
|
+
end
|
|
245
|
+
when Set
|
|
246
|
+
return "Set[...]" if visited.key?(obj)
|
|
247
|
+
|
|
248
|
+
visited[obj] = true
|
|
249
|
+
begin
|
|
250
|
+
"Set[#{obj.map { |e| format_value(e, visited) }.join(", ")}]"
|
|
251
|
+
ensure
|
|
252
|
+
visited.delete(obj)
|
|
253
|
+
end
|
|
254
|
+
else
|
|
255
|
+
obj.inspect
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Deep-freeze model state to detect accidental mutation immediately.
|
|
260
|
+
#
|
|
261
|
+
# @param obj [Object]
|
|
262
|
+
# @return [Object]
|
|
263
|
+
def deep_freeze(obj)
|
|
264
|
+
Ractor.make_shareable(obj)
|
|
265
|
+
rescue Ractor::Error
|
|
266
|
+
fallback_freeze(obj, {}.compare_by_identity)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# Invoke a Proc/lambda with only as many positional arguments as it accepts.
|
|
270
|
+
#
|
|
271
|
+
# @param callable [#call, #parameters]
|
|
272
|
+
# @param args [Array<Object>]
|
|
273
|
+
# @return [Object]
|
|
274
|
+
def invoke_with_arity(callable, *args)
|
|
275
|
+
params = callable.respond_to?(:parameters) ? callable.parameters : nil
|
|
276
|
+
return callable.call(*args) unless params
|
|
277
|
+
|
|
278
|
+
return callable.call(*args) if params.any? { |type, _| type == :rest }
|
|
279
|
+
|
|
280
|
+
max_positional = params.count { |type, _| type == :req || type == :opt }
|
|
281
|
+
callable.call(*args.first(max_positional))
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def fallback_freeze(obj, visited)
|
|
285
|
+
return obj if visited.key?(obj)
|
|
286
|
+
|
|
287
|
+
visited[obj] = true
|
|
288
|
+
case obj
|
|
289
|
+
when Array
|
|
290
|
+
obj.each { |elem| fallback_freeze(elem, visited) }
|
|
291
|
+
when Hash
|
|
292
|
+
obj.each do |k, v|
|
|
293
|
+
fallback_freeze(k, visited)
|
|
294
|
+
fallback_freeze(v, visited)
|
|
295
|
+
end
|
|
296
|
+
when Set
|
|
297
|
+
obj.each { |elem| fallback_freeze(elem, visited) }
|
|
298
|
+
when Struct
|
|
299
|
+
obj.members.each { |member| fallback_freeze(obj[member], visited) }
|
|
300
|
+
when Data
|
|
301
|
+
obj.to_h.each_value { |v| fallback_freeze(v, visited) }
|
|
302
|
+
end
|
|
303
|
+
obj.freeze
|
|
304
|
+
end
|
|
305
|
+
private_class_method :fallback_freeze
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
end
|
data/lib/pbt/version.rb
CHANGED
data/lib/pbt.rb
CHANGED
|
@@ -74,27 +74,27 @@ module Pbt
|
|
|
74
74
|
)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
# Create a stateful property-based test
|
|
78
|
-
# The returned
|
|
77
|
+
# Create a stateful property-based test using a yield-based model builder DSL.
|
|
78
|
+
# The returned `Pbt::Stateful::Property` is compatible with `Pbt.assert`, `Pbt.check`,
|
|
79
|
+
# `Pbt.statistics`, and `property.replay(run)`.
|
|
79
80
|
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
# Each command object is expected to provide:
|
|
85
|
-
# - `name`
|
|
86
|
-
# - `arguments(state)` -> an arbitrary
|
|
87
|
-
# - `applicable?(state, args)` -> bool
|
|
88
|
-
# - `next_state(state, args)`
|
|
89
|
-
# - `run!(sut, args)` -> result
|
|
90
|
-
# - `verify!(before_state:, after_state:, args:, result:, sut:)`
|
|
91
|
-
#
|
|
92
|
-
# @param model [Object]
|
|
93
|
-
# @param sut [Proc] Factory proc that returns a fresh SUT per run.
|
|
94
|
-
# @param max_steps [Integer]
|
|
81
|
+
# @param max_steps [Integer] Maximum number of commands per generated run (default: 20).
|
|
82
|
+
# @param min_steps [Integer] Minimum number of commands per generated run (default: 1).
|
|
83
|
+
# @param max_shrink_attempts [Integer] Total shrink attempt budget per failure (default: 1000).
|
|
84
|
+
# @yieldparam m [Pbt::Stateful::SpecBuilder] Model builder for `initial_state`, `sut`/`teardown`/`around`, `command`, and `invariant`.
|
|
95
85
|
# @return [Pbt::Stateful::Property]
|
|
96
|
-
def self.stateful(
|
|
97
|
-
Stateful::
|
|
86
|
+
def self.stateful(max_steps: 20, min_steps: 1, max_shrink_attempts: 1_000)
|
|
87
|
+
raise Stateful::InvalidSpec, "Pbt.stateful requires a block" unless block_given?
|
|
88
|
+
|
|
89
|
+
builder = Stateful::SpecBuilder.new
|
|
90
|
+
yield(builder)
|
|
91
|
+
spec = builder.build
|
|
92
|
+
Stateful::Property.new(
|
|
93
|
+
spec: spec,
|
|
94
|
+
max_steps: max_steps,
|
|
95
|
+
min_steps: min_steps,
|
|
96
|
+
max_shrink_attempts: max_shrink_attempts
|
|
97
|
+
)
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
# Inspect an independent sample of generated values, optionally grouped by a classifier.
|
data/sig/manifest.yaml
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
module Pbt
|
|
2
|
+
module Arbitrary
|
|
3
|
+
class EmptyDomainError < ArgumentError
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class FilterExhaustedError < StandardError
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
interface _Callable
|
|
10
|
+
def call: (*untyped, **untyped) -> untyped
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
interface _Generatable[out T]
|
|
14
|
+
def generate: (?Random rng) -> T
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
interface _Arbitrary[out T]
|
|
18
|
+
def generate: (?Random rng) -> T
|
|
19
|
+
def shrink: (untyped current) -> Enumerator[T, untyped]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Sample[out T]
|
|
23
|
+
attr_reader value: T
|
|
24
|
+
|
|
25
|
+
def initialize: (T value) { () -> Enumerable[Sample[T]] } -> void
|
|
26
|
+
def shrink: () -> Enumerator[Sample[T], untyped]
|
|
27
|
+
def map: [U] () { (T) -> U } -> Sample[U]
|
|
28
|
+
def filter: () { (T) -> boolish } -> Sample[T]
|
|
29
|
+
|
|
30
|
+
def self.capture: [T] (_Arbitrary[T] arbitrary, Random rng) -> Sample[T]
|
|
31
|
+
def self.from_value: [T] (_Arbitrary[T] arbitrary, T value) -> Sample[T]
|
|
32
|
+
def self.contextual?: (untyped arbitrary) -> bool
|
|
33
|
+
def self.tuple: (Array[Sample[untyped]] samples) -> Sample[Array[untyped]]
|
|
34
|
+
def self.array: [T] (Array[Sample[T]] samples, _Arbitrary[Integer] length_arbitrary, Integer min_length) -> Sample[Array[T]]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Arbitrary[out T = untyped]
|
|
38
|
+
def self.cover_result: (untyped arbitrary, untyped value) -> bool?
|
|
39
|
+
|
|
40
|
+
def generate: (?Random rng) -> T
|
|
41
|
+
def shrink: (untyped current) -> Enumerator[T, untyped]
|
|
42
|
+
def cover?: (untyped value) -> bool?
|
|
43
|
+
def sample: (?Random rng) -> Sample[T]
|
|
44
|
+
def contextual?: () -> bool
|
|
45
|
+
def map: [U] () { (T) -> U } -> MapArbitrary[U]
|
|
46
|
+
| [U] (^(T) -> U mapper, ?(^(untyped) -> untyped | _Callable)? unmapper) -> MapArbitrary[U]
|
|
47
|
+
| (_Callable mapper, ?(^(untyped) -> untyped | _Callable)? unmapper) -> MapArbitrary[untyped]
|
|
48
|
+
def filter: (?max_attempts: Integer) { (T) -> boolish } -> FilterArbitrary[T]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class IntegerArbitrary < Arbitrary[Integer]
|
|
52
|
+
def initialize: (Integer min, Integer max) -> void
|
|
53
|
+
def shrink: (Integer current, ?target: Integer?) -> Enumerator[Integer, untyped]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class ChooseArbitrary < Arbitrary[Integer | Float]
|
|
57
|
+
def initialize: (Range[Integer] | Range[Float] range) -> void
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class ConstantArbitrary[out T = untyped] < Arbitrary[T]
|
|
61
|
+
def initialize: (T val) -> void
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class ConstantFromArbitrary[out T = untyped] < Arbitrary[T]
|
|
65
|
+
def initialize: (Array[T] choices) -> void
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class ArrayArbitrary[out T = untyped] < Arbitrary[Array[T]]
|
|
69
|
+
def initialize: (_Arbitrary[T] value_arb, ?Integer min_length, ?Integer max_length) -> void
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
class TupleArbitrary < Arbitrary[Array[untyped]]
|
|
73
|
+
def initialize: (*_Arbitrary[untyped] arbs) -> void
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class FixedHashArbitrary < Arbitrary[Hash[untyped, untyped]]
|
|
77
|
+
def initialize: (Hash[untyped, _Arbitrary[untyped]] hash) -> void
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class OneOfArbitrary[out T = untyped] < Arbitrary[T]
|
|
81
|
+
def initialize: (Array[_Arbitrary[T]] arbitraries) -> void
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
class FrequencyArbitrary[out T = untyped] < Arbitrary[T]
|
|
85
|
+
def initialize: (Array[[Integer, _Arbitrary[T]]] choices) -> void
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
class MapArbitrary[out T = untyped] < Arbitrary[T]
|
|
89
|
+
def initialize: (_Arbitrary[untyped] arb, ^(untyped) -> untyped | _Callable mapper, ?(^(untyped) -> untyped | _Callable)? unmapper, ?bijective: bool) -> void
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class FloatArbitrary < MapArbitrary[Float]
|
|
93
|
+
def initialize: () -> void
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class FilterArbitrary[out T = untyped] < Arbitrary[T]
|
|
97
|
+
DEFAULT_MAX_ATTEMPTS: Integer
|
|
98
|
+
|
|
99
|
+
def initialize: (_Arbitrary[T] arb, ?max_attempts: Integer) { (T) -> boolish } -> void
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
module ArbitraryMethods
|
|
103
|
+
def integer: (?min: Integer, ?max: Integer) -> IntegerArbitrary
|
|
104
|
+
def nat: (?max: Integer) -> IntegerArbitrary
|
|
105
|
+
def array: [T] (_Arbitrary[T] arb, ?min: Integer, ?max: Integer, ?empty: bool) -> ArrayArbitrary[T]
|
|
106
|
+
def tuple: (*_Arbitrary[untyped] arbs) -> TupleArbitrary
|
|
107
|
+
def fixed_hash: (Hash[untyped, _Arbitrary[untyped]] hash) -> FixedHashArbitrary
|
|
108
|
+
def choose: (Range[Integer] | Range[Float] range) -> ChooseArbitrary
|
|
109
|
+
def constant_from: [T] (*T choices) -> ConstantFromArbitrary[T]
|
|
110
|
+
def one_of: [T] (*_Arbitrary[T] arbitraries) -> OneOfArbitrary[T]
|
|
111
|
+
def frequency: [T] (*[Integer, _Arbitrary[T]] choices) -> FrequencyArbitrary[T]
|
|
112
|
+
def hexa: () -> ConstantFromArbitrary[String]
|
|
113
|
+
def hexa_string: (?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[String]
|
|
114
|
+
def char: () -> MapArbitrary[String]
|
|
115
|
+
def alphanumeric_char: () -> ConstantFromArbitrary[String]
|
|
116
|
+
def alphanumeric_string: (?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[String]
|
|
117
|
+
def ascii_char: () -> ConstantFromArbitrary[String]
|
|
118
|
+
def ascii_string: (?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[String]
|
|
119
|
+
def printable_ascii_char: () -> ConstantFromArbitrary[String]
|
|
120
|
+
def printable_ascii_string: (?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[String]
|
|
121
|
+
def printable_char: () -> ConstantFromArbitrary[String]
|
|
122
|
+
def printable_string: (?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[String]
|
|
123
|
+
def symbol: (?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[Symbol]
|
|
124
|
+
def float: () -> FloatArbitrary
|
|
125
|
+
def set: [T] (_Arbitrary[T] arb, ?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[Set[T]]
|
|
126
|
+
def hash: () -> Integer
|
|
127
|
+
| [K, V] (_Arbitrary[K] key_arbitrary, _Arbitrary[V] value_arbitrary, ?min: Integer, ?max: Integer, ?empty: bool) -> MapArbitrary[Hash[K, V]]
|
|
128
|
+
def boolean: () -> ConstantFromArbitrary[bool]
|
|
129
|
+
def constant: [T] (T val) -> ConstantArbitrary[T]
|
|
130
|
+
def nil: () -> ConstantArbitrary[nil]
|
|
131
|
+
def date: (?base_date: Date, ?past_offset_days: Integer, ?future_offset_days: Integer) -> MapArbitrary[Date]
|
|
132
|
+
def past_date: (?base_date: Date, ?past_offset_days: Integer) -> MapArbitrary[Date]
|
|
133
|
+
def future_date: (?base_date: Date, ?future_offset_days: Integer) -> MapArbitrary[Date]
|
|
134
|
+
def time: (?base_time: Time, ?past_offset_seconds: Integer, ?future_offset_seconds: Integer) -> MapArbitrary[Time]
|
|
135
|
+
def past_time: (?base_time: Time, ?past_offset_seconds: Integer) -> MapArbitrary[Time]
|
|
136
|
+
def future_time: (?base_time: Time, ?future_offset_seconds: Integer) -> MapArbitrary[Time]
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
data/sig/pbt/check.rbs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Pbt
|
|
2
|
+
module Check
|
|
3
|
+
FATAL_EXCEPTIONS: Array[singleton(Exception)]
|
|
4
|
+
|
|
5
|
+
type worker_mode = :none | :ractor
|
|
6
|
+
|
|
7
|
+
interface _Property
|
|
8
|
+
def generate: (?Random rng) -> untyped
|
|
9
|
+
def shrink: (untyped val) -> Enumerator[untyped, untyped]
|
|
10
|
+
def run: (untyped val) -> untyped
|
|
11
|
+
def run_in_ractor: (untyped val) -> Ractor
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Configuration < Struct[untyped]
|
|
15
|
+
attr_accessor verbose: bool
|
|
16
|
+
attr_accessor worker: worker_mode
|
|
17
|
+
attr_accessor num_runs: Integer
|
|
18
|
+
attr_accessor seed: Integer
|
|
19
|
+
attr_accessor thread_report_on_exception: bool
|
|
20
|
+
attr_accessor max_skips: Integer?
|
|
21
|
+
|
|
22
|
+
def initialize: (
|
|
23
|
+
?verbose: bool,
|
|
24
|
+
?worker: worker_mode,
|
|
25
|
+
?num_runs: Integer,
|
|
26
|
+
?seed: Integer,
|
|
27
|
+
?thread_report_on_exception: bool,
|
|
28
|
+
?max_skips: Integer?
|
|
29
|
+
) -> void
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module ConfigurationMethods
|
|
33
|
+
def configuration: () -> Configuration
|
|
34
|
+
def configure: () { (Configuration) -> untyped } -> untyped
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Case < Struct[untyped]
|
|
38
|
+
attr_accessor val: untyped
|
|
39
|
+
attr_accessor ractor: Ractor?
|
|
40
|
+
attr_accessor exception: Exception?
|
|
41
|
+
attr_accessor index: Integer?
|
|
42
|
+
attr_accessor sample: Arbitrary::Sample[untyped]?
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Property
|
|
46
|
+
def initialize: (Arbitrary::_Arbitrary[untyped] arb, ?keyword_args: bool, ?splat_args: bool) { (*untyped, **untyped) -> untyped } -> void
|
|
47
|
+
def generate: (?Random rng) -> untyped
|
|
48
|
+
def generate_for_check: (Random rng) -> untyped
|
|
49
|
+
def shrink: (untyped val) -> Enumerator[untyped, untyped]
|
|
50
|
+
def run: (untyped val) -> void
|
|
51
|
+
def run_in_ractor: (untyped val) -> Ractor
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module RunnerMethods
|
|
55
|
+
def assert: (
|
|
56
|
+
?verbose: bool,
|
|
57
|
+
?worker: worker_mode,
|
|
58
|
+
?num_runs: Integer,
|
|
59
|
+
?seed: Integer,
|
|
60
|
+
?thread_report_on_exception: bool,
|
|
61
|
+
?max_skips: Integer?
|
|
62
|
+
) { () -> _Property } -> void
|
|
63
|
+
|
|
64
|
+
def check: (
|
|
65
|
+
?verbose: bool,
|
|
66
|
+
?worker: worker_mode,
|
|
67
|
+
?num_runs: Integer,
|
|
68
|
+
?seed: Integer,
|
|
69
|
+
?thread_report_on_exception: bool,
|
|
70
|
+
?max_skips: Integer?
|
|
71
|
+
) { () -> _Property } -> Reporter::RunDetails
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -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
|