summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_target/src/tests.rs
blob: 76375170db63da637c0a41b8533aedc82d8b3703 (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
55
56
57
use crate::spec::Target;

#[test]
fn report_unused_fields() {
    let json = serde_json::from_str(
        r#"
    {
        "arch": "powerpc64",
        "data-layout": "e-m:e-i64:64-n32:64",
        "llvm-target": "powerpc64le-elf",
        "target-pointer-width": "64",
        "code-mode": "foo"
    }
    "#,
    )
    .unwrap();
    let warnings = Target::from_json(json).unwrap().1;
    assert_eq!(warnings.warning_messages().len(), 1);
    assert!(warnings.warning_messages().join("\n").contains("code-mode"));
}

#[test]
fn report_incorrect_json_type() {
    let json = serde_json::from_str(
        r#"
    {
        "arch": "powerpc64",
        "data-layout": "e-m:e-i64:64-n32:64",
        "llvm-target": "powerpc64le-elf",
        "target-pointer-width": "64",
        "link-env-remove": "foo"
    }
    "#,
    )
    .unwrap();
    let warnings = Target::from_json(json).unwrap().1;
    assert_eq!(warnings.warning_messages().len(), 1);
    assert!(warnings.warning_messages().join("\n").contains("link-env-remove"));
}

#[test]
fn no_warnings_for_valid_target() {
    let json = serde_json::from_str(
        r#"
    {
        "arch": "powerpc64",
        "data-layout": "e-m:e-i64:64-n32:64",
        "llvm-target": "powerpc64le-elf",
        "target-pointer-width": "64",
        "link-env-remove": ["foo"]
    }
    "#,
    )
    .unwrap();
    let warnings = Target::from_json(json).unwrap().1;
    assert_eq!(warnings.warning_messages().len(), 0);
}