Skip to content

Commit 4ae83b9

Browse files
committed
Add tests for cargo add's rust-version behavior
1 parent 9ddcf9f commit 4ae83b9

File tree

29 files changed

+213
-0
lines changed

29 files changed

+213
-0
lines changed

tests/testsuite/cargo_add/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ mod quiet;
102102
mod registry;
103103
mod rename;
104104
mod require_weak;
105+
mod rust_version_ignore;
106+
mod rust_version_incompatible;
107+
mod rust_version_latest;
108+
mod rust_version_older;
105109
mod sorted_table_with_dotted_item;
106110
mod target;
107111
mod target_cfg;
Lines changed: 6 additions & 0 deletions
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.68"

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

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
12+
cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
13+
.rust_version("1.66")
14+
.publish();
15+
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
16+
.rust_version("1.72")
17+
.publish();
18+
19+
let project = Project::from_template(curr_dir!().join("in"));
20+
let project_root = project.root();
21+
let cwd = &project_root;
22+
23+
snapbox::cmd::Command::cargo_ui()
24+
.arg("-Zmsrv-policy")
25+
.arg("add")
26+
.arg("--ignore-rust-version")
27+
.arg_line("rust-version-user")
28+
.current_dir(cwd)
29+
.masquerade_as_nightly_cargo(&["msrv-policy"])
30+
.assert()
31+
.success()
32+
.stdout_matches_path(curr_dir!().join("stdout.log"))
33+
.stderr_matches_path(curr_dir!().join("stderr.log"));
34+
35+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
36+
}
Lines changed: 9 additions & 0 deletions
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.68"
7+
8+
[dependencies]
9+
rust-version-user = "0.2.1"

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

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Updating `dummy-registry` index
2+
Adding rust-version-user v0.2.1 to dependencies.

tests/testsuite/cargo_add/rust_version_ignore/stdout.log

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
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.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
12+
cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
13+
.rust_version("1.66")
14+
.publish();
15+
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
16+
.rust_version("1.72")
17+
.publish();
18+
19+
let project = Project::from_template(curr_dir!().join("in"));
20+
let project_root = project.root();
21+
let cwd = &project_root;
22+
23+
snapbox::cmd::Command::cargo_ui()
24+
.arg("-Zmsrv-policy")
25+
.arg("add")
26+
.arg_line("rust-version-user")
27+
.current_dir(cwd)
28+
.masquerade_as_nightly_cargo(&["msrv-policy"])
29+
.assert()
30+
.failure()
31+
.stdout_matches_path(curr_dir!().join("stdout.log"))
32+
.stderr_matches_path(curr_dir!().join("stderr.log"));
33+
34+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
35+
}
Lines changed: 6 additions & 0 deletions
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.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Updating `dummy-registry` index
2+
error: could not find version of crate `rust-version-user` that satisfies this package's rust-version
3+
help: use `--ignore-rust-version` to override this behavior
4+
note: the lowest rust-version available for `rust-version-user` is 1.66

tests/testsuite/cargo_add/rust_version_incompatible/stdout.log

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
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.72"

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

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
12+
cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
13+
.rust_version("1.66")
14+
.publish();
15+
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
16+
.rust_version("1.72")
17+
.publish();
18+
19+
let project = Project::from_template(curr_dir!().join("in"));
20+
let project_root = project.root();
21+
let cwd = &project_root;
22+
23+
snapbox::cmd::Command::cargo_ui()
24+
.arg("-Zmsrv-policy")
25+
.arg("add")
26+
.arg_line("rust-version-user")
27+
.current_dir(cwd)
28+
.masquerade_as_nightly_cargo(&["msrv-policy"])
29+
.assert()
30+
.success()
31+
.stdout_matches_path(curr_dir!().join("stdout.log"))
32+
.stderr_matches_path(curr_dir!().join("stderr.log"));
33+
34+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
35+
}
Lines changed: 9 additions & 0 deletions
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.72"
7+
8+
[dependencies]
9+
rust-version-user = "0.2.1"

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

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Updating `dummy-registry` index
2+
Adding rust-version-user v0.2.1 to dependencies.

tests/testsuite/cargo_add/rust_version_latest/stdout.log

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
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_older/in/src/lib.rs

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
12+
cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
13+
.rust_version("1.66")
14+
.publish();
15+
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
16+
.rust_version("1.72")
17+
.publish();
18+
19+
let project = Project::from_template(curr_dir!().join("in"));
20+
let project_root = project.root();
21+
let cwd = &project_root;
22+
23+
snapbox::cmd::Command::cargo_ui()
24+
.arg("-Zmsrv-policy")
25+
.arg("add")
26+
.arg_line("rust-version-user")
27+
.current_dir(cwd)
28+
.masquerade_as_nightly_cargo(&["msrv-policy"])
29+
.assert()
30+
.success()
31+
.stdout_matches_path(curr_dir!().join("stdout.log"))
32+
.stderr_matches_path(curr_dir!().join("stderr.log"));
33+
34+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
35+
}
Lines changed: 9 additions & 0 deletions
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_older/out/src/lib.rs

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
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 this package's rust-version (use `--ignore-rust-version` to override)
3+
Adding rust-version-user v0.1.0 to dependencies.

tests/testsuite/cargo_add/rust_version_older/stdout.log

Whitespace-only changes.

0 commit comments

Comments
 (0)