From 5250b893a73aa9109501f32a587f6cf37ebcb4e9 Mon Sep 17 00:00:00 2001 From: Dorian Peron Date: Thu, 3 Apr 2025 15:41:54 +0200 Subject: [PATCH] test(env): fix test_gnu_e20 for coverage run --- tests/by-util/test_env.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 18b6b67c1..be9ab19cd 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -525,14 +525,20 @@ fn test_gnu_e20() { let scene = TestScenario::new(util_name!()); let env_bin = String::from(uutests::util::get_tests_binary()) + " " + util_name!(); + let input = [ + String::from("-i"), + String::from(r#"-SA="B\_C=D" "#) + env_bin.escape_default().to_string().as_str() + "", + ]; - let (input, output) = ( - [ - String::from("-i"), - String::from(r#"-SA="B\_C=D" "#) + env_bin.escape_default().to_string().as_str() + "", - ], - "A=B C=D\n", - ); + let mut output = "A=B C=D\n".to_string(); + + // Workaround for the test to pass when coverage is being run. + // If enabled, the binary called by env_bin will most probably be + // instrumented for coverage, and thus will set the + // __LLVM_PROFILE_RT_INIT_ONCE + if env::var("__LLVM_PROFILE_RT_INIT_ONCE").is_ok() { + output.push_str("__LLVM_PROFILE_RT_INIT_ONCE=__LLVM_PROFILE_RT_INIT_ONCE\n"); + } let out = scene.ucmd().args(&input).succeeds(); assert_eq!(out.stdout_str(), output);