From ece3ce60fbe5e7e6f31c69fd462d1b37521b0dc8 Mon Sep 17 00:00:00 2001 From: quake Date: Tue, 6 Oct 2020 15:44:39 +0900 Subject: [PATCH] test: remove hardcoded CommandLineTools path in macos test --- tests/compare_dyldinfos.rs | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/tests/compare_dyldinfos.rs b/tests/compare_dyldinfos.rs index 0c9dcaf0a..f5bce7f7a 100644 --- a/tests/compare_dyldinfos.rs +++ b/tests/compare_dyldinfos.rs @@ -1,7 +1,17 @@ use std::process; +fn get_realpath(cmd: &str) -> String { + let output = process::Command::new("/usr/bin/xcrun") + .arg("-f") + .arg(cmd) + .output() + .expect("can get realpath"); + String::from_utf8(output.stdout).expect("output is valid utf8") +} + pub fn compare(args: Vec<&str>) { - let apple = process::Command::new("/Library/Developer/CommandLineTools/usr/bin/dyldinfo") + let apple = process::Command::new("/usr/bin/xcrun") + .arg("dyldinfo") .args(&args) .output() .expect("run Apple dyldinfo"); @@ -39,39 +49,28 @@ pub fn compare(args: Vec<&str>) { #[cfg(target_os = "macos")] #[test] fn compare_binds() { - compare(vec![ - "-bind", - "/Library/Developer/CommandLineTools/usr/bin/dyldinfo", - ]); - compare(vec![ - "-bind", - "/Library/Developer/CommandLineTools/usr/bin/clang", - ]); + let dyldinfo = get_realpath("dyldinfo"); + let clang = get_realpath("clang"); + compare(vec!["-bind", &dyldinfo]); + compare(vec!["-bind", &clang]); compare(vec!["-bind", "/usr/bin/tmutil"]); } #[cfg(target_os = "macos")] #[test] fn compare_lazy_binds() { - compare(vec![ - "-lazy_bind", - "/Library/Developer/CommandLineTools/usr/bin/dyldinfo", - ]); - compare(vec![ - "-lazy_bind", - "/Library/Developer/CommandLineTools/usr/bin/clang", - ]); + let dyldinfo = get_realpath("dyldinfo"); + let clang = get_realpath("clang"); + compare(vec!["-lazy_bind", &dyldinfo]); + compare(vec!["-lazy_bind", &clang]); compare(vec!["-lazy_bind", "/usr/bin/tmutil"]); } #[cfg(target_os = "macos")] #[test] fn compare_combined_options() { - compare(vec![ - "-lazy_bind", - "-bind", - "/Library/Developer/CommandLineTools/usr/bin/dyldinfo", - ]); + let dyldinfo = get_realpath("dyldinfo"); + compare(vec!["-lazy_bind", "-bind", &dyldinfo]); } #[cfg(not(target_os = "macos"))]