1 //! Tests for targets with `rust-version`.
3 use cargo_test_support
::{project, registry::Package}
;
6 fn rust_version_gated() {
14 rust-version = "1.9999"
17 .file("src/lib.rs", "")
20 .masquerade_as_nightly_cargo()
21 .with_stderr_contains(
22 "warning: `rust-version` is not supported on this version of Cargo and will be ignored\
23 \n\nconsider adding `cargo-features = [\"rust-version\"]` to the manifest",
34 rust-version = "1.9999"
37 .file("src/lib.rs", "")
40 .with_stderr_contains(
41 "warning: `rust-version` is not supported on this version of Cargo and will be ignored\
42 \n\nthis Cargo does not support nightly features, but if you\n\
43 switch to nightly channel you can add\n\
44 `cargo-features = [\"rust-version\"]` to enable this feature",
50 fn rust_version_satisfied() {
55 cargo-features = ["rust-version"]
61 rust-version = "1.1.1"
66 .file("src/main.rs", "fn main() {}")
69 p
.cargo("build").masquerade_as_nightly_cargo().run();
70 p
.cargo("build --ignore-rust-version -Zunstable-options")
71 .masquerade_as_nightly_cargo()
76 fn rust_version_bad_caret() {
81 cargo-features = ["rust-version"]
87 rust-version = "^1.43"
92 .file("src/main.rs", "fn main() {}")
95 .masquerade_as_nightly_cargo()
98 "error: failed to parse manifest at `[..]`\n\n\
99 Caused by:\n `rust-version` must be a value like \"1.32\"",
105 fn rust_version_bad_pre_release() {
110 cargo-features = ["rust-version"]
116 rust-version = "1.43-beta.1"
121 .file("src/main.rs", "fn main() {}")
124 .masquerade_as_nightly_cargo()
127 "error: failed to parse manifest at `[..]`\n\n\
128 Caused by:\n `rust-version` must be a value like \"1.32\"",
134 fn rust_version_bad_nonsense() {
139 cargo-features = ["rust-version"]
145 rust-version = "foodaddle"
150 .file("src/main.rs", "fn main() {}")
153 .masquerade_as_nightly_cargo()
156 "error: failed to parse manifest at `[..]`\n\n\
157 Caused by:\n `rust-version` must be a value like \"1.32\"",
163 fn rust_version_too_high() {
168 cargo-features = ["rust-version"]
174 rust-version = "1.9876.0"
179 .file("src/main.rs", "fn main() {}")
183 .masquerade_as_nightly_cargo()
186 "error: package `foo v0.0.1 ([..])` cannot be built because it requires \
187 rustc 1.9876.0 or newer, while the currently active rustc version is [..]",
190 p
.cargo("build --ignore-rust-version -Zunstable-options")
191 .masquerade_as_nightly_cargo()
196 fn rust_version_dependency_fails() {
197 Package
::new("bar", "0.0.1")
198 .cargo_feature("rust-version")
199 .rust_version("1.2345.0")
200 .file("src/lib.rs", "fn other_stuff() {}")
215 .file("src/main.rs", "fn main(){}")
219 .masquerade_as_nightly_cargo()
222 " Updating `[..]` index\n \
223 Downloading crates ...\n \
224 Downloaded bar v0.0.1 (registry `[..]`)\n\
225 error: package `bar v0.0.1` cannot be built because it requires \
226 rustc 1.2345.0 or newer, while the currently active rustc version is [..]",
229 p
.cargo("build --ignore-rust-version -Zunstable-options")
230 .masquerade_as_nightly_cargo()
235 fn rust_version_older_than_edition() {
240 cargo-features = ["rust-version"]
252 .file("src/main.rs", "fn main() {}")
255 .masquerade_as_nightly_cargo()
257 .with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)",