From 208fa8e7f88f29214ef99984bf47c6a9ebc2ed0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teemu=20P=C3=A4tsi?= Date: Sun, 20 Apr 2025 23:03:10 +0300 Subject: [PATCH] id: Simplify testing different UID and EUID --- tests/by-util/test_id.rs | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index b3eae9705..9dac99bce 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -479,24 +479,14 @@ fn test_id_pretty_print_password_record() { .stderr_contains("the argument '-p' cannot be used with '-P'"); } -enum CompilationResult { - CompilerNotInstalled, - Error, - Success, -} - -fn compile_preload_file_with_gcc(c_file: &str, so_file: &str) -> CompilationResult { - let result = std::process::Command::new("gcc") +fn compile_preload_file_with_gcc( + c_file: &str, + so_file: &str, +) -> Result { + Ok(std::process::Command::new("gcc") .args(["-fPIC", "-shared", "-o", &so_file, &c_file]) - .status(); - - match result { - Err(err) if err.kind() == std::io::ErrorKind::NotFound => { - CompilationResult::CompilerNotInstalled - } - Ok(status) if status.success() => CompilationResult::Success, - _ => CompilationResult::Error, - } + .status() + .map_err(|_| "`gcc` is not installed")?) } #[test] @@ -508,14 +498,9 @@ fn test_id_different_uid_and_euid() { // The UID should be 1000, whereas the EUID should be 0. let c_file = at.as_string() + "/different_uid_and_euid.c"; let so_file = at.as_string() + "/different_uid_and_euid.so"; - let compilation_result = compile_preload_file_with_gcc(&c_file, &so_file); - match compilation_result { - CompilationResult::CompilerNotInstalled => { - println!("test skipped: `gcc` compiler is not installed"); - return; - } - CompilationResult::Error => panic!("Preload file compilation failed"), - CompilationResult::Success => {} + let status = unwrap_or_return!(compile_preload_file_with_gcc(&c_file, &so_file)); + if !status.success() { + panic!("Preload file compilation failed") } let result = ucmd.env("LD_PRELOAD", so_file).run();