-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Don't use process::exit
in bootstrap tests
#98830
Comments
I don't think unique exit codes are a good idea -- too much hassle; we should probably replace the exit's with a call to something like crate::exit which can panic! in cfg(test) and resume_unwind in regular code; the goal of the exits is really just to more cleanly exit than the big panic message you get otherwise. |
process::exit
in bootstrap tests
@rustbot claim |
Thank you for mentering! // exit.rs
fn detail_exit(message:String){
if (test) {
panic!(message)
} else (not test) {
resume_unwind(Box::new(message))
}
} Is this understanding correct or incorrect? |
@kons-9 exit is fine to keep using when we're not running tests. Otherwise that looks broadly correct. The magic built-in to replace I would put this in lib.rs or utils.rs, no need to add a new file just for one function. |
Ah, I missed that Mark suggested resume_unwind earlier - ok, that's fine to use, it will make sure tempfiles are deleted and that sort of thing. |
Thank you for your reply!
Copy that! I am going to use #[cfg(test)] in that code, but would cfg!(test) be better? (you might have suggested this macro because of my code. ) |
@kons-9 I think |
replace process exit with more detailed exit in src/bootstrap/*.rs Fixes [rust-lang#98830](rust-lang#98830) I implemeted "detail_exit.rs" in lib.rs, and replace all of std::process::exit. So, error code should panic in test code. ``` // lib.rs pub fn detail_exit(code: i32) -> ! { // Successful exit if code == 0 { std::process::exit(0); } if cfg!(test) { panic!("status code: {}", code); } else { std::panic::resume_unwind(Box::new(code)); } } ``` <details> <summary>% rg "exit\(" src/bootstrap/*.rs</summary> ``` builder.rs 351: crate::detail_exit(1); 1000: crate::detail_exit(1); 1429: crate::detail_exit(1); compile.rs 1331: crate::detail_exit(1); config.rs 818: crate::detail_exit(2); 1488: crate::detail_exit(1); flags.rs 263: crate::detail_exit(exit_code); 349: crate::detail_exit(exit_code); 381: crate::detail_exit(1); 602: crate::detail_exit(1); 616: crate::detail_exit(1); 807: crate::detail_exit(1); format.rs 35: crate::detail_exit(1); 117: crate::detail_exit(1); lib.rs 714: detail_exit(1); 1620: detail_exit(1); 1651:pub fn detail_exit(code: i32) -> ! { 1654: std::process::exit(0); sanity.rs 107: crate::detail_exit(1); setup.rs 97: crate::detail_exit(1); 290: crate::detail_exit(1); test.rs 676: crate::detail_exit(1); 1024: crate::detail_exit(1); 1254: crate::detail_exit(1); tool.rs 207: crate::detail_exit(1); toolstate.rs 96: crate::detail_exit(3); 111: crate::detail_exit(1); 182: crate::detail_exit(1); 228: crate::detail_exit(1); util.rs 339: crate::detail_exit(1); 378: crate::detail_exit(1); 468: crate::detail_exit(1); ``` </details>
Bootstrap has a lot of places where it calls process::exit. This makes it hard to figure out why tests fail. We should use unique exit codes so it's easier to tell where something wrong (and maybe consider using resume_unwind instead? not sure).
The text was updated successfully, but these errors were encountered: