rustc-ap-rustc_target 727.0.0

Automatically published version of the package `rustc_target` in the rust-lang/rust repository from commit 9a27044f42ace9eb652781b53f598e25d4e7e918 The publishing script for this crate lives at: https://github.com/alexcrichton/rustc-auto-publish
use crate::spec::Target;
use rustc_serialize::json::Json;
use std::str::FromStr;

#[test]
fn report_unused_fields() {
    let json = 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 = 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 = 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);
}