Skip to content

Commit 2e1a230

Browse files
authored
Add test matrix generator (#593)
1 parent fcf376d commit 2e1a230

26 files changed

+921
-82
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ A working example can be found at [openzeppelin-contracts, here.][35]
9999
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
100100
| network | `--network development` | Use network settings defined in the Truffle or Buidler config |
101101
| 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] |
102+
| matrix | `--matrix` | Generate a JSON object that maps which mocha tests hit which lines of code. (Useful
103+
as an input for some fuzzing, mutation testing and fault-localization algorithms.) [More...][38]|
102104

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

@@ -123,6 +125,7 @@ module.exports = {
123125
| measureStatementCoverage | *boolean* | `true` | Computes statement (in addition to line) coverage. [More...][34] |
124126
| measureFunctionCoverage | *boolean* | `true` | Computes function coverage. [More...][34] |
125127
| measureModifierCoverage | *boolean* | `true` | Computes each modifier invocation as a code branch. [More...][34] |
128+
| matrixOutputPath | *String* | `./testMatrix.json` | Relative path to write test matrix JSON object to. [More...][38] |
126129
| istanbulFolder | *String* | `./coverage` | Folder location for Istanbul coverage reports. |
127130
| istanbulReporter | *Array* | `['html', 'lcov', 'text', 'json']` | [Istanbul coverage reporters][2] |
128131
| 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.|
@@ -232,4 +235,5 @@ $ yarn
232235
[35]: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/e5fbbda9bac49039847a7ed20c1d966766ecc64a/scripts/coverage.js
233236
[36]: https://hardhat.org/
234237
[37]: https://github.com/sc-forks/solidity-coverage/blob/master/HARDHAT_README.md
238+
[38]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#generating-a-test-matrix
235239

docs/advanced.md

+15
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,18 @@ Setting the `measureStatementCoverage` and/or `measureFunctionCoverage` options
9797
improve performance, lower the cost of execution and minimize complications that arise from `solc`'s
9898
limits on how large the compilation payload can be.
9999

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

0 commit comments

Comments
 (0)