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

Test fails without meaningfull error #80

Closed
wucke13 opened this issue Oct 20, 2020 · 6 comments
Closed

Test fails without meaningfull error #80

wucke13 opened this issue Oct 20, 2020 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@wucke13
Copy link

wucke13 commented Oct 20, 2020

Probably one of my features is erroneous, but which one? AFAICT this panics, but I have no clue why. In order to provide a smooth user experience it would be good to at least give a hint about which operation failed?

Runnning RUST_BACKTRACE=full cargo test --test cucumber yields

    Finished test [unoptimized + debuginfo] target(s) in 0.06s
     Running target/debug/deps/cucumber-fa5ad0392460a05d
thread 'main' panicked at 'Box<Any>', /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/macros.rs:13:23
stack backtrace:
   0:     0x55acd74d17b5 - backtrace::backtrace::libunwind::trace::h14d338b30b3ea0a7
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x55acd74d17b5 - backtrace::backtrace::trace_unsynchronized::h73ea91d74a3fd67f
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x55acd74d17b5 - std::sys_common::backtrace::_print_fmt::hd42948c952866e12
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x55acd74d17b5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha8f928866ff7571e
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x55acd74f1ebc - core::fmt::write::he0c1e5f7426d2718
                               at src/libcore/fmt/mod.rs:1076
   5:     0x55acd74cf3b2 - std::io::Write::write_fmt::hf3afc6cfd57d0033
                               at src/libstd/io/mod.rs:1537
   6:     0x55acd74d3dc0 - std::sys_common::backtrace::_print::hfc0110703f3696fd
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x55acd74d3dc0 - std::sys_common::backtrace::print::h3f77c6990ddfaa22
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x55acd74d3dc0 - std::panicking::default_hook::{{closure}}::heae49580a8d62d75
                               at src/libstd/panicking.rs:198
   9:     0x55acd74d3b0c - std::panicking::default_hook::hecc34e3f729e213c
                               at src/libstd/panicking.rs:217
  10:     0x55acd74d4403 - std::panicking::rust_panic_with_hook::he82f5d0644692441
                               at src/libstd/panicking.rs:526
  11:     0x55acd7187a5f - std::panicking::begin_panic::he5aefd58387aa516
                               at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:456
  12:     0x55acd718166e - cucumber_rust::cucumber::Cucumber<W>::features::{{closure}}::h4a5d20ffc4ea8bef
                               at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/macros.rs:13
  13:     0x55acd71bf1bb - core::result::Result<T,E>::unwrap_or_else::h3018b0865befdae0
                               at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/result.rs:853
  14:     0x55acd71814aa - cucumber_rust::cucumber::Cucumber<W>::features::h6644844a43b836a8
                               at /home/wucke13/.cargo/registry/src/github.com-1ecc6299db9ec823/cucumber_rust-0.7.3/src/cucumber.rs:67
  15:     0x55acd717b661 - cucumber::main::hbbf24b4bf9886645
                               at libs/otaws_core/test/cucumber.rs:29
  16:     0x55acd718e9fb - std::rt::lang_start::{{closure}}::h965835a951167d61
                               at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  17:     0x55acd74d47d3 - std::rt::lang_start_internal::{{closure}}::h5d3ea623498f5f43
                               at src/libstd/rt.rs:52
  18:     0x55acd74d47d3 - std::panicking::try::do_call::hac65e71be769a440
                               at src/libstd/panicking.rs:348
  19:     0x55acd74d47d3 - std::panicking::try::hd4706e264bcf6712
                               at src/libstd/panicking.rs:325
  20:     0x55acd74d47d3 - std::panic::catch_unwind::h948a0fb4a8b3ee82
                               at src/libstd/panic.rs:394
  21:     0x55acd74d47d3 - std::rt::lang_start_internal::h72cc068ed2d0ac53
                               at src/libstd/rt.rs:51
  22:     0x55acd718e9d7 - std::rt::lang_start::hb125968c0c74e6ef
                               at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67
  23:     0x55acd717b7ea - main
  24:     0x7fa2e6c96c7d - __libc_start_main
  25:     0x55acd71761aa - _start
                               at ../sysdeps/x86_64/start.S:120
  26:                0x0 - <unknown>
@bbqsrc
Copy link
Member

bbqsrc commented Oct 20, 2020

Hey! Yes, that's bad. We'll fix it!

@wucke13
Copy link
Author

wucke13 commented Oct 26, 2020

I ran into another issue, where again some of my features causes an error. To my surprise, the official ruby-cucumber implementation seems to parse my features just fine. Unfortunately I can not share the feature file in question so far, due to legal reasons. Having the file name would already help, knowing in which line the parser gets unhappy would be excellent!

@bbqsrc bbqsrc added bug Something isn't working help wanted Extra attention is needed labels Oct 26, 2020
@bbqsrc
Copy link
Member

bbqsrc commented Oct 26, 2020

I haven't the time to debug this right now, unfortunately, and didn't find time last week either.

My guess is that it is this line: https://github.com/bbqsrc/cucumber-rust/blob/main/src/cucumber.rs#L100

If you use the example for the Any type in the std library, you can at least print the error before panicking by attempting to cast to &str and String first. If you want to try this, clone the cucumber repo and use path dependencies to build your tests against it.

@bbqsrc bbqsrc added this to the v0.8 milestone Dec 2, 2020
@Andrepuel
Copy link

https://github.com/bbqsrc/cucumber-rust/blob/main/src/cucumber.rs#L100

Looks like this line does not make sense anymore.

Besides the problem mentioned here, what are your thoughts on using the library anyhow on steps definitions? Right now, a step can never fail. We could have something like:

pub struct StepsExample<W> {
    __marker: std::marker::PhantomData<W>,
}
impl<W> StepsExample<W> {
    pub fn given<Cb, U>(&mut self, name: &'static str, cn: Cb) -> &mut Self
    where
        Cb: Fn(W) -> U,
        U: IntoStepResult<W>,
    {
        todo!()
    }

    pub fn given_async<Cb, F, U>(&mut self, name: &'static str, cn: Cb) -> &mut Self
    where
        Cb: Fn(W) -> F,
        F: std::future::Future<Output = U>,
        U: IntoStepResult<W>,
    {
        todo!()
    }
}
pub struct StepError(); // anyhow::Error or something like it
impl From<i32> for StepError {
    //Example conversion, anyhow already does it
    fn from(_: T) -> Self {
        StepError()
    }
}
pub trait IntoStepResult<W> {
    fn into_step_result(self) -> Result<W, StepError>;
}
impl<W> IntoStepResult<W> for W {
    fn into_step_result(self) -> Result<W, StepError> {
        Ok(self)
    }
}
impl<W, E> IntoStepResult<W> for Result<W, E>
where
    E: Into<StepError>,
{
    fn into_step_result(self) -> Result<W, StepError> {
        self.map_err(|e| e.into())
    }
}

fn sample(steps: &mut StepsExample<String>) {
    steps.given("something", |word| format!("-- {}", word));
    steps.given_async("something async", |_word| async move { Err(StepError()) });
    steps.given("error conversion", |_world| Err(32));
}

@Andrepuel
Copy link

I noticed that the error reporting fails only on async steps. Probably because we reset the panic hook, which tokio (using tokio on my experiments) also needs to set.

I think the best approach would be to depend on some Async runtime (tokio or async-std) and then use spawn for async steps. Instead of setting a hook for panic, we just use the JoinHandle to fetch if the task failed with panic.

@tyranron
Copy link
Member

Fixed in #128 as parsing errors are now propagated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants