Skip to content

Commit

Permalink
add info to rust-ldd tests failures
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed May 24, 2024
1 parent 4e82ed5 commit f18cb8a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
12 changes: 7 additions & 5 deletions tests/run-make/rust-lld-by-default/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ fn main() {
.input("main.rs")
.run();
assert!(
find_lld_version_in_logs(output),
"the LLD version string should be present in the output logs"
find_lld_version_in_logs(&output),
"the LLD version string should be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);

// But it can still be disabled by turning the linker feature off.
Expand All @@ -31,12 +32,13 @@ fn main() {
.input("main.rs")
.run();
assert!(
!find_lld_version_in_logs(output),
"the LLD version string should not be present in the output logs"
!find_lld_version_in_logs(&output),
"the LLD version string should not be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);
}

fn find_lld_version_in_logs(output: Output) -> bool {
fn find_lld_version_in_logs(output: &Output) -> bool {
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
let stderr = std::str::from_utf8(&output.stderr).unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line))
Expand Down
12 changes: 7 additions & 5 deletions tests/run-make/rust-lld-custom-target/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ fn main() {
.input("lib.rs")
.run();
assert!(
find_lld_version_in_logs(output),
"the LLD version string should be present in the output logs"
find_lld_version_in_logs(&output),
"the LLD version string should be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);

// But it can also be disabled via linker features.
Expand All @@ -37,12 +38,13 @@ fn main() {
.input("lib.rs")
.run();
assert!(
!find_lld_version_in_logs(output),
"the LLD version string should not be present in the output logs"
!find_lld_version_in_logs(&output),
"the LLD version string should not be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);
}

fn find_lld_version_in_logs(output: Output) -> bool {
fn find_lld_version_in_logs(output: &Output) -> bool {
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
let stderr = std::str::from_utf8(&output.stderr).unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line))
Expand Down
17 changes: 10 additions & 7 deletions tests/run-make/rust-lld/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ fn main() {
.input("main.rs")
.run();
assert!(
find_lld_version_in_logs(output),
"the LLD version string should be present in the output logs"
find_lld_version_in_logs(&output),
"the LLD version string should be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);

// It should not be used when we explictly opt-out of lld.
Expand All @@ -33,8 +34,9 @@ fn main() {
.input("main.rs")
.run();
assert!(
!find_lld_version_in_logs(output),
"the LLD version string should not be present in the output logs"
!find_lld_version_in_logs(&output),
"the LLD version string should not be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);

// While we're here, also check that the last linker feature flag "wins" when passed multiple
Expand All @@ -50,12 +52,13 @@ fn main() {
.input("main.rs")
.run();
assert!(
find_lld_version_in_logs(output),
"the LLD version string should be present in the output logs"
find_lld_version_in_logs(&output),
"the LLD version string should be present in the output logs:\n{}",
std::str::from_utf8(&output.stderr).unwrap()
);
}

fn find_lld_version_in_logs(output: Output) -> bool {
fn find_lld_version_in_logs(output: &Output) -> bool {
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
let stderr = std::str::from_utf8(&output.stderr).unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line))
Expand Down

0 comments on commit f18cb8a

Please sign in to comment.