Skip to content

Commit afd7ef0

Browse files
committed
Add test matrix generator (#593)
1 parent e76a165 commit afd7ef0

25 files changed

+897
-12
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ A working example can be found at [openzeppelin-contracts, here.][35]
5858
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
5959
| network | `--network development` | Use network settings defined in the Hardhat config |
6060
| 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] |
61+
| matrix | `--matrix` | Generate a JSON object that maps which mocha tests hit which lines of code. (Useful
62+
as an input for some fuzzing, mutation testing and fault-localization algorithms.) [More...][39]|
6163

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

@@ -82,6 +84,7 @@ module.exports = {
8284
| measureStatementCoverage | *boolean* | `true` | Computes statement (in addition to line) coverage. [More...][34] |
8385
| measureFunctionCoverage | *boolean* | `true` | Computes function coverage. [More...][34] |
8486
| measureModifierCoverage | *boolean* | `true` | Computes each modifier invocation as a code branch. [More...][34] |
87+
| matrixOutputPath | *String* | `./testMatrix.json` | Relative path to write test matrix JSON object to. [More...][39] |
8588
| istanbulFolder | *String* | `./coverage` | Folder location for Istanbul coverage reports. |
8689
| istanbulReporter | *Array* | `['html', 'lcov', 'text', 'json']` | [Istanbul coverage reporters][2] |
8790
| 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.|
@@ -212,6 +215,7 @@ $ yarn
212215
[36]: https://hardhat.org/
213216
[37]: https://github.com/sc-forks/solidity-coverage/blob/master/HARDHAT_README.md
214217
[38]: https://github.com/sindresorhus/globby#globbing-patterns
218+
[39]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#generating-a-test-matrix
215219
[1001]: https://docs.soliditylang.org/en/v0.8.0/using-the-compiler.html#input-description
216220
[1002]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-stack
217221

docs/advanced.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,18 @@ Setting the `measureStatementCoverage` and/or `measureFunctionCoverage` options
106106
improve performance, lower the cost of execution and minimize complications that arise from `solc`'s
107107
limits on how large the compilation payload can be.
108108

109+
## Generating a test matrix
110+
111+
Some advanced testing strategies benefit from knowing which tests in a suite hit a
112+
specific line of code. Examples include:
113+
+ [mutation testing][22], where this data lets you select the correct subset of tests to check
114+
a mutation with.
115+
+ [fault localization techniques][23], where the complete data set is a key input to algorithms that try
116+
to guess where bugs might exist in a given codebase.
117+
118+
Running the coverage command with `--matrix` will write [a JSON test matrix][25] which maps greppable
119+
test names to each line of code to a file named `testMatrix.json` in your project's root.
120+
121+
[22]: https://github.com/JoranHonig/vertigo#vertigo
122+
[23]: http://spideruci.org/papers/jones05.pdf
123+
[25]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/matrix.md

0 commit comments

Comments
 (0)