cucumber-rs / cucumber

Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
https://cucumber-rs.github.io/cucumber/main
Apache License 2.0
563 stars 69 forks source link

Problem with Cucumber setup #314

Closed Earthworn closed 9 months ago

Earthworn commented 9 months ago

Hi, i followed the Quickstart guide and tried to run die example tests. I m on Windows 10 When i call cargo test -p cucumber --test example it fails instantly with: (error: package cucumber cannot be tested because it requires dev-dependencies and is not a member of the workspace) I also tried cargo test --test example then it does start to compile but fails with: could not compile quickstart_2 (test "example") due to previous error; 1 warning emitted Here is an extract of the warning:

          Warning: .drectve `-exclude-symbols:_ZN4core3ops8function6FnOnce9call_once17h718365105d8c95cbE ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr257drop_in_place$LT$hashbrown..raw..RawTable$LT$$LP$$RF$str$C$$LP$$RP$$RP$$GT$..reserve_rehash$LT$hashbrown..map..make_hasher$LT$$RF$str$C$$LP$$RP$$C$std..collections..hash..map..RandomState$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he7df083f920ee42dE" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr26drop_in_place$LT$usize$GT$17h8a0c2301359c414aE" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr30drop_in_place$LT$$RF$usize$GT$17h5544a261123022e1E" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr32drop_in_place$LT$$RF$$RF$str$GT$17ha965fb47bd2bf802E" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr365drop_in_place$LT$hashbrown..raw..RawTable$LT$$LP$$RF$str$C$$LP$$RP$$RP$$GT$..find_or_find_insert_slot$LT$hashbrown..map..equivalent_key$LT$$RF$str$C$$RF$str$C$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$C$hashbrown..map..make_hasher$LT$$RF$str$C$$LP$$RP$$C$std..collections..hash..map..RandomState$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17h949f7561e009f6bbE" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr47drop_in_place$LT$$LP$$RF$str$C$$LP$$RP$$RP$$GT$17hebf4139d97db4920E" ' unrecognized     
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr52drop_in_place$LT$std..thread..local..AccessError$GT$17hb86a08c2686349d6E" ' unrecognized          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr76drop_in_place$LT$$RF$std..collections..hash..set..HashSet$LT$$RF$str$GT$$GT$17h30baf595195e3006E" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core4char7methods22_$LT$impl$u20$char$GT$8len_utf817h15fef8e0022228b2E" ' unrecognized
          Warning: .drectve `-exclude-symbols:_ZN4core5alloc6layout6Layout5array5inner17h97939f616f56a5faE ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN81_$LT$core..str..iter..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17ha5040fb0292b72dfE" ' unrecognized
          Warning: .drectve `-exclude-symbols:_ZN9hashbrown3raw4sse25Group10match_byte17h4eae4788174ea010E ' unrecognized
          Warning: corrupt .drectve at end of def file
          Warning: corrupt .drectve at end of def file
          Warning: corrupt .drectve at end of def file

my cargo.toml file is this:

[package]
name = "quickstart_2"
version = "0.1.0"
edition = "2021"

[dependencies]

[dev-dependencies]
cucumber = "0.20"
futures = "0.3"

[[test]]
name = "example"
harness = false

My example.rs in tests is this:

use cucumber::{given, World};

// These `Cat` definitions would normally be inside your project's code, 
// not test code, but we create them here for the show case.
#[derive(Debug, Default)]
struct Cat {
    pub hungry: bool,
}

impl Cat {
    fn feed(&mut self) {
        self.hungry = false;
    }
}

// `World` is your shared, likely mutable state.
// Cucumber constructs it via `Default::default()` for each scenario. 
#[derive(Debug, Default, World)]
pub struct AnimalWorld {
    cat: Cat,
}

// Steps are defined with `given`, `when` and `then` attributes.
#[given("a hungry cat")]
fn hungry_cat(world: &mut AnimalWorld) {
    world.cat.hungry = true;
}

// This runs before everything else, so you can setup things here.
fn main() {
    // You may choose any executor you like (`tokio`, `async-std`, etc.).
    // You may even have an `async` main, it doesn't matter. The point is that
    // Cucumber is composable. :)
    futures::executor::block_on(AnimalWorld::run("tests/features/book"));
}

and my file structure is: src main.rs tests features book animal.feature cargo.toml cargo.lock

Not sure whats going on and how to fix. Can someone help me?

Earthworn commented 9 months ago

I fixed it. For anyone having the same issue: Just reinstall rust.

Still would be glad if someone could explain what my problem was.

tyranron commented 9 months ago

@Earthworn glad you've resolved this. Running cargo test --test example is the correct way.

When i call cargo test -p cucumber --test example it fails instantly with: (error: package cucumber cannot be tested because it requires dev-dependencies and is not a member of the workspace)

This is because it was meant to run from this repo root (after doing git clone https://github.com/cucumber-rs/cucumber).

I think I should strip that -p cucumber in the Book, because it definitely confuses newbies, not familiar with Rust tooling. Thanks for pointing that out.

I also tried cargo test --test example then it does start to compile but fails with: could not compile quickstart_2 (test "example") due to previous error; 1 warning emitted Here is an extract of the warning:

          Warning: .drectve `-exclude-symbols:_ZN4core3ops8function6FnOnce9call_once17h718365105d8c95cbE ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr257drop_in_place$LT$hashbrown..raw..RawTable$LT$$LP$$RF$str$C$$LP$$RP$$RP$$GT$..reserve_rehash$LT$hashbrown..map..make_hasher$LT$$RF$str$C$$LP$$RP$$C$std..collections..hash..map..RandomState$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he7df083f920ee42dE" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr26drop_in_place$LT$usize$GT$17h8a0c2301359c414aE" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr30drop_in_place$LT$$RF$usize$GT$17h5544a261123022e1E" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr32drop_in_place$LT$$RF$$RF$str$GT$17ha965fb47bd2bf802E" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr365drop_in_place$LT$hashbrown..raw..RawTable$LT$$LP$$RF$str$C$$LP$$RP$$RP$$GT$..find_or_find_insert_slot$LT$hashbrown..map..equivalent_key$LT$$RF$str$C$$RF$str$C$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$C$hashbrown..map..make_hasher$LT$$RF$str$C$$LP$$RP$$C$std..collections..hash..map..RandomState$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17h949f7561e009f6bbE" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr47drop_in_place$LT$$LP$$RF$str$C$$LP$$RP$$RP$$GT$17hebf4139d97db4920E" ' unrecognized     
          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr52drop_in_place$LT$std..thread..local..AccessError$GT$17hb86a08c2686349d6E" ' unrecognized          Warning: .drectve `-exclude-symbols:"_ZN4core3ptr76drop_in_place$LT$$RF$std..collections..hash..set..HashSet$LT$$RF$str$GT$$GT$17h30baf595195e3006E" ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN4core4char7methods22_$LT$impl$u20$char$GT$8len_utf817h15fef8e0022228b2E" ' unrecognized
          Warning: .drectve `-exclude-symbols:_ZN4core5alloc6layout6Layout5array5inner17h97939f616f56a5faE ' unrecognized
          Warning: .drectve `-exclude-symbols:"_ZN81_$LT$core..str..iter..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17ha5040fb0292b72dfE" ' unrecognized
          Warning: .drectve `-exclude-symbols:_ZN9hashbrown3raw4sse25Group10match_byte17h4eae4788174ea010E ' unrecognized
          Warning: corrupt .drectve at end of def file
          Warning: corrupt .drectve at end of def file
          Warning: corrupt .drectve at end of def file

Regarding this... it's the issue with Rust toolchain on Windows, which I'm not familiar with. This, however, steps out of scope of this repo. I'm glad that "just reboot/reinstall" trick worked for you.

tyranron commented 9 months ago

I think I should strip that -p cucumber in the Book, because it definitely confuses newbies, not familiar with Rust tooling. Thanks for pointing that out.

Actually, I couldn't find such command anywhere in the Book or in the docs. Could you point where exactly you got it from?

UPD: Oh... it's on the generated images, because they are recorded from running in this repo.

tyranron commented 9 months ago

@Earthworn edge Book now contains renewed GIFs (you may need hard reload pages to see them).

Earthworn commented 9 months ago

Hi, thank you for the clarification. Yeah i m obivousliy a newbie and look for a way to run the test.