Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test does not run when passed a negative number #18

Closed
ColinPitrat opened this issue Apr 6, 2019 · 4 comments
Closed

Test does not run when passed a negative number #18

ColinPitrat opened this issue Apr 6, 2019 · 4 comments
Assignees

Comments

@ColinPitrat
Copy link

I've been puzzled by tests that wouldn't run. I finally traced it down to giving a negative argument.

The following works:

    #[rstest_parametrize(
        input, expected,
        case(0.0, 0.0),
        case(1.0, 1.0),
        )]
    fn identity(input: f64, expected: f64) {
        assert_eq!(input, expected);
    }

and produces the following output:

running 2 tests
test point::tests::identity_case_0 ... ok
test point::tests::identity_case_1 ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Adding a case with a negative value, the test doesn't run anymore:

    #[rstest_parametrize(
        input, expected,
        case(0.0, 0.0),
        case(1.0, 1.0),
        case(-1.0, -1.0),
        )]
    fn identity(input: f64, expected: f64) {
        assert_eq!(input, expected);
    }

it produces the following output:

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The issue happens with or without nightly.
cargo 1.33.0 (f099fe94b 2019-02-12)
rustc 1.33.0 (2aa4c46cf 2019-02-28)

cargo 1.35.0-nightly (6f3e9c367 2019-04-04)
rustc 1.35.0-nightly (acd8dd6a5 2019-04-05)

I'm using rstest 0.2.2. From Cargo.lock:

"checksum rstest 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "17060b44b74f0aed4e7ee6c970e57b5e51adbd3aecd814e1ab38a27e00901d67"
@la10736
Copy link
Owner

la10736 commented Apr 7, 2019

Hi @ColinPitrat , thanks to report it.

trunk version at least point the issue by a meaningful error message:

   Compiling playground v0.1.0 (/home/michele/learning/rust/rstest/playground)
error: expected identifier or literal
 --> src/main.rs:7:6
  |
7 | case(-1.0, -1.0),
  |      ^

error: aborting due to previous error

I'll fix it ASAP but I cannot release the fix till the next version that I planned in the next month (I hope).

As work around you can use Unwrap("<arbitrary rust code>") syntax that should works as expected:

use rstest::rstest_parametrize;

#[rstest_parametrize(
input, expected,
case(0.0, 0.0),
case(1.0, 1.0),
case(Unwrap("-1.0"), Unwrap("-1.0")),
)]
fn identity(input: f64, expected: f64) {
    assert_eq!(input, expected);
}
michele@DartVader:~/learning/rust/ddddddd$ cargo test
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running target/debug/deps/ddddddd-0a92a75e7aec63ff

running 3 tests
test identity_case_2 ... ok
test identity_case_0 ... ok
test identity_case_1 ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

@ColinPitrat
Copy link
Author

Thanks for the tip. On top of fixing it, I wonder if there would be a way to ensure this kind of failures don't go unnoticed. The good practice is to make a test fail before making it pass to avoid this kind of problem but it's easy to forget and not even notice that some tests are not running.

@la10736
Copy link
Owner

la10736 commented Apr 7, 2019

From the next release this kind of odd behavior should never happen. Every kind of wrong syntax or parsing errors will be reported.

@la10736 la10736 self-assigned this Apr 8, 2019
la10736 pushed a commit that referenced this issue Apr 8, 2019
corner cases. Now syntax like case(some(42)) works but I don't know if
I really want it ... by now I accept it.
@la10736
Copy link
Owner

la10736 commented Apr 9, 2019

General case will be traced in #19

@la10736 la10736 closed this as completed Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants