diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:47:55 +0000 |
commit | 2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4 (patch) | |
tree | 033cc839730fda84ff08db877037977be94e5e3a /tests/testsuite/rust_version.rs | |
parent | Initial commit. (diff) | |
download | cargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.tar.xz cargo-2aadc03ef15cb5ca5cc2af8a7c08e070742f0ac4.zip |
Adding upstream version 0.70.1+ds1.upstream/0.70.1+ds1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/testsuite/rust_version.rs')
-rw-r--r-- | tests/testsuite/rust_version.rs | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/tests/testsuite/rust_version.rs b/tests/testsuite/rust_version.rs new file mode 100644 index 0000000..91711cf --- /dev/null +++ b/tests/testsuite/rust_version.rs @@ -0,0 +1,194 @@ +//! Tests for targets with `rust-version`. + +use cargo_test_support::{project, registry::Package}; + +#[cargo_test] +fn rust_version_satisfied() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "1.1.1" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check").run(); + p.cargo("check --ignore-rust-version").run(); +} + +#[cargo_test] +fn rust_version_bad_caret() { + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "^1.43" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build() + .cargo("check") + .with_status(101) + .with_stderr( + "error: failed to parse manifest at `[..]`\n\n\ + Caused by:\n `rust-version` must be a value like \"1.32\"", + ) + .run(); +} + +#[cargo_test] +fn rust_version_bad_pre_release() { + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "1.43-beta.1" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build() + .cargo("check") + .with_status(101) + .with_stderr( + "error: failed to parse manifest at `[..]`\n\n\ + Caused by:\n `rust-version` must be a value like \"1.32\"", + ) + .run(); +} + +#[cargo_test] +fn rust_version_bad_nonsense() { + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "foodaddle" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build() + .cargo("check") + .with_status(101) + .with_stderr( + "error: failed to parse manifest at `[..]`\n\n\ + Caused by:\n `rust-version` must be a value like \"1.32\"", + ) + .run(); +} + +#[cargo_test] +fn rust_version_too_high() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "1.9876.0" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + "error: package `foo v0.0.1 ([..])` cannot be built because it requires \ + rustc 1.9876.0 or newer, while the currently active rustc version is [..]\n\n", + ) + .run(); + p.cargo("check --ignore-rust-version").run(); +} + +#[cargo_test] +fn rust_version_dependency_fails() { + Package::new("bar", "0.0.1") + .rust_version("1.2345.0") + .file("src/lib.rs", "fn other_stuff() {}") + .publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + [dependencies] + bar = "0.0.1" + "#, + ) + .file("src/main.rs", "fn main(){}") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr( + " Updating `[..]` index\n \ + Downloading crates ...\n \ + Downloaded bar v0.0.1 (registry `[..]`)\n\ + error: package `bar v0.0.1` cannot be built because it requires \ + rustc 1.2345.0 or newer, while the currently active rustc version is [..]\n\ + Either upgrade to rustc 1.2345.0 or newer, or use\n\ + cargo update -p bar@0.0.1 --precise ver\n\ + where `ver` is the latest version of `bar` supporting rustc [..]", + ) + .run(); + p.cargo("check --ignore-rust-version").run(); +} + +#[cargo_test] +fn rust_version_older_than_edition() { + project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + rust-version = "1.1" + edition = "2018" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build() + .cargo("check") + .with_status(101) + .with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)", + ) + .run(); +} |