Home / Learn / 19 Editions
19.7 Testing it
Page 8 of 11
19.7.1 Three tests on the export of main
The package is of edition 0.3, so each one is a test. The tests check the parser and both kinds of run, on the same export that main uses, so a reader can compare their numbers with the program's output. The two runs use silent, so they print nothing, and they check what was performed:
test "a line that does not parse is left out"
do read_lines(export()).len
expect result == 3
test "a dry run counts the labels and prints none"
given @printer = silent()
do print_labels(read_lines(export()), dry_run: true)
expect result == 2
expect not performed @printer.print_label
test "a run prints a label for each line with stock"
given @printer = silent()
do print_labels(read_lines(export()), dry_run: false)
expect result == 2
expect performed @printer.print_label19.7.2 A plain dry_run and the calls silent records
The tests pass dry_run as a plain true or false. Here the tests have nothing to prove about it: each installs its own printer with given, and the condition is proven once, inside print_labels, for every value of dry_run, so the tests only check behavior. silent answers every print_label with unit, and the trace of each test records the calls, which expect performed and expect not performed read.
19.7.3 The proof and the tests
The proof and the tests cover different ground. The verifier proves, for every list and every call, that a label is printed only when dry_run is false, and the lock in una.toml keeps that rule from being dropped. The test "a dry run counts the labels and prints none" checks the same rule on one list, with expect not performed, and also checks the count, which no condition states. After an upgrade of una to a later release, rerun both: a stricter rule can only add obligations or errors, and the tests catch a change in behavior.
19.7.4 Running the tests
una test . prints:
test labels "a line that does not parse is left out" ... ok
test labels "a dry run counts the labels and prints none" ... ok
test labels "a run prints a label for each line with stock" ... ok
3 tests: 3 passed, 0 failedNext:19.8 Common mistakes