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 3, 2023
1 parent 857af5c commit 7707867
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ mod quiet;
mod registry;
mod rename;
mod require_weak;
mod rust_version;
mod rust_version_incompatible;
mod sorted_table_with_dotted_item;
mod target;
mod target_cfg;
Expand Down Expand Up @@ -201,4 +203,14 @@ fn add_registry_packages(alt: bool) {
.feature("eyes", &[])
.feature("ears", &[])
.publish();

// rust-version
cargo_test_support::registry::Package::new("rust-version-user", "0.1.0")
.alternative(alt)
.rust_version("1.66")
.publish();
cargo_test_support::registry::Package::new("rust-version-user", "0.2.1")
.alternative(alt)
.rust_version("1.72")
.publish();
}
6 changes: 6 additions & 0 deletions tests/testsuite/cargo_add/rust_version/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.
27 changes: 27 additions & 0 deletions tests/testsuite/cargo_add/rust_version/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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();
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/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/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 the minimum supported rust version
Adding rust-version-user v0.1.0 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.
27 changes: 27 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,27 @@
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();
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,2 @@
Updating `dummy-registry` index
error: could not find version of crate `rust-version-user` that satisfies the minimum supported rust version
Empty file.

0 comments on commit 7707867

Please sign in to comment.