| Crates.io | cargo-fixeq |
| lib.rs | cargo-fixeq |
| version | 0.5.0 |
| created_at | 2020-01-12 02:35:35.445187+00 |
| updated_at | 2023-12-20 05:37:40.307485+00 |
| description | Fix `assert_eq!` test errors automatically. |
| homepage | |
| repository | https://github.com/quark-zju/cargo-fixeq |
| max_upload_size | |
| id | 197652 |
| size | 28,167 |
cargo-fixeqFix assert_eq! test errors by editing the source code to match the test output.
Inspired by Mercurial's run-tests.py -i.
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:
fn f(n: usize) -> usize {
if n <= 2 { 1 } else { f(n - 1) + f(n - 2) }
}
#[test]
fn test_f() {
assert_eq!(f(10), 0);
assert_eq!(f(20), 0);
}
Run cargo fixeq from the project root:
cargo fixeq
The dummy values are fixed automatically:
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 updating 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.
cargo-fixeq 0.5 works for Rust >= 1.73, which changed assert_eq! output format.cargo-fixeq 0.4 works for Rust < 1.73.