ntest
ntest copied to clipboard
`#[ntest::timeout()]` does not work properly with C-string literals
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!();
}
}