Skip to content

Commit

Permalink
Add docs for failures persistence and replay (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Aug 8, 2024
1 parent b83a2ff commit 7c8eda2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Forge Standard Library Overview](./forge/forge-std.md)
- [Understanding Traces](./forge/traces.md)
- [Fork Testing](./forge/fork-testing.md)
- [Replaying Failures](./forge/replay-testing.md)
<!-- - [Coverage Reports]() !-->
- [Advanced Testing](./forge/advanced-testing.md)
- [Fuzz Testing](./forge/fuzz-testing.md)
Expand Down
42 changes: 42 additions & 0 deletions src/forge/replay-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Replaying Failures

Forge supports incrementally replaying last test run failures by persisting them on the disk.
### Rerun failures
The `--rerun` option can be used to omit successful tests and replay recorded failures only:
```bash
forge test --rerun
```
The failed tests are written in `~/.foundry/cache/test-failures` file. This file is updated each time `forge test` is performed, so it reflects failures from the last run.

### Fuzz tests failures
Forge saves all fuzz tests counterexamples and replays them before new test campaigns are started (This is done in order to ensure there is no regression introduced).
Fuzz tests failures encountered in several runs are by default persisted in `~/.foundry/cache/fuzz/failures` file. The file content is not replaced by subsequent test runs, but new records are added to existing entries.

The default file used to persist and rerun fuzz test failures from can be changed in foundry.toml:
```toml
[fuzz]
failure_persist_file="/tests/failures.txt"
```

or by using inline config
```Solidity
/// forge-config: default.fuzz.failure-persist-file = /tests/failures.txt
```

### Invariant tests failures
Failures from invariant tests are saved and replayed before new test campaigns are started, similar with fuzz tests. The difference is that the failed sequences are persisted in individual files, with specific `~/.foundry/cache/invariant/failures/{TEST_SUITE_NAME}/{INVARIANT_NAME}` default path. Content of this file is replaced only when a different counterexample is found.

The default directory to persist invariant test failures can be changed in foundry.toml:
```toml
[invariant]
failure_persist_dir="/tests/dir"
```

or by using inline config
```Solidity
/// forge-config: default.invariant.failure-persist-dir = /tests/dir
```

### Remove persisted failures
To ignore saved failures and start a clean test campaign, simply remove the persisted files or run [`forge clean`](../reference/forge/forge-clean.md) (removes all build artifacts and cache directories).

0 comments on commit 7c8eda2

Please sign in to comment.