]> git.proxmox.com Git - cargo.git/commitdiff
Tests for setting multitarget in config
authorWeihang Lo <me@weihanglo.tw>
Fri, 11 Mar 2022 17:23:18 +0000 (01:23 +0800)
committerWeihang Lo <me@weihanglo.tw>
Fri, 11 Mar 2022 17:53:59 +0000 (01:53 +0800)
tests/testsuite/multitarget.rs

index afa8ea3c9bc51128318daa4c33523226d3d8a8e5..5b4e3cff1fe6c68cd8fa9d17409768b4785fd144 100644 (file)
@@ -10,7 +10,27 @@ fn double_target_rejected() {
         .build();
 
     p.cargo("build --target a --target b")
-        .with_stderr("error: specifying multiple `--target` flags requires `-Zmultitarget`")
+        .with_stderr("[ERROR] specifying multiple `--target` flags requires `-Zmultitarget`")
+        .with_status(101)
+        .run();
+}
+
+#[cargo_test]
+fn double_target_rejected_with_config() {
+    let p = project()
+        .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
+        .file("src/main.rs", "fn main() {}")
+        .file(
+            ".cargo/config.toml",
+            r#"
+                [build]
+                target = ["a", "b"]
+            "#,
+        )
+        .build();
+
+    p.cargo("build")
+        .with_stderr("[ERROR] specifying multiple `--target` flags requires `-Zmultitarget`")
         .with_status(101)
         .run();
 }
@@ -39,6 +59,35 @@ fn simple_build() {
     assert!(p.target_bin(t2, "foo").is_file());
 }
 
+#[cargo_test]
+fn simple_build_with_config() {
+    if cross_compile::disabled() {
+        return;
+    }
+    let t1 = cross_compile::alternate();
+    let t2 = rustc_host();
+    let p = project()
+        .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
+        .file("src/main.rs", "fn main() {}")
+        .file(
+            ".cargo/config.toml",
+            &format!(
+                r#"
+                    [unstable]
+                    multitarget = true
+                    [build]
+                    target = ["{t1}", "{t2}"]
+                "#
+            ),
+        )
+        .build();
+
+    p.cargo("build").masquerade_as_nightly_cargo().run();
+
+    assert!(p.target_bin(t1, "foo").is_file());
+    assert!(p.target_bin(t2, "foo").is_file());
+}
+
 #[cargo_test]
 fn simple_test() {
     if !cross_compile::can_run_on_host() {
@@ -70,7 +119,7 @@ fn simple_run() {
         .build();
 
     p.cargo("run -Z multitarget --target a --target b")
-        .with_stderr("error: only one `--target` argument is supported")
+        .with_stderr("[ERROR] only one `--target` argument is supported")
         .with_status(101)
         .masquerade_as_nightly_cargo()
         .run();
@@ -142,3 +191,91 @@ fn same_value_twice() {
 
     assert!(p.target_bin(t, "foo").is_file());
 }
+
+#[cargo_test]
+fn same_value_twice_with_config() {
+    if cross_compile::disabled() {
+        return;
+    }
+    let t = rustc_host();
+    let p = project()
+        .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
+        .file("src/main.rs", "fn main() {}")
+        .file(
+            ".cargo/config.toml",
+            &format!(
+                r#"
+                    [unstable]
+                    multitarget = true
+                    [build]
+                    target = ["{t}", "{t}"]
+                "#
+            ),
+        )
+        .build();
+
+    p.cargo("build").masquerade_as_nightly_cargo().run();
+
+    assert!(p.target_bin(t, "foo").is_file());
+}
+
+#[cargo_test]
+fn works_with_config_in_both_string_or_list() {
+    if cross_compile::disabled() {
+        return;
+    }
+    let t = rustc_host();
+    let p = project()
+        .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
+        .file("src/main.rs", "fn main() {}")
+        .file(
+            ".cargo/config.toml",
+            &format!(
+                r#"
+                    [unstable]
+                    multitarget = true
+                    [build]
+                    target = "{t}"
+                "#
+            ),
+        )
+        .build();
+
+    p.cargo("build").masquerade_as_nightly_cargo().run();
+
+    assert!(p.target_bin(t, "foo").is_file());
+
+    p.cargo("clean").run();
+
+    p.change_file(
+        ".cargo/config.toml",
+        &format!(
+            r#"
+                [unstable]
+                multitarget = true
+                [build]
+                target = ["{t}"]
+            "#
+        ),
+    );
+
+    p.cargo("build").masquerade_as_nightly_cargo().run();
+
+    assert!(p.target_bin(t, "foo").is_file());
+}
+
+#[cargo_test]
+fn works_with_env() {
+    let t = rustc_host();
+    let p = project()
+        .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    p.cargo("build")
+        .env("CARGO_BUILD_TARGET", t)
+        .masquerade_as_nightly_cargo()
+        .run();
+
+    assert!(p.target_bin(t, "foo").is_file());
+}