Skip to content

Commit 0bf470a

Browse files
authored
Move to staging branch for 0.8.0 restructure (#502)
Additional Coverage Measurements
2 parents 5174ecd + f84e1da commit 0bf470a

File tree

243 files changed

+8073
-5746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+8073
-5746
lines changed

BUIDLER_README.md

-133
This file was deleted.

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ A working example can be found at [openzeppelin-contracts, here.][35]
7171
| Option <img width=200/> | Example <img width=750/>| Description <img width=1000/> |
7272
|--------------|------------------------------------|--------------------------------|
7373
| 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])|
74-
| testfiles | `--testfiles "test/registry/*.ts"` | (Buidler) Test file(s) to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
74+
| testfiles | `--testfiles "test/registry/*.ts"` | (Hardhat) Test file(s) to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
7575
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
76-
| network | `--network development` | Use network settings defined in the Truffle or Buidler config |
76+
| network | `--network development` | Use network settings defined in the Truffle or Hardhat config |
7777
| 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] |
78+
| matrix | `--matrix` | Generate a JSON object that maps which mocha tests hit which lines of code. (Useful
79+
as an input for some fuzzing, mutation testing and fault-localization algorithms.) [More...][39]|
7880

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

@@ -98,6 +100,11 @@ module.exports = {
98100
| skipFiles | *Array* | `['Migrations.sol']` | Array of contracts or folders (with paths expressed relative to the `contracts` directory) that should be skipped when doing instrumentation. |
99101
| measureStatementCoverage | *boolean* | `true` | Computes statement (in addition to line) coverage. [More...][34] |
100102
| measureFunctionCoverage | *boolean* | `true` | Computes function coverage. [More...][34] |
103+
| measureModifierCoverage | *boolean* | `true` | Computes each modifier invocation as a code branch. [More...][34] |
104+
| 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.)) |
105+
| matrixOutputPath | *String* | `./testMatrix.json` | Relative path to write test matrix JSON object to. [More...][39]|
106+
| mochaJsonOutputPath | *String* | `./mochaOutput.json` | Relative path to write mocha JSON reporter object to. [More...][39]|
107+
| abiOutputPath | *String* | `./humanReadableAbis.json` | Relative path to write diff-able ABI data to |
101108
| istanbulFolder | *String* | `./coverage` | Folder location for Istanbul coverage reports. |
102109
| istanbulReporter | *Array* | `['html', 'lcov', 'text', 'json']` | [Istanbul coverage reporters][2] |
103110
| 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.|
@@ -228,6 +235,7 @@ $ yarn
228235
[36]: https://hardhat.org/
229236
[37]: https://github.com/sc-forks/solidity-coverage/blob/master/HARDHAT_README.md
230237
[38]: https://github.com/sindresorhus/globby#globbing-patterns
238+
[39]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/advanced.md#generating-a-test-matrix
231239
[1001]: https://docs.soliditylang.org/en/v0.8.0/using-the-compiler.html#input-description
232240
[1002]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#running-out-of-stack
233241

docs/advanced.md

+24
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,27 @@ 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+
It also generates a `mochaOutput.json` file which contains test run data similar to that
122+
generated by mocha's built-in [JSON reporter][27].
123+
124+
In combination these data sets can be passed to Joram's Honig's [tarantula][29] tool which uses
125+
a fault localization algorithm to generate 'suspiciousness' ratings for each line of
126+
Solidity code in your project.
127+
128+
[22]: https://github.com/JoranHonig/vertigo#vertigo
129+
[23]: http://spideruci.org/papers/jones05.pdf
130+
[25]: https://github.com/sc-forks/solidity-coverage/blob/master/docs/matrix.md
131+
[27]: https://mochajs.org/api/reporters_json.js.html
132+
[29]: https://github.com/JoranHonig/tarantula

0 commit comments

Comments
 (0)