Skip to content

Commit

Permalink
Add tests for per-target edition
Browse files Browse the repository at this point in the history
Test:
* enabling edition feature & setting at target level (happy path)
* overriding the package-level edition with per-target edition
* feature gating of per-target edition
* per-target edition usage for rustdoc
  • Loading branch information
dwijnand committed Jul 31, 2018
1 parent 75c15f8 commit 67c52ff
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
92 changes: 92 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 67c52ff

Please sign in to comment.