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

Example usage of test_matrix broken #144

Open
till-metaco opened this issue Jul 15, 2024 · 1 comment
Open

Example usage of test_matrix broken #144

till-metaco opened this issue Jul 15, 2024 · 1 comment

Comments

@till-metaco
Copy link

Description

The example usage for test_matrix does not compile in version 3.3.1 with rustc 1.77.2.

To reproduce

  1. Create an empty project with cargo new test_matrix
  2. Add test_case with cargo add --dev test-case
  3. Add the test module from the example usage on crates.io like so
fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    use test_case::test_matrix;

    #[test_matrix(
        [-2, 2],
        [-4, 4]
    )]
    fn multiplication_matrix_tests(x: i8, y: i8) {
        let actual = (x * y).abs();

        assert_eq!(8, actual)
    }
}
  1. Compile and run the tests with cargo test

Expected behaviour

The tests compile and run without errors

Actual behaviour

The tests don't compile with the error message

error[E0428]: the name `_2_2_expects` is defined multiple times
  --> src/main.rs:9:5
   |
9  | /     #[test_matrix(
10 | |         [-2, 2],
11 | |         [-2, 4]
12 | |     )]
   | |______^ `_2_2_expects` redefined here
   |
   = note: `_2_2_expects` must be defined only once in the value namespace of this module
   = note: this error originates in the attribute macro `test_matrix` (in Nightly builds, run with -Z macro-backtrace for more info)

Additional context

The error seems to stem from the way the minus signs are translated to function names, because it compiles if the matrix is defined as

   #[test_matrix(
        [-1, 2],
        [-3, 4]
    )]

(these tests compile, but fail for obvious reasons.

@till-metaco
Copy link
Author

Seems related to #19

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

1 participant