madlib icon indicating copy to clipboard operation
madlib copied to clipboard

Test coverage counts accessing any field of a Record as coverage for the whole Record

Open brekk opened this issue 9 months ago • 0 comments

Consider the following two files and their related tests:

Temp.mad

import String from "String"

untested :: Integer -> String
untested = (y) => show(y) ++ "!"

emphasis :: Integer -> String
emphasis = String.repeat('!')

export record = { emphasis, untested }

Temp2.mad

import String from "String"

untested :: Integer -> String
export untested = (y) => show(y) ++ "!"

emphasis :: Integer -> String
export emphasis = String.repeat('!')

export record = { emphasis, untested }

Temp.spec.mad

import { assertEquals, test } from "Test"
import { record } from "./Temp2"
test("record coverage", () => assertEquals("coverage" ++ record.emphasis(5), "coverage!!!!!"))

Temp2.spec.mad

import { assertEquals, test } from "Test"
import { emphasis } from "./Temp2"
test("emphasis coverage", () => assertEquals("coverage" ++ emphasis(5), "coverage!!!!!"))

Running these with madlib test --coverage results in coverage being counted like so:

Coverage
--------

Module          Lines  Functions  Branches   Total
--------------------------------------------------
src/Temp.mad   66.66%      0.00%   100.00%  55.55%
src/Temp2.mad  33.33%      0.00%   100.00%  44.44%
Total          49.99%      0.00%   100.00%  49.99%

I'd expect them to be equivalent (ish?), but the test which uses the record form counts coverage for the whole record, rather than just one of its fields.

brekk avatar Apr 28 '24 02:04 brekk