cargo-fixeq
Fix assert_eq!
test errors by editing the source code.
Inspired by Mercurial's run-tests.py -i
.
bash
cargo install cargo-fixeq
Write tests using assert_eq!
as usual. Put the code to evaluate on the left, leave a dummy value on the right:
```rust fn f(n: usize) -> usize { if n <= 2 { 1 } else { f(n - 1) + f(n - 2) } }
fn testf() { asserteq!(f(10), 0); assert_eq!(f(20), 0); } ```
Run cargo fixeq
:
bash
cargo fixeq
The dummy values are fixed automatically:
diff
fn test_f() {
- assert_eq!(f(10), 0);
- assert_eq!(f(20), 0);
+ assert_eq!(f(10), 55);
+ assert_eq!(f(20), 6765);
}
In general, cargo-fixeq
can be helpful for writing initial tests and update tests. See here for a more complicated real world example.
All parameters are passed to cargo test
. cargo-fixeq
does not define its own parameters.