5 releases (breaking)

0.5.0 Dec 20, 2023
0.4.0 Mar 7, 2020
0.3.0 Jan 12, 2020
0.2.0 Jan 12, 2020
0.1.0 Jan 12, 2020

#266 in Cargo plugins

MIT license

20KB
477 lines

cargo-fixeq

build

Fix assert_eq! test errors by editing the source code to match the test output.

Inspired by Mercurial's run-tests.py -i.

Installation

cargo install cargo-fixeq

Example

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.

Command-line Parameters

All parameters are passed to cargo test. cargo-fixeq does not define its own parameters.

Versions

Similar Projects

Dependencies

~1.5MB
~40K SLoC