diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index fb1c7ddb646..399038e3813 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4379,6 +4379,98 @@ fn inferred_benchmarks() { ); } +#[test] +fn target_edition() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["edition"] + [package] + name = "foo" + version = "0.0.1" + + [lib] + edition = "2018" + "#, + ) + .file("src/lib.rs", "") + .build(); + + assert_that( + p.cargo("build").arg("-v").masquerade_as_nightly_cargo(), + execs().with_stderr_contains("\ +[COMPILING] foo v0.0.1 ([..]) +[RUNNING] `rustc [..]--edition=2018 [..] +"), + ); +} + +#[test] +fn target_edition_override() { + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["edition"] + [package] + name = "foo" + version = "0.0.1" + authors = [] + edition = "2018" + + [lib] + edition = "2015" + "#, + ) + .file("src/lib.rs", "") + .build(); + + assert_that( + p.cargo("build").arg("-v").masquerade_as_nightly_cargo(), + execs().with_stderr_contains("\ +[COMPILING] foo v0.0.1 ([..]) +[RUNNING] `rustc [..]--edition=2015 [..] +"), + ); +} + +#[test] +fn target_edition_feature_gated() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + edition = "2018" + "#, + ) + .file("src/lib.rs", "") + .build(); + + assert_that( + p.cargo("build").arg("-v").masquerade_as_nightly_cargo(), + execs().with_status(101).with_stderr(format!( + "\ +error: failed to parse manifest at `[..]` + +Caused by: + editions are unstable + +Caused by: + feature `edition` is required + +consider adding `cargo-features = [\"edition\"]` to the manifest +" + )), + ); +} + #[test] fn same_metadata_different_directory() { // A top-level crate built in two different workspaces should have the diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 7feecccedfe..fc933ad3b11 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1290,6 +1290,43 @@ fn doc_edition() { ); } +#[test] +fn doc_target_edition() { + if !support::is_nightly() { + return; + } + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["edition"] + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [lib] + edition = "2018" + "#, + ) + .file("src/lib.rs", "") + .build(); + + assert_that( + p.cargo("doc -v").masquerade_as_nightly_cargo(), + execs() + .with_status(0) + .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"), + ); + + assert_that( + p.cargo("test -v").masquerade_as_nightly_cargo(), + execs() + .with_status(0) + .with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]") + ); +} + // Tests an issue where depending on different versions of the same crate depending on `cfg`s // caused `cargo doc` to fail. #[test]