Skip to content

Commit 7707867

Browse files
committed
Add tests for cargo add's rust-version behavior
1 parent 857af5c commit 7707867

File tree

15 files changed

+98
-0
lines changed

15 files changed

+98
-0
lines changed

tests/testsuite/cargo_add/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ mod quiet;
102102
mod registry;
103103
mod rename;
104104
mod require_weak;
105+
mod rust_version;
106+
mod rust_version_incompatible;
105107
mod sorted_table_with_dotted_item;
106108
mod target;
107109
mod target_cfg;
@@ -201,4 +203,14 @@ fn add_registry_packages(alt: bool) {
201203
.feature("eyes", &[])
202204
.feature("ears", &[])
203205
.publish();
206+
207+
// rust-version
208+
cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
209+
.alternative(alt)
210+
.rust_version("1.66")
211+
.publish();
212+
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
213+
.alternative(alt)
214+
.rust_version("1.72")
215+
.publish();
204216
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
rust-version = "1.70"

tests/testsuite/cargo_add/rust_version/in/src/lib.rs

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use crate::cargo_add::init_registry;
6+
use cargo_test_support::curr_dir;
7+
8+
#[cargo_test(nightly, reason = "-Zmsrv-policy is unstable")]
9+
fn case() {
10+
init_registry();
11+
let project = Project::from_template(curr_dir!().join("in"));
12+
let project_root = project.root();
13+
let cwd = &project_root;
14+
15+
snapbox::cmd::Command::cargo_ui()
16+
.arg("-Zmsrv-policy")
17+
.arg("add")
18+
.arg_line("rust-version-user")
19+
.current_dir(cwd)
20+
.masquerade_as_nightly_cargo(&["msrv-policy"])
21+
.assert()
22+
.success()
23+
.stdout_matches_path(curr_dir!().join("stdout.log"))
24+
.stderr_matches_path(curr_dir!().join("stderr.log"));
25+
26+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
rust-version = "1.70"
7+
8+
[dependencies]
9+
rust-version-user = "0.1.0"

tests/testsuite/cargo_add/rust_version/out/src/lib.rs

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Updating `dummy-registry` index
2+
warning: selecting older version of `rust-version-user` to satisfy the minimum supported rust version
3+
Adding rust-version-user v0.1.0 to dependencies.

tests/testsuite/cargo_add/rust_version/stdout.log

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
rust-version = "1.56"

tests/testsuite/cargo_add/rust_version_incompatible/in/src/lib.rs

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use crate::cargo_add::init_registry;
6+
use cargo_test_support::curr_dir;
7+
8+
#[cargo_test(nightly, reason = "-Zmsrv-policy is unstable")]
9+
fn case() {
10+
init_registry();
11+
let project = Project::from_template(curr_dir!().join("in"));
12+
let project_root = project.root();
13+
let cwd = &project_root;
14+
15+
snapbox::cmd::Command::cargo_ui()
16+
.arg("-Zmsrv-policy")
17+
.arg("add")
18+
.arg_line("rust-version-user")
19+
.current_dir(cwd)
20+
.masquerade_as_nightly_cargo(&["msrv-policy"])
21+
.assert()
22+
.failure()
23+
.stdout_matches_path(curr_dir!().join("stdout.log"))
24+
.stderr_matches_path(curr_dir!().join("stderr.log"));
25+
26+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
rust-version = "1.56"

tests/testsuite/cargo_add/rust_version_incompatible/out/src/lib.rs

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Updating `dummy-registry` index
2+
error: could not find version of crate `rust-version-user` that satisfies the minimum supported rust version

tests/testsuite/cargo_add/rust_version_incompatible/stdout.log

Whitespace-only changes.

0 commit comments

Comments
 (0)