Skip to content

Additional Coverage Measurements #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8e8f668
Add branch coverage for logical OR conditions (#499)
cgewecke Apr 22, 2020
bdc6f91
Update logical-or tests for Hardhat
cgewecke Dec 3, 2020
7f85a0c
Update tests for solc 0.7.x (#582)
cgewecke Dec 4, 2020
43ccd3b
Suppress compilation warnings introduced by injected trace statements…
cgewecke Dec 4, 2020
292819d
Remove truffle library backup copy (#584)
cgewecke Dec 4, 2020
7403f3f
Add coverage for ternary conditionals (#587)
cgewecke Dec 8, 2020
bf77884
Add modifier-invocation-as-branch coverage (#588)
cgewecke Dec 15, 2020
c1bd4bc
Use bytes8 instead of bytes32 as hash key (#590)
cgewecke Dec 17, 2020
0ac8e74
Add coverage measurement category options (#592)
cgewecke Jan 4, 2021
4487a1b
Add test matrix generator (#593)
cgewecke Jan 5, 2021
350e699
Do not treat inheritance constructors as branches (#594)
cgewecke Jan 5, 2021
23f7987
Fix pre/post strategy for modifier coverage (#595)
cgewecke Jan 5, 2021
2be29b2
Allow duplicate modifiers on same function (#596)
cgewecke Jan 6, 2021
b2d4a66
Add modifierWhitelist option (#597)
cgewecke Jan 6, 2021
ac0618c
Add ABI diff logic (#598)
cgewecke Jan 11, 2021
833dba0
Add abi diff plugin method tests (#600)
cgewecke Jan 12, 2021
bebeb37
Generate mocha JSON output with --matrix (#601)
cgewecke Jan 13, 2021
58e0396
Update @solidity-parser/parser to 0.14.1
cgewecke Mar 29, 2022
ca1e23b
Stop injecting statement coverage into conditionals
cgewecke Mar 29, 2022
c650762
Update tests for adjusted statement coverage
cgewecke Mar 29, 2022
416fd69
Fix constructor keyword test
cgewecke Mar 29, 2022
495c6f8
Fix if/else tests
cgewecke Mar 29, 2022
bb24453
Fix loops, modifiers, options and statements tests
cgewecke Mar 29, 2022
a316160
Fix rebase errors & regenerate yarn.lock
cgewecke Apr 26, 2022
1621558
Remove buidler
cgewecke Apr 26, 2022
819bbaf
Remove more buildler things
cgewecke Apr 26, 2022
a3b4d72
Fix assert tests
cgewecke Apr 26, 2022
33586e2
Fix constructor test
cgewecke Apr 26, 2022
df84fbf
Temporarily skip truffle integration tests
cgewecke Apr 26, 2022
63ad677
Fix true/false scoped method definition function visibilities
cgewecke Apr 26, 2022
f84e1da
Remove Builder-E2E test
cgewecke Apr 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 0 additions & 133 deletions BUIDLER_README.md

This file was deleted.

12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ A working example can be found at [openzeppelin-contracts, here.][35]
| Option <img width=200/> | Example <img width=750/>| Description <img width=1000/> |
|--------------|------------------------------------|--------------------------------|
| file | `--file="test/registry/*.js"` | (Truffle) Filename or glob describing a subset of tests to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
| testfiles | `--testfiles "test/registry/*.ts"` | (Buidler) Test file(s) to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
| testfiles | `--testfiles "test/registry/*.ts"` | (Hardhat) Test file(s) to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
| network | `--network development` | Use network settings defined in the Truffle or Buidler config |
| network | `--network development` | Use network settings defined in the Truffle or Hardhat config |
| temp[<sup>*</sup>][14] | `--temp build` | :warning: **Caution** :warning: Path to a *disposable* folder to store compilation artifacts in. Useful when your test setup scripts include hard-coded paths to a build directory. [More...][14] |
| matrix | `--matrix` | Generate a JSON object that maps which mocha tests hit which lines of code. (Useful
as an input for some fuzzing, mutation testing and fault-localization algorithms.) [More...][39]|

[<sup>*</sup> Advanced use][14]

Expand All @@ -98,6 +100,11 @@ module.exports = {
| skipFiles | *Array* | `['Migrations.sol']` | Array of contracts or folders (with paths expressed relative to the `contracts` directory) that should be skipped when doing instrumentation. |
| measureStatementCoverage | *boolean* | `true` | Computes statement (in addition to line) coverage. [More...][34] |
| measureFunctionCoverage | *boolean* | `true` | Computes function coverage. [More...][34] |
| measureModifierCoverage | *boolean* | `true` | Computes each modifier invocation as a code branch. [More...][34] |
| modifierWhitelist | *String[]* | `[]` | List of modifier names (ex: "onlyOwner") to exclude from branch measurement. (Useful for modifiers which prepare something instead of acting as a gate.)) |
| matrixOutputPath | *String* | `./testMatrix.json` | Relative path to write test matrix JSON object to. [More...][39]|
| mochaJsonOutputPath | *String* | `./mochaOutput.json` | Relative path to write mocha JSON reporter object to. [More...][39]|
| abiOutputPath | *String* | `./humanReadableAbis.json` | Relative path to write diff-able ABI data to |
| istanbulFolder | *String* | `./coverage` | Folder location for Istanbul coverage reports. |
| istanbulReporter | *Array* | `['html', 'lcov', 'text', 'json']` | [Istanbul coverage reporters][2] |
| mocha | *Object* | `{ }` | [Mocha options][3] to merge into existing mocha config. `grep` and `invert` are useful for skipping certain tests under coverage using tags in the test descriptions.|
Expand Down Expand Up @@ -228,6 +235,7 @@ $ yarn
[36]: https://hardhat.org/
[37]: https://github.com/sc-forks/solidity-coverage/blob/master/HARDHAT_README.md
[38]: https://github.com/sindresorhus/globby#globbing-patterns
[39]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#generating-a-test-matrix
[1001]: https://docs.soliditylang.org/en/v0.8.0/using-the-compiler.html#input-description
[1002]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-stack

24 changes: 24 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,27 @@ Setting the `measureStatementCoverage` and/or `measureFunctionCoverage` options
improve performance, lower the cost of execution and minimize complications that arise from `solc`'s
limits on how large the compilation payload can be.

## Generating a test matrix

Some advanced testing strategies benefit from knowing which tests in a suite hit a
specific line of code. Examples include:
+ [mutation testing][22], where this data lets you select the correct subset of tests to check
a mutation with.
+ [fault localization techniques][23], where the complete data set is a key input to algorithms that try
to guess where bugs might exist in a given codebase.

Running the coverage command with `--matrix` will write [a JSON test matrix][25] which maps greppable
test names to each line of code to a file named `testMatrix.json` in your project's root.

It also generates a `mochaOutput.json` file which contains test run data similar to that
generated by mocha's built-in [JSON reporter][27].

In combination these data sets can be passed to Joram's Honig's [tarantula][29] tool which uses
a fault localization algorithm to generate 'suspiciousness' ratings for each line of
Solidity code in your project.

[22]: https://github.com/JoranHonig/vertigo#vertigo
[23]: http://spideruci.org/papers/jones05.pdf
[25]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/matrix.md
[27]: https://mochajs.org/api/reporters_json.js.html
[29]: https://github.com/JoranHonig/tarantula
Loading