register ?hash ?pp ?expected_sampling_ratio ?minimum_number_of_samples ?regression ?stop_after ?on_sample gen property
runs the property
on random values generated with gen
.
The property is run on as many samples as possible depending on stop_after
. gen
is called any time a new simple must be provided.
The seed used to generate samples is controlled by Tezt (see Test.register
). This function ensures that if the test is run twice with the same seed, then the same values will be generated.
The property
will be called on each generated sample produced by gen
. It does so in an environment where the output on both stdout
and stderr
is captured by default. Except for the counter-example found for which, property
is run again without capturing anything. This behaviour should ease the debugging (especially hello debugging).
The test can fail in the following cases:
1) A counter example was found
2) The last run with the counter example succeeded
3) Not enough samples were generated
The first case is expected. The reason for the second case, is likely related to non-determinism of the property since the test was run twice with the same generated value. For the third case, this is to ensure the property is run on many samples as detailed below.
One issue with proerty-based testing is that it is not easy to ensure that the generator and the property are run an a large range of values. The default behaviour of this register function is to prevent such a case to occur. To do so, two parameters are used: expected_sampling_ratio
andminimum_number_of_samples
.
expected_sampling_ratio
(by default 0.10) ensures that the generator generates in general different sample.
minimum_number_of_samples
(by default 50) ensures that the property is run at least that numbero f times.
Those default values should ensure that it is not a constraint most of the times, while at the same time should capture erronenous cases.
stop_after
allows to determine how many samples should be drawn to run the property on. By default it is set to `Timeout 0.10
, meaning that the test will stop after 100ms. It can be set to `Count n
to decide a precise number of times the test should be run. Do note that the default value depends on the CLI arguments provided by the user. If --loop
was set, then the default value is `Loop
. While if `--loop-count n
was set with n > 1
, the default value will be `Count n
.
on_sample
is called any time a new value is generated.
If pp
is provided, it can be used to print the counter-example found.
If hash
is provided, it will be used to hash
values. This function is used to count the number of distinct samples.
regression
can be instantiated to be sure that some fixed deterministic examples is always run.
This function can be influenced with two options from the command-line:
--shrink
triggers the shrinker to find a smaller counter-example. An explanation about shrinking can be found in the documentation of the package Bam
.
--no-capture
so that output is not captured