Skip to content

Commit

Permalink
Add tests for cargo add's rust-version behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
cassaundra committed May 4, 2023
1 parent 9ddcf9f commit 4ae83b9
Show file tree
Hide file tree
Showing 29 changed files with 213 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ mod quiet;
mod registry;
mod rename;
mod require_weak;
mod rust_version_ignore;
mod rust_version_incompatible;
mod rust_version_latest;
mod rust_version_older;
mod sorted_table_with_dotted_item;
mod target;
mod target_cfg;
Expand Down
6 changes: 6 additions & 0 deletions tests/testsuite/cargo_add/rust_version_ignore/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.68"
Empty file.
36 changes: 36 additions & 0 deletions tests/testsuite/cargo_add/rust_version_ignore/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

use crate::cargo_add::init_registry;
use cargo_test_support::curr_dir;

#[cargo_test(nightly, reason = "-Zmsrv-policy is unstable")]
fn case() {
init_registry();

cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
.rust_version("1.66")
.publish();
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
.rust_version("1.72")
.publish();

let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg("--ignore-rust-version")
.arg_line("rust-version-user")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
9 changes: 9 additions & 0 deletions tests/testsuite/cargo_add/rust_version_ignore/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.68"

[dependencies]
rust-version-user = "0.2.1"
Empty file.
2 changes: 2 additions & 0 deletions tests/testsuite/cargo_add/rust_version_ignore/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Updating `dummy-registry` index
Adding rust-version-user v0.2.1 to dependencies.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.56"
Empty file.
35 changes: 35 additions & 0 deletions tests/testsuite/cargo_add/rust_version_incompatible/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

use crate::cargo_add::init_registry;
use cargo_test_support::curr_dir;

#[cargo_test(nightly, reason = "-Zmsrv-policy is unstable")]
fn case() {
init_registry();

cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
.rust_version("1.66")
.publish();
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
.rust_version("1.72")
.publish();

let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.failure()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.56"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Updating `dummy-registry` index
error: could not find version of crate `rust-version-user` that satisfies this package's rust-version
help: use `--ignore-rust-version` to override this behavior
note: the lowest rust-version available for `rust-version-user` is 1.66
Empty file.
6 changes: 6 additions & 0 deletions tests/testsuite/cargo_add/rust_version_latest/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.72"
Empty file.
35 changes: 35 additions & 0 deletions tests/testsuite/cargo_add/rust_version_latest/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

use crate::cargo_add::init_registry;
use cargo_test_support::curr_dir;

#[cargo_test(nightly, reason = "-Zmsrv-policy is unstable")]
fn case() {
init_registry();

cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
.rust_version("1.66")
.publish();
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
.rust_version("1.72")
.publish();

let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
9 changes: 9 additions & 0 deletions tests/testsuite/cargo_add/rust_version_latest/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.72"

[dependencies]
rust-version-user = "0.2.1"
Empty file.
2 changes: 2 additions & 0 deletions tests/testsuite/cargo_add/rust_version_latest/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Updating `dummy-registry` index
Adding rust-version-user v0.2.1 to dependencies.
Empty file.
6 changes: 6 additions & 0 deletions tests/testsuite/cargo_add/rust_version_older/in/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.70"
Empty file.
35 changes: 35 additions & 0 deletions tests/testsuite/cargo_add/rust_version_older/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

use crate::cargo_add::init_registry;
use cargo_test_support::curr_dir;

#[cargo_test(nightly, reason = "-Zmsrv-policy is unstable")]
fn case() {
init_registry();

cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
.rust_version("1.66")
.publish();
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
.rust_version("1.72")
.publish();

let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("-Zmsrv-policy")
.arg("add")
.arg_line("rust-version-user")
.current_dir(cwd)
.masquerade_as_nightly_cargo(&["msrv-policy"])
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
9 changes: 9 additions & 0 deletions tests/testsuite/cargo_add/rust_version_older/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
rust-version = "1.70"

[dependencies]
rust-version-user = "0.1.0"
Empty file.
3 changes: 3 additions & 0 deletions tests/testsuite/cargo_add/rust_version_older/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Updating `dummy-registry` index
warning: selecting older version of `rust-version-user` to satisfy this package's rust-version (use `--ignore-rust-version` to override)
Adding rust-version-user v0.1.0 to dependencies.
Empty file.

0 comments on commit 4ae83b9

Please sign in to comment.