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

#[ntest::timeout()] does not work properly with C-string literals #30

Open
muzarski opened this issue Nov 28, 2024 · 0 comments
Open

#[ntest::timeout()] does not work properly with C-string literals #30

muzarski opened this issue Nov 28, 2024 · 0 comments

Comments

@muzarski
Copy link

muzarski commented Nov 28, 2024

Describe the bug
The macro panics when C-String literals are used in the test marked with #[ntest::timeout()].

To Reproduce
Create a new crate with the following in main/lib.rs:

#[cfg(test)]
mod tests {
    #[test]
    #[ntest::timeout(100)]
    fn foo() {
        let _cstr = c"";
    }
}

Expected behavior
The aforementioned code compiles.

Screenshots
Here is the compiler output of cargo check --tests:

error: custom attribute panicked
 --> src/main.rs:8:5
  |
8 |     #[ntest::timeout(100)]
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: Unrecognized literal: `c""`

error[E0425]: cannot find function `foo` in this scope
  --> src/main.rs:9:5
   |
9  | /     fn foo() {
10 | |         let _cstr = c"";
11 | |     }
   | |_____^ not found in this scope

For more information about this error, try `rustc --explain E0425`.

Desktop (please complete the following information):

  • OS: Fedora Linux
  • Version: 39

Additional context
What's interesting, is if the literal is hidden behind a macro_rules!, the error does not appear. Thus, the following compiles as expected:

#[cfg(test)]
mod tests {
    macro_rules! get_cstr {
        () => {
            c""
        };
    }

    #[test]
    #[ntest::timeout(100)]
    fn foo() {
        let cstr = get_cstr!();
    }
}
@muzarski muzarski changed the title #[ntest::timeout()] does not work with properly with C-string literals #[ntest::timeout()] does not work properly with C-string literals Nov 28, 2024
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