Skip to content

Commit 66100bf

Browse files
committed
test(env): Fix test_gnu_e20 for coverage run
1 parent 61ba83a commit 66100bf

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

tests/by-util/test_env.rs

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

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

491-
let out = new_ucmd!().args(&input).succeeds();
492-
assert_eq!(out.stdout_str(), output);
498+
new_ucmd!().args(&input).succeeds().stdout_is(output);
493499
}
494500

495501
#[test]

0 commit comments

Comments
 (0)