go-internal icon indicating copy to clipboard operation
go-internal copied to clipboard

testscript: IgnoreMissedCoverage is unused

Open FiloSottile opened this issue 3 years ago • 2 comments

It doesn't look like Params.IgnoreMissedCoverage and IgnoreMissedCoverage() are wired up to anything, and indeed code paths that end with os.Exit are missing from the coverage report without an error being raised.

FiloSottile avatar Jun 21 '22 11:06 FiloSottile

Looks like I'm to blame here; ignoreMissedCoverage was used until my refactor in dc4b49510d96256f881880b9802536a6a70edfcc.

mvdan avatar Jun 21 '22 11:06 mvdan

In the previous mechanism, each command ran as a sub-process and was expected to produce exactly one coverage profile. This is why the boolean option mattered: if the sub-process failed to produce the coverage file, by default we would error, unless the option was enabled.

The new mechanism allows command sub-processes to produce multiple coverage files, for the sake of collecting and merging all of them. This allows us to measure the code coverage of Go tools or programs which execute themselves as children, akin to go build.

However, swapping the "must produce 1 file" for "may produce any number of files", I failed to add back the requirement that at least one file should be produced - since each command spawns at least one Go sub-process. When that is fixed, then IgnoreMissedCoverage has a purpose again.

It's worth noting that, right now, TESTSCRIPT_COVER_DIR is shared across all commands and their invocations, so we can't simply check whether the directory is not empty. One option is to use a separate directory per command invocation, mimicking the old behavior with coverFilename.

mvdan avatar Jun 21 '22 12:06 mvdan