rust-cli / anstyle

ANSI text styling
https://docs.rs/anstyle
Other
120 stars 19 forks source link

test state::codegen::table fails #110

Closed jcajka closed 1 year ago

jcajka commented 1 year ago

test state::codegen::table fails when cargo tests is run. This happens on main, v1.0.1 and v1.0.0 not tested on older releases.

$ git clone https://github.com/rust-cli/anstyle
$ pushd anstyle
$ cargo test
.
.
.
running 3 tests
test state::definitions::tests::pack_state_action ... ok
test state::definitions::tests::unpack_state_action ... ok
test state::codegen::table ... FAILED

failures:

---- state::codegen::table stdout ----
thread 'state::codegen::table' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', crates/anstyle-parse/src/state/codegen.rs:11:54
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    state::codegen::table

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

This is on Fedora with rust-1.71.0, gcc-13.1.1 and binutils-2.39

epage commented 1 year ago

I'm on rust 1.71.0 on Ubuntu and I'm not able to reproduce this. Neither is CI.

cargo test should be setting the CWD to crates/anstyle-parse/ for running tests which then makes ./src/state/table.rs accessible`.

jcajka commented 1 year ago

Interesting, I have been trying this in various clean Fedora container envs across all arches with same results regardless of if executed via workspace or directly in the anstyle-parse. All other tests passes, I will reach out to he Fedora Rust folks, if they have any ideas.

jcajka commented 1 year ago

Reported to Fedora folks via https://bugzilla.redhat.com/show_bug.cgi?id=2229663

cuviper commented 1 year ago

I can reproduce this in a clean container, and the "not found" is coming from codegenrs::rustfmt when it tries to spawn that command. After dnf install rustfmt, it works for me.

epage commented 1 year ago

Improved the error message so it should be more discoverable (haven't updated the Cargo.lock to reflect that yet)

jcajka commented 1 year ago

@cuviper @epage Thank you for quick replies and help. It works for me now. For the record rustfmt in Fedora should most probably by version dependent on the rust, with mismatched versions(1.71.0 for rustfmt and 1.70 for rust) it fails in this way.

     Running unittests src/lib.rs (target/debug/deps/anstyle_parse-955adce0aca35b06)

running 3 tests
test state::definitions::tests::pack_state_action ... ok
test state::definitions::tests::unpack_state_action ... ok
rustfmt: error while loading shared libraries: librustc_driver-01757800555a7cc0.so: cannot open shared object file: No such file or directory
test state::codegen::table ... FAILED

failures:

---- state::codegen::table stdout ----
thread 'state::codegen::table' panicked at '
---- expected: ./src/state/table.rs
++++ actual:   In-memory
... long diff omitted...
Update with SNAPSHOTS=overwrite', crates/anstyle-parse/src/state/codegen.rs:12:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    state::codegen::table

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

One naive question do you know if there is some way to specify external dependencies, like file/cmd exists on the PATH, .so/.a file, pkgconfig library, etc. in the Cargo file? It seems to me that it could help in cases like this. Does it make sense?

epage commented 1 year ago

In a Cargo.toml? Not at this time. The closest is the rustup toolchain file which I'd rather not use in my projects.

I assume this is a problem for other projects like rust-analyzer which, from what I remember, run rustfmt --check in CI on the whole project.