summaryrefslogtreecommitdiffstats
path: root/third_party/rust/goblin/tests/compare_dyldinfos.rs
blob: 8307ad6771589678b4ccc73370f7f73000805959 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::process;

pub fn compare(args: Vec<&str>) {
    let apple = process::Command::new("/Library/Developer/CommandLineTools/usr/bin/dyldinfo")
        .args(&args)
        .output()
        .expect("run Apple dyldinfo");

    let goblin = process::Command::new("cargo")
        .arg("run")
        .arg("--quiet")
        .arg("--example")
        .arg("dyldinfo")
        .arg("--")
        .args(&args)
        .output()
        .expect("run cargo dyldinfo");

    if apple.stdout.as_slice() != goblin.stdout.as_slice() {
        println!("dyldinfo calls disagree!");
        println!("Apple dyldinfo {:?} output:\n{}", &args, String::from_utf8_lossy(&apple.stdout));
        println!("---");
        println!("cargo dyldinfo {:?} output:\n{}", &args, String::from_utf8_lossy(&goblin.stdout));
        panic!("Apple dyldinfo and cargo dyldinfo differed (args: {:?})", args);
    }
}

#[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"]);
    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"]);
    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"]);
}

#[cfg(not(target_os="macos"))]
#[test]
fn skipped_on_this_platform() {
    // this test does nothing on other platforms
}