Counterexamples and ids
A failure is only useful if you can come back to it: replay it tomorrow, name it in a pull request, pin it once it’s fixed. So every counterexample proptastic saves is a file, and has an id.
A counterexample, an example
Section titled “A counterexample, an example”A counterexample is an input proptastic found that breaks a property: the one a failure
prints, the one a run saves, its file and its id. An example is an input a person chose to
keep, with .example(…), which passes once the bug is fixed. A counterexample you pin becomes an
example, which is why the line that does it says pin it.
The file
Section titled “The file”When a property fails, the run saves its counterexample in counterexamples/ in the build
directory, a file named for the test:
id=c8f0ad315seed=5700478088505024352choices=50/1000000 0/1000000 49/999999idnames this counterexample.seedis the run’s seed, in decimal, as a number.choicesare the choices the domains read, each as the value and the largest it could have been: alice’s 50, bob’s 0, and the amount’s choice 49, which is 50, as the amount starts at 1.
The next run tries those choices before anything else, so the bug fails at once, every run. Once the property passes, the file is deleted. Seeds and replay has the rest.
The file’s name
Section titled “The file’s name”A test’s name can hold anything its language allows: spaces, $, #, letters past ASCII, even
/. Kotlin and Spock name tests in plain words. Taken as it is, a name could leave the directory,
be refused by Windows, or be another test’s file on a Mac, which ignores case. So the name is made
safe, then made unique:
- Only safe characters. Letters
AtoZandatoz, digits,.,_and-are kept; anything else becomes_, one for each character. No name holds a/or\, so none can step out ofcounterexamples/. - Short. At most the name’s last 80 characters, the end being where the test’s own name is. With the rest, a file’s name is at most 94 bytes, far under the 255 systems allow.
- Never hidden, never an option. A name that would start with
., which hides a file, or-, which a command reads as an option, starts with_instead. - Never a Windows device. Windows keeps
CON,PRN,AUX,NUL,COM0toCOM9andLPT0toLPT9for devices, in any case and whatever follows the first dot, so a name that begins with one of those, up to its first dot, starts with_. - No other test’s. Last comes
-and 8 hex digits of the SHA-256 of the test’s name exactly as it is. Soa banda_b, which the first rule makes alike, get files of their own, and so doFooandfoowhere case is ignored.
bank.BankAccountTest#aTransferWithAFeeKeepsTheTotal() is saved as
bank.BankAccountTest_aTransferWithAFeeKeepsTheTotal__-64373114.txt. Every file and folder named
after a test is named by this one rule: its event, events/…-64373114.json, its
corpus’s folder and the folder of a search’s kept inputs. The proptastic
command finds each by the same rule, which every edition keeps.
The id
Section titled “The id”c8f0ad315 is c, for counterexample, and 8 hex digits: the start of the SHA-256 of the
property’s id, a newline, and the choices line. So the same counterexample of the same property
has the same id on every machine, and the next run that finds it finds the same id.
An id is made once, when the counterexample is first saved, and kept after. A run that finds the same choices again keeps it, and so does a test that’s renamed, its file carried to the new name. Different choices are a different counterexample, with an id of its own.
What names one
Section titled “What names one”- The event a failure writes has it, as
id, for a tool to read (Files a run leaves). - The proptastic command takes it, to explain a counterexample or to pin it as an example:
proptastic example c8f0ad315. - A pin can say where it came from with
.via(…)after.example(…), such as.via("c8f0ad315"), which a failure of that example shows.
mutastic’s mutants have ids of the same shape, m and 8 hex digits, so a counterexample and the
mutant it catches can be named side by side.