Skip to content

Commit 208fa8e

Browse files
committed
id: Simplify testing different UID and EUID
1 parent a498a27 commit 208fa8e

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

tests/by-util/test_id.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -479,24 +479,14 @@ fn test_id_pretty_print_password_record() {
479479
.stderr_contains("the argument '-p' cannot be used with '-P'");
480480
}
481481

482-
enum CompilationResult {
483-
CompilerNotInstalled,
484-
Error,
485-
Success,
486-
}
487-
488-
fn compile_preload_file_with_gcc(c_file: &str, so_file: &str) -> CompilationResult {
489-
let result = std::process::Command::new("gcc")
482+
fn compile_preload_file_with_gcc(
483+
c_file: &str,
484+
so_file: &str,
485+
) -> Result<std::process::ExitStatus, String> {
486+
Ok(std::process::Command::new("gcc")
490487
.args(["-fPIC", "-shared", "-o", &so_file, &c_file])
491-
.status();
492-
493-
match result {
494-
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
495-
CompilationResult::CompilerNotInstalled
496-
}
497-
Ok(status) if status.success() => CompilationResult::Success,
498-
_ => CompilationResult::Error,
499-
}
488+
.status()
489+
.map_err(|_| "`gcc` is not installed")?)
500490
}
501491

502492
#[test]
@@ -508,14 +498,9 @@ fn test_id_different_uid_and_euid() {
508498
// The UID should be 1000, whereas the EUID should be 0.
509499
let c_file = at.as_string() + "/different_uid_and_euid.c";
510500
let so_file = at.as_string() + "/different_uid_and_euid.so";
511-
let compilation_result = compile_preload_file_with_gcc(&c_file, &so_file);
512-
match compilation_result {
513-
CompilationResult::CompilerNotInstalled => {
514-
println!("test skipped: `gcc` compiler is not installed");
515-
return;
516-
}
517-
CompilationResult::Error => panic!("Preload file compilation failed"),
518-
CompilationResult::Success => {}
501+
let status = unwrap_or_return!(compile_preload_file_with_gcc(&c_file, &so_file));
502+
if !status.success() {
503+
panic!("Preload file compilation failed")
519504
}
520505

521506
let result = ucmd.env("LD_PRELOAD", so_file).run();

0 commit comments

Comments
 (0)