Git Product home page Git Product logo

Comments (4)

becheran avatar becheran commented on May 25, 2024 1

Thx for reporting. I will have a look.

from ntest.

becheran avatar becheran commented on May 25, 2024

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.

mati865 avatar mati865 commented on May 25, 2024

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.

mati865 avatar mati865 commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.