Comments (4)
Thx for reporting. I will have a look.
from ntest.
Sorry for the very late delay. Just had a look how the timout
macro expands and I can't see the problem yet.
I have a simple test:
#[test]
#[ntest::timeout(1000)]
fn timeout_test() {
assert!(false);
}
Which expands to:
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "timeout_test"]
pub const timeout_test: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("timeout_test"),
ignore: false,
ignore_message: ::core::option::Option::None,
source_file: "tests\\end_to_end.rs",
start_line: 12usize,
start_col: 4usize,
end_line: 12usize,
end_col: 16usize,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::IntegrationTest,
},
testfn: test::StaticTestFn(|| test::assert_test_result(timeout_test())),
};
fn timeout_test() {
fn ntest_callback() {
if !false {
::core::panicking::panic("assertion failed: false")
}
}
let ntest_timeout_now = std::time::Instant::now();
let (sender, receiver) = std::sync::mpsc::channel();
std::thread::spawn(move || { if let Ok(()) = sender.send(ntest_callback()) {} });
match receiver.recv_timeout(std::time::Duration::from_millis(1000u64)) {
Ok(t) => return t,
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
::std::rt::panic_fmt(
format_args!(
"timeout: the function call took {0} ms. Max time {1} ms",
ntest_timeout_now.elapsed().as_millis(),
1000u64,
),
);
}
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
::std::rt::begin_panic("explicit panic")
}
}
}
I see that rust analyzer fails to interprete this and does not show the > Run Test
icon. But I don't know why? What is wrong with the expansion?
Without using the timeout macro it would have expanded to:
extern crate test;
#[cfg(test)]
#[rustc_test_marker = "timeout_test"]
pub const timeout_test: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName("timeout_test"),
ignore: false,
ignore_message: ::core::option::Option::None,
source_file: "tests\\end_to_end.rs",
start_line: 11usize,
start_col: 4usize,
end_line: 11usize,
end_col: 16usize,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::IntegrationTest,
},
testfn: test::StaticTestFn(|| test::assert_test_result(timeout_test())),
};
fn timeout_test() {
if !false {
::core::panicking::panic("assertion failed: false")
}
}
from ntest.
Just a guess but I think the macros are expanded differently when this is performed by RA. I have no other sensible expalnation for panic happening in #23 when using RA but not when building code with Cargo.
I hope to look into this issue from RA side but cannot give any ETA.
from ntest.
Given the discussion in rust-lang/rust-analyzer#11109 I do believe there is nothing left to fix in this crate and missing test/debug button is RA bug.
When RA expands the macros it seems to consider each attribute separately so when expanding #[ntest::timeout(1000)]
it "sees" only pub fn ...
part and doesn't consider that function as a test.
As a workaround I think it should be possible to provide workaround attribute like that but I'd have to experiment with it first:
#[ntest::timeout_some_name(test, 1000)]
fn timeout_test() {
assert!(false);
}
#[ntest::timeout_some_name(tokio::test, 1000)]
async fn timeout_test() {
assert!(false);
}
timeout_some_name
(with proper name ofc) would take test macro and timeout, add or expand that macro (don't know yet how RA will behave) over code generated by ntest and then return it to RA.
from ntest.
Related Issues (11)
- Expected identifier error HOT 1
- ntest broken against latest syn crate HOT 3
- Running release tests causes SIGILL HOT 3
- `timeout` attribute reports timeout even when test panics HOT 3
- Version 0.8.1 not in repo? HOT 1
- Negative numbers HOT 1
- Rust Analyzer gives a warning (incorrect_ident_case) if `test_case` argument is an enum or struct
- Add feature for async test of #[tokio::test] cases HOT 5
- timeout macro for tests which return Result HOT 3
- Since removing timebomb stuck tests do not timeout and fail HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ntest.