Add custom target tests
authorPhilipp Oppermann <dev@phil-opp.com>
Sat, 24 Mar 2018 20:38:48 +0000 (21:38 +0100)
committerPhilipp Oppermann <dev@phil-opp.com>
Sun, 25 Mar 2018 10:53:22 +0000 (12:53 +0200)
tests/testsuite/custom_target.rs [new file with mode: 0644]
tests/testsuite/main.rs

diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs
new file mode 100644 (file)
index 0000000..86f5b95
--- /dev/null
@@ -0,0 +1,170 @@
+use cargotest::is_nightly;
+use cargotest::support::{execs, project};
+use hamcrest::assert_that;
+
+#[test]
+fn custom_target_minimal() {
+    if !is_nightly() {
+        return;
+    }
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+
+            name = "foo"
+            version = "0.0.1"
+            authors = ["author@example.com"]
+        "#,
+        )
+        .file(
+            "src/lib.rs",
+            r#"
+            #![feature(no_core)]
+            #![feature(lang_items)]
+            #![no_core]
+
+            pub fn foo() -> u32 {
+                42
+            }
+
+            #[lang = "sized"]
+            pub trait Sized {
+                // Empty.
+            }
+            #[lang = "copy"]
+            pub trait Copy {
+                // Empty.
+            }
+        "#,
+        )
+        .file(
+            "custom-target.json",
+            r#"
+            {
+                "llvm-target": "x86_64-unknown-none-gnu",
+                "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
+                "arch": "x86_64",
+                "target-endian": "little",
+                "target-pointer-width": "64",
+                "target-c-int-width": "32",
+                "os": "none",
+                "linker-flavor": "ld.lld"
+            }
+        "#,
+        )
+        .build();
+
+    assert_that(
+        p.cargo("build")
+            .arg("--lib")
+            .arg("--target")
+            .arg("custom-target.json")
+            .arg("-v"),
+        execs().with_status(0),
+    );
+    assert_that(
+        p.cargo("build")
+            .arg("--lib")
+            .arg("--target")
+            .arg("src/../custom-target.json")
+            .arg("-v"),
+        execs().with_status(0),
+    );
+}
+
+#[test]
+fn custom_target_dependency() {
+    if !is_nightly() {
+        return;
+    }
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+
+            name = "foo"
+            version = "0.0.1"
+            authors = ["author@example.com"]
+
+            [dependencies]
+            bar = { path = "bar" }
+        "#,
+        )
+        .file(
+            "src/lib.rs",
+            r#"
+            #![feature(no_core)]
+            #![feature(lang_items)]
+            #![feature(optin_builtin_traits)]
+            #![no_core]
+
+            extern crate bar;
+
+            pub fn foo() -> u32 {
+                bar::bar()
+            }
+
+            #[lang = "freeze"]
+            unsafe auto trait Freeze {}
+        "#,
+        )
+        .file(
+            "bar/Cargo.toml",
+            r#"
+            [package]
+
+            name = "bar"
+            version = "0.0.1"
+            authors = ["author@example.com"]
+        "#,
+        )
+        .file(
+            "bar/src/lib.rs",
+            r#"
+            #![feature(no_core)]
+            #![feature(lang_items)]
+            #![no_core]
+
+            pub fn bar() -> u32 {
+                42
+            }
+
+            #[lang = "sized"]
+            pub trait Sized {
+                // Empty.
+            }
+            #[lang = "copy"]
+            pub trait Copy {
+                // Empty.
+            }
+        "#,
+        )
+        .file(
+            "custom-target.json",
+            r#"
+            {
+                "llvm-target": "x86_64-unknown-none-gnu",
+                "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
+                "arch": "x86_64",
+                "target-endian": "little",
+                "target-pointer-width": "64",
+                "target-c-int-width": "32",
+                "os": "none",
+                "linker-flavor": "ld.lld"
+            }
+        "#,
+        )
+        .build();
+
+    assert_that(
+        p.cargo("build")
+            .arg("--lib")
+            .arg("--target")
+            .arg("custom-target.json")
+            .arg("-v"),
+        execs().with_status(0),
+    );
+}
index bd7c32b9af0dfb5ad2f4fd5aa0c724c44dc33f4f..979afe3b720461123a29733986d0a8d0b1027a41 100644 (file)
@@ -43,6 +43,7 @@ mod config;
 mod corrupt_git;
 mod cross_compile;
 mod cross_publish;
+mod custom_target;
 mod death;
 mod dep_info;
 mod directory;