Skip to content

Commit 47b2096

Browse files
committed
test(env): Fix test_gnu_e20 for coverage run
1 parent 71bd9c5 commit 47b2096

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tests/by-util/test_env.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,20 @@ fn test_gnu_e20() {
525525
let scene = TestScenario::new(util_name!());
526526

527527
let env_bin = String::from(uutests::util::get_tests_binary()) + " " + util_name!();
528-
529-
let (input, output) = (
530-
[
531-
String::from("-i"),
532-
String::from(r#"-SA="B\_C=D" "#) + env_bin.escape_default().to_string().as_str() + "",
533-
],
534-
"A=B C=D\n",
535-
);
528+
let input = [
529+
String::from("-i"),
530+
String::from(r#"-SA="B\_C=D" "#) + env_bin.escape_default().to_string().as_str() + "",
531+
];
532+
533+
let mut output = "A=B C=D\n".to_string();
534+
535+
// Workaround for the test to pass when coverage is being run.
536+
// If enabled, the binary called by env_bin will most probably be
537+
// instrumented for coverage, and thus will set the
538+
// __LLVM_PROFILE_RT_INIT_ONCE
539+
if env::var("__LLVM_PROFILE_RT_INIT_ONCE").is_ok() {
540+
output.push_str("__LLVM_PROFILE_RT_INIT_ONCE=__LLVM_PROFILE_RT_INIT_ONCE\n");
541+
}
536542

537543
let out = scene.ucmd().args(&input).succeeds();
538544
assert_eq!(out.stdout_str(), output);

0 commit comments

Comments
 (0)