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

Make errors from make_test_list legible #1228

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

sourcefrog
Copy link
Contributor

In debugging sourcefrog/cargo-mutants#226 I found that invocations like ~/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/bin/cargo nextest run cause some test failures in the nextest tree, for reasons I'm still working to understand.

In main, those errors are printed like this, with a pile of ASCII byte values:

thread 'basic::test_termination' panicked at nextest-runner/tests/integration/fixtures.rs:383:10:
test list successfully created: CommandFail { binary_id: RustBinaryId("cdylib-example"), command: ["/home/mbp/src/nextest/fixtures/nextest-tests/target/debug/deps/cdylib_example-9222c584dde9dbd0", "--list", "--format", "terse"], exit_status: ExitStatus(unix_wait_status(32512)), stdout: [], stderr: [47, 104, 111, 109, 101, 47, 109, 98, 112, 47, 115, 114, 99, 47, 110, 101, 120, 116, 101, 115, 116, 47, 102, 105, 120, 116, 117, 114, 101, 115, 47, 110, 101, 120, 116, 101, 115, 116, 45, 116, 101, 115, 116, 115, 47, 116, 97, 114, 103, 101, 116, 47, 100, 101, 98, 117, 103, 47, 100, 101, 112, 115, 47, 99, 100, 121, 108, 105, 98, 95, 101, 120, 97, 109, 112, 108, 101, 45, 57, 50, 50, 50, 99, 53, 56, 52, 100, 100, 101, 57, 100, 98, 100, 48, 58, 32, 101, 114, 114, 111, 114, 32, 119, 104, 105, 108, 101, 32, 108, 111, 97, 100, 105, 110, 103, 32, 115, 104, 97, 114, 101, 100, 32, 108, 105, 98, 114, 97, 114, 105, 101, 115, 58, 32, 108, 105, 98, 116, 101, 115, 116, 45, 99, 98, 97, 98, 55, 49, 54, 57, 55, 100, 102, 57, 55, 98, 48, 48, 46, 115, 111, 58, 32, 99, 97, 110, 110, 111, 116, 32, 111, 112, 101, 110, 32, 115, 104, 97, 114, 101, 100, 32, 111, 98, 106, 101, 99, 116, 32, 102, 105, 108, 101, 58, 32, 78, 111, 32, 115, 117, 99, 104, 32, 102, 105, 108, 101, 32, 111, 114, 32, 100, 105, 114, 101, 99, 116, 111, 114, 121, 10] }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is because unwrap prints the Debug form and the error holds a Vec<u8>.

There could be a few ways to change this but it seemed like the intention of the existing code was to keep the exact output in the error enum as bytes, and only do lossy conversion to UTF-8 from Display. So, I looked for a way to get the Display form printed, and it seemed like a good way was to just return the error, since the tests that call this already themselves return Results.

With this applied the failures are much more helpful:

error: creating test list failed

Caused by:
  for `cdylib-example`, command `/tmp/nextest-fixtureQWK72c/src/target/debug/deps/cdylib_example-9222c584dde9dbd0 --list --format terse` exited with code 127
--- stdout:

--- stderr:
/tmp/nextest-fixtureQWK72c/src/target/debug/deps/cdylib_example-9222c584dde9dbd0: error while loading shared libraries: libtest-cbab71697df97b00.so: cannot open shared object file: No such file or directory

---

This allows any Err to be returned from the test, which in turn causes its Display (rather than Debug form) to be shown, which makes errors containing Vec<u8> much more readable.
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c44c6cd) 77.40% compared to head (bca344f) 77.39%.
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1228      +/-   ##
==========================================
- Coverage   77.40%   77.39%   -0.01%     
==========================================
  Files          72       72              
  Lines       17859    17859              
==========================================
- Hits        13823    13822       -1     
- Misses       4036     4037       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sunshowers
Copy link
Member

Thank you!

@sunshowers sunshowers merged commit cfd19f6 into nextest-rs:main Jan 16, 2024
13 checks passed
@sourcefrog sourcefrog deleted the readable-error branch January 16, 2024 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants