Skip to content

Commit c2b83a9

Browse files
committed
Add tests for cargo add's rust-version behavior
1 parent 1dc03a7 commit c2b83a9

File tree

29 files changed

+217
-0
lines changed

29 files changed

+217
-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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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("-Zunstable-options")
25+
.arg("-Zmsrv-policy")
26+
.arg("add")
27+
.arg("--ignore-rust-version")
28+
.arg_line("rust-version-user")
29+
.current_dir(cwd)
30+
.masquerade_as_nightly_cargo(&["msrv-policy"])
31+
.assert()
32+
.success()
33+
.stdout_matches_path(curr_dir!().join("stdout.log"))
34+
.stderr_matches_path(curr_dir!().join("stderr.log"));
35+
36+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
37+
}
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.1.1")
16+
.rust_version("1.66")
17+
.publish();
18+
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
19+
.rust_version("1.72")
20+
.publish();
21+
22+
let project = Project::from_template(curr_dir!().join("in"));
23+
let project_root = project.root();
24+
let cwd = &project_root;
25+
26+
snapbox::cmd::Command::cargo_ui()
27+
.arg("-Zmsrv-policy")
28+
.arg("add")
29+
.arg_line("rust-version-user")
30+
.current_dir(cwd)
31+
.masquerade_as_nightly_cargo(&["msrv-policy"])
32+
.assert()
33+
.failure()
34+
.stdout_matches_path(curr_dir!().join("stdout.log"))
35+
.stderr_matches_path(curr_dir!().join("stderr.log"));
36+
37+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
38+
}
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 of 1.56
3+
help: use `--ignore-rust-version` to override this behavior
4+
note: the lowest rust-version available for `rust-version-user` is 1.66, used in version 0.1.1

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: ignoring `rust-version-user` 0.2.1 to satisfy this package's rust-version of 1.70 (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)