Move profile override tests to a dedicated file.
authorEric Huss <eric@huss.org>
Sat, 21 Apr 2018 20:47:01 +0000 (13:47 -0700)
committerEric Huss <eric@huss.org>
Fri, 27 Apr 2018 20:42:30 +0000 (13:42 -0700)
tests/testsuite/main.rs
tests/testsuite/profile_overrides.rs [new file with mode: 0644]
tests/testsuite/profiles.rs

index e1d3181cd082837fc044f8006e8d8037aa10da5e..51b8ae584689becf7257e3f6c4ff8e741b3270cb 100644 (file)
@@ -70,6 +70,7 @@ mod path;
 mod plugins;
 mod proc_macro;
 mod profiles;
+mod profile_overrides;
 mod publish;
 mod read_manifest;
 mod registry;
diff --git a/tests/testsuite/profile_overrides.rs b/tests/testsuite/profile_overrides.rs
new file mode 100644 (file)
index 0000000..458e9e0
--- /dev/null
@@ -0,0 +1,234 @@
+use cargotest::support::{basic_lib_manifest, execs, project};
+use cargotest::ChannelChanger;
+use hamcrest::assert_that;
+
+#[test]
+fn profile_override_gated() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [profile.dev.build-override]
+            opt-level = 3
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build").masquerade_as_nightly_cargo(),
+        execs().with_status(101).with_stderr(
+            "\
+error: failed to parse manifest at `[..]`
+
+Caused by:
+  feature `profile-overrides` is required
+
+consider adding `cargo-features = [\"profile-overrides\"]` to the manifest
+",
+        ),
+    );
+
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [profile.dev.overrides."*"]
+            opt-level = 3
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build").masquerade_as_nightly_cargo(),
+        execs().with_status(101).with_stderr(
+            "\
+error: failed to parse manifest at `[..]`
+
+Caused by:
+  feature `profile-overrides` is required
+
+consider adding `cargo-features = [\"profile-overrides\"]` to the manifest
+",
+        ),
+    );
+}
+
+#[test]
+fn profile_override_basic() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            cargo-features = ["profile-overrides"]
+
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            bar = {path = "bar"}
+
+            [profile.dev]
+            opt-level = 1
+
+            [profile.dev.overrides.bar]
+            opt-level = 3
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
+        .file("bar/src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build -v").masquerade_as_nightly_cargo(),
+        execs().with_status(0).with_stderr(
+            "[COMPILING] bar [..]
+[RUNNING] `rustc --crate-name bar [..] -C opt-level=3 [..]`
+[COMPILING] foo [..]
+[RUNNING] `rustc --crate-name foo [..] -C opt-level=1 [..]`
+[FINISHED] dev [optimized + debuginfo] target(s) in [..]",
+        ),
+    );
+}
+
+#[test]
+fn profile_override_bad_name() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            cargo-features = ["profile-overrides"]
+
+            [package]
+            name = "foo"
+            version = "0.0.1"
+
+            [dependencies]
+            bar = {path = "bar"}
+
+            [profile.dev.overrides.bart]
+            opt-level = 3
+
+            [profile.dev.overrides.no-suggestion]
+            opt-level = 3
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
+        .file("bar/src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build").masquerade_as_nightly_cargo(),
+        execs().with_status(0).with_stderr_contains(
+            "\
+[WARNING] package `bart` for profile override not found
+
+Did you mean `bar`?
+[WARNING] package `no-suggestion` for profile override not found
+[COMPILING] [..]
+",
+        ),
+    );
+}
+
+#[test]
+fn profile_override_dev_release_only() {
+    let p = project("foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            cargo-features = ["profile-overrides"]
+
+            [package]
+            name = "foo"
+            version = "0.0.1"
+
+            [dependencies]
+            bar = {path = "bar"}
+
+            [profile.test.overrides.bar]
+            opt-level = 3
+        "#,
+        )
+        .file("src/lib.rs", "")
+        .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
+        .file("bar/src/lib.rs", "")
+        .build();
+
+    assert_that(
+        p.cargo("build").masquerade_as_nightly_cargo(),
+        execs().with_status(101).with_stderr_contains(
+            "\
+Caused by:
+  Profile overrides may only be specified for `dev` or `release` profile, not `test`.
+",
+        ),
+    );
+}
+
+#[test]
+fn profile_override_bad_settings() {
+    let bad_values = [
+        (
+            "panic = \"abort\"",
+            "`panic` may not be specified in a profile override.",
+        ),
+        (
+            "lto = true",
+            "`lto` may not be specified in a profile override.",
+        ),
+        (
+            "rpath = true",
+            "`rpath` may not be specified in a profile override.",
+        ),
+        ("overrides = {}", "Profile overrides cannot be nested."),
+    ];
+    for &(ref snippet, ref expected) in bad_values.iter() {
+        let p = project("foo")
+            .file(
+                "Cargo.toml",
+                &format!(
+                    r#"
+                cargo-features = ["profile-overrides"]
+
+                [package]
+                name = "foo"
+                version = "0.0.1"
+
+                [dependencies]
+                bar = {{path = "bar"}}
+
+                [profile.dev.overrides.bar]
+                {}
+            "#,
+                    snippet
+                ),
+            )
+            .file("src/lib.rs", "")
+            .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
+            .file("bar/src/lib.rs", "")
+            .build();
+
+        assert_that(
+            p.cargo("build").masquerade_as_nightly_cargo(),
+            execs()
+                .with_status(101)
+                .with_stderr_contains(format!("Caused by:\n  {}", expected)),
+        );
+    }
+}
index 00f1340ee1a87beefe08d6b723961f754f969d1a..8d1478ced245f2afeeac726c0354976a94b81d41 100644 (file)
@@ -1,8 +1,7 @@
 use std::env;
 
 use cargotest::is_nightly;
-use cargotest::support::{basic_lib_manifest, execs, project};
-use cargotest::ChannelChanger;
+use cargotest::support::{execs, project};
 use hamcrest::assert_that;
 
 #[test]
@@ -342,150 +341,6 @@ fn profile_in_virtual_manifest_works() {
     );
 }
 
-#[test]
-fn profile_override_gated() {
-    let p = project("foo")
-        .file(
-            "Cargo.toml",
-            r#"
-            [package]
-            name = "foo"
-            version = "0.0.1"
-            authors = []
-
-            [profile.dev.build-override]
-            opt-level = 3
-        "#,
-        )
-        .file("src/lib.rs", "")
-        .build();
-
-    assert_that(
-        p.cargo("build").masquerade_as_nightly_cargo(),
-        execs().with_status(101).with_stderr(
-            "\
-error: failed to parse manifest at `[..]`
-
-Caused by:
-  feature `profile-overrides` is required
-
-consider adding `cargo-features = [\"profile-overrides\"]` to the manifest
-",
-        ),
-    );
-
-    let p = project("foo")
-        .file(
-            "Cargo.toml",
-            r#"
-            [package]
-            name = "foo"
-            version = "0.0.1"
-            authors = []
-
-            [profile.dev.overrides."*"]
-            opt-level = 3
-        "#,
-        )
-        .file("src/lib.rs", "")
-        .build();
-
-    assert_that(
-        p.cargo("build").masquerade_as_nightly_cargo(),
-        execs().with_status(101).with_stderr(
-            "\
-error: failed to parse manifest at `[..]`
-
-Caused by:
-  feature `profile-overrides` is required
-
-consider adding `cargo-features = [\"profile-overrides\"]` to the manifest
-",
-        ),
-    );
-}
-
-#[test]
-fn profile_override_basic() {
-    let p = project("foo")
-        .file(
-            "Cargo.toml",
-            r#"
-            cargo-features = ["profile-overrides"]
-
-            [package]
-            name = "foo"
-            version = "0.0.1"
-            authors = []
-
-            [dependencies]
-            bar = {path = "bar"}
-
-            [profile.dev]
-            opt-level = 1
-
-            [profile.dev.overrides.bar]
-            opt-level = 3
-        "#,
-        )
-        .file("src/lib.rs", "")
-        .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
-        .file("bar/src/lib.rs", "")
-        .build();
-
-    assert_that(
-        p.cargo("build -v").masquerade_as_nightly_cargo(),
-        execs().with_status(0).with_stderr(
-            "[COMPILING] bar [..]
-[RUNNING] `rustc --crate-name bar [..] -C opt-level=3 [..]`
-[COMPILING] foo [..]
-[RUNNING] `rustc --crate-name foo [..] -C opt-level=1 [..]`
-[FINISHED] dev [optimized + debuginfo] target(s) in [..]",
-        ),
-    );
-}
-
-#[test]
-fn profile_override_bad_name() {
-    let p = project("foo")
-        .file(
-            "Cargo.toml",
-            r#"
-            cargo-features = ["profile-overrides"]
-
-            [package]
-            name = "foo"
-            version = "0.0.1"
-
-            [dependencies]
-            bar = {path = "bar"}
-
-            [profile.dev.overrides.bart]
-            opt-level = 3
-
-            [profile.dev.overrides.no-suggestion]
-            opt-level = 3
-        "#,
-        )
-        .file("src/lib.rs", "")
-        .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
-        .file("bar/src/lib.rs", "")
-        .build();
-
-    assert_that(
-        p.cargo("build").masquerade_as_nightly_cargo(),
-        execs().with_status(0).with_stderr_contains(
-            "\
-[WARNING] package `bart` for profile override not found
-
-Did you mean `bar`?
-[WARNING] package `no-suggestion` for profile override not found
-[COMPILING] [..]
-",
-        ),
-    );
-}
-
 #[test]
 fn profile_panic_test_bench() {
     let p = project("foo")
@@ -516,90 +371,3 @@ fn profile_panic_test_bench() {
         ),
     );
 }
-
-#[test]
-fn profile_override_dev_release_only() {
-    let p = project("foo")
-        .file(
-            "Cargo.toml",
-            r#"
-            cargo-features = ["profile-overrides"]
-
-            [package]
-            name = "foo"
-            version = "0.0.1"
-
-            [dependencies]
-            bar = {path = "bar"}
-
-            [profile.test.overrides.bar]
-            opt-level = 3
-        "#,
-        )
-        .file("src/lib.rs", "")
-        .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
-        .file("bar/src/lib.rs", "")
-        .build();
-
-    assert_that(
-        p.cargo("build").masquerade_as_nightly_cargo(),
-        execs().with_status(101).with_stderr_contains(
-            "\
-Caused by:
-  Profile overrides may only be specified for `dev` or `release` profile, not `test`.
-",
-        ),
-    );
-}
-
-#[test]
-fn profile_override_bad_settings() {
-    let bad_values = [
-        (
-            "panic = \"abort\"",
-            "`panic` may not be specified in a profile override.",
-        ),
-        (
-            "lto = true",
-            "`lto` may not be specified in a profile override.",
-        ),
-        (
-            "rpath = true",
-            "`rpath` may not be specified in a profile override.",
-        ),
-        ("overrides = {}", "Profile overrides cannot be nested."),
-    ];
-    for &(ref snippet, ref expected) in bad_values.iter() {
-        let p = project("foo")
-            .file(
-                "Cargo.toml",
-                &format!(
-                    r#"
-                cargo-features = ["profile-overrides"]
-
-                [package]
-                name = "foo"
-                version = "0.0.1"
-
-                [dependencies]
-                bar = {{path = "bar"}}
-
-                [profile.dev.overrides.bar]
-                {}
-            "#,
-                    snippet
-                ),
-            )
-            .file("src/lib.rs", "")
-            .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
-            .file("bar/src/lib.rs", "")
-            .build();
-
-        assert_that(
-            p.cargo("build").masquerade_as_nightly_cargo(),
-            execs()
-                .with_status(101)
-                .with_stderr_contains(format!("Caused by:\n  {}", expected)),
-        );
-    }
-}