Skip to content

Commit 98ab277

Browse files
committed
test(env): Fix test_gnu_e20 for coverage run
1 parent 4758490 commit 98ab277

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

tests/by-util/test_env.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,22 @@ fn test_split_string_into_args_debug_output_whitespace_handling() {
477477
fn test_gnu_e20() {
478478
let env_bin = String::from(crate::common::util::TESTS_BINARY) + " " + util_name!();
479479

480-
let (input, output) = (
481-
[
482-
String::from("-i"),
483-
String::from(r#"-SA="B\_C=D" "#) + env_bin.escape_default().to_string().as_str() + "",
484-
],
485-
"A=B C=D\n",
486-
);
480+
let input = [
481+
String::from("-i"),
482+
String::from(r#"-SA="B\_C=D" "#) + env_bin.escape_default().to_string().as_str() + "",
483+
];
484+
485+
let mut output = "A=B C=D\n".to_string();
486+
487+
// Workaround for the test to pass when coverage is being run.
488+
// If enabled, the binary called by env_bin will most probably be
489+
// instrumented for coverage, and thus will set the
490+
// __LLVM_PROFILE_RT_INIT_ONCE
491+
if env::var("__LLVM_PROFILE_RT_INIT_ONCE").is_ok() {
492+
output.push_str("__LLVM_PROFILE_RT_INIT_ONCE=__LLVM_PROFILE_RT_INIT_ONCE\n");
493+
}
487494

488-
let out = new_ucmd!().args(&input).succeeds();
489-
assert_eq!(out.stdout_str(), output);
495+
new_ucmd!().args(&input).succeeds().stdout_is(output);
490496
}
491497

492498
#[test]

0 commit comments

Comments
 (0)