feat(toolchain): include err in rustc_version output#4741
feat(toolchain): include err in rustc_version output#4741Bogay wants to merge 4 commits intorust-lang:mainfrom
Conversation
2ceb33c to
b8c00f3
Compare
b8c00f3 to
1ad60d1
Compare
1ad60d1 to
44ec134
Compare
| .with_stdout(snapbox::str![ | ||
| r#" | ||
| ... | ||
| compiler: (rustc does not exist: [..]) | ||
| ... | ||
| "# | ||
| ]) |
There was a problem hiding this comment.
This test failed (example job) because it the Toolchain::create_command in Toolchain::rustc_version does not return Err even rustc doesn't exist in toolchain. AFAIK it fallback to the rustc in PATH, which I believe related to #3387 . It's also hard to produce a env that don't have rustc in PATH because mock_bin use rustc to compile the binary. (If we can restrict rustup proxy to not use rustc inside PATH, I think that would be easier.)
There was a problem hiding this comment.
@Bogay Give this a try:
fs::remove_file(path.join("bin/rustc")).unwrap();
cx.config
.expect_with_env(&["rustup", "show", "active-toolchain", "--verbose"], [("PATH", ""), ("RUST_RECURSION_COUNT", "1023")])
[..]The RUST_RECURSION_COUNT is explicitly large to make sure that create_command() bails out.
OTOH if the error string spans multiple lines we might want to capture the first line only.
| .is_err(); | ||
| } | ||
|
|
||
| #[cfg(unix)] |
There was a problem hiding this comment.
I use shell script to mock the exit code of rustc in toolchain, which I think can only be executed on unix. Not sure whether it's acceptable in rustup test suite. 🤔
There was a problem hiding this comment.
Thanks for asking! Actually we have mock_bin_src.rs which you can use instead of this dirty hack. You can modify it to make the thing crash in a cross-platform and deterministic way. IIRC the rustc we call in other tests is actually this instead of the real rustc.
There was a problem hiding this comment.
Yes. In other tests mock_bin_src.rs is used for mock rustc. However, I don't know how to control args passed to rustc in this testcase. Maybe we can control the exit code using env var? But that's a new pattern which is not used in mock_bin_src.rs.
There was a problem hiding this comment.
@Bogay I do think you can try passing an env variable instead. The rustup proxy should pass the env variables down to the mock binary. Just make sure the env var is not super commonly-named to avoid side effects.
Alternatively you can compile a rust binary yourself which is independent from mock_bin_src.rs if that turns out easier for you.
This PR includes error details in
Toolchain::rustc_versionso that it's more clear to end-user what happened.Close #3607