bnjbvr / cargo-machete

Remove unused Rust dependencies with this one weird trick!
MIT License
799 stars 29 forks source link

Test failure for 0.7.0 on Arch Linux #140

Open orhun opened 1 month ago

orhun commented 1 month ago

Hey, I'm getting the following test failure while building the latest version for Arch Linux (in a clean chroot):

failures:

---- test_ignore_target stdout ----
thread 'test_ignore_target' panicked at src/main.rs:310:5:
assertion failed: entries.unwrap().is_empty()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    test_ignore_target

test result: FAILED. 12 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.98s

error: test failed, to rerun pass `--bin cargo-machete`

Do I need any preparation before running the tests? Any ideas about it? 🤔

As a workaround I currently --skip this test in the package.

bnjbvr commented 1 month ago

Thanks for the report. That's weird, I can't repro on my (MacOS) machine; are you using the version from a github release, or installed from cargo, or building from a specific git hash?

orhun commented 1 month ago

I'm pulling the release from GitHub (0.7.0) and building in an isolated environment. See the PKGBUILD for build steps.

Let me know if there is any other information is needed!

bnjbvr commented 1 month ago

Thanks for the details; unfortunately I can't reproduce on my machine. If anyone can reproduce and track the test failure, that would be greatly appreciated 🙏

orhun commented 1 month ago

Maybe you can tell me what that test is doing, how is it being run and why it might fail. Then I can dig into it a bit :)

bnjbvr commented 1 month ago

The test checks collect_paths, which has options to ignore target directories (first assertion), or to ignore files mentioned in ignore files (second assertion, where there's /target in ./integration-tests/with-target/target/program/.gitignore), or that when none of these is enabled, we do find some entries.

If the .gitignore file is missing from the archive you're downloading, I could see that test failing. Otherwise it's not clear why it's not failing: is the .gitignore file found? is it then not ignored, or interpreting /target as a different path than ./integration-tests/with-target/target/?

orhun commented 1 month ago

Okay I found the culprit. The downloaded archive from GitHub is not a git repository (does not contain .git folder) so I'm guessing the underlying library does not take .gitignore into account in that case.

The test passes when I rename .gitignore to .ignore 🫠

bnjbvr commented 1 month ago

Thanks for the investigation! I think we could rename .gitignore to .ignore and not lose any testing coverage, since this is testing that any kind of ignore files is taken into account. Thoughts?

orhun commented 1 month ago

Yup, sounds good to me 👍🏼