Skip to content

Coverage ​

--coverage instruments what it compiles: the entry of every function and every statement of every block increments a counter, and the counters are written beside the output when the program ends - a return, a panic and an exit all write.

sh
talor test src/main.talor --coverage -o build/main.ll
talor build --coverage

The compiler writes <stem>.covmap beside the output, naming what each counter is: the file, the line and column, whether it is a function or a statement, and the function's name. The running program writes the counts beside itself, and TALOR_COV_FILE overrides where they go.

talor run refuses the flag, because what it builds it deletes, and coverage data that dies with the temporary is not data:

'--coverage' is a flag of compile, test and build, and the data is written beside what they build; 'cov report' reads it

What is counted ​

The program's own source: the tree the root module sits in. The standard library and a package reached by a require are compiled with the program and are not regions, because a total the library dominates is a number no build step can gate on. A closure's body is counted like any other statement its function holds, and the entry point the compiler writes is not a region.

talor cov report ​

A report takes .covmap or .covdata paths, pairs each with its sibling, and sums the counts of regions that name the same file, line, column, kind and function - two instances of a generic are one region, and a hit in either one is a hit:

sh
talor cov report build/main.covdata
file          regions  covered  cover
main.talor          5        3  60.0%  1, 5
TOTAL               5        3  60.0%

The lines the last column names are the ones with a region that was never reached. The percentage is regions covered and not lines: a line counts because a region starts on it, and a line no region starts on - a comment, a blank line, a brace - is outside the accounting altogether.

--min <pct> takes a percentage from 0 to 100 and answers 1 when the total is under it, which is the question a build step asks:

sh
talor cov report build/main.covdata --min 80
coverage 60.0% is under --min 80

talor cov annotate ​

The same data against the source, under the file's name, one mark per line: - for a line where a region was not reached, . for one where every region was, and a space for a line no region starts on.

main.talor
- fn unused(n: i64): i64 {
      n * 2
  }

. fn main(): i32 {
.     println(`${sign(3)}`);
      0
  }

Counters are plain increments and are not synchronized: under threads a count can be lost, and a lost count can only lose a line, never invent one.

Talor v0.1.0 - Released under the MIT OR Apache-2.0 license.