Skip to content

Commit 7c8d997

Browse files
committed
Add overwrite testcase for cargo add --public
1 parent a1a75e8 commit 7c8d997

File tree

25 files changed

+252
-0
lines changed

25 files changed

+252
-0
lines changed

tests/testsuite/cargo_add/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ mod offline_empty_cache;
6969
mod optional;
7070
mod overwrite_default_features;
7171
mod overwrite_default_features_with_no_default_features;
72+
mod overwrite_no_public;
73+
mod overwrite_no_public_with_public;
74+
mod overwrite_public;
75+
mod overwrite_public_with_no_public;
7276
mod overwrite_features;
7377
mod overwrite_git_with_path;
7478
mod overwrite_inherit_features_noop;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cargo-features = ["public-dependency"]
2+
[workspace]
3+
4+
[package]
5+
name = "cargo-list-test-fixture"
6+
version = "0.0.0"
7+
8+
[dependencies]
9+
my-package1 = "99999.0.0"
10+
my-package2 = "0.4.1"

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

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use cargo_test_support::curr_dir;
6+
7+
#[cargo_test]
8+
fn case() {
9+
cargo_test_support::registry::init();
10+
for name in ["my-package1", "my-package2"] {
11+
for ver in [
12+
"0.1.1+my-package",
13+
"0.2.0+my-package",
14+
"0.2.3+my-package",
15+
"0.4.1+my-package",
16+
"20.0.0+my-package",
17+
"99999.0.0+my-package",
18+
"99999.0.0-alpha.1+my-package",
19+
] {
20+
cargo_test_support::registry::Package::new(name, ver).publish();
21+
}
22+
}
23+
24+
let project = Project::from_template(curr_dir!().join("in"));
25+
let project_root = project.root();
26+
let cwd = &project_root;
27+
28+
snapbox::cmd::Command::cargo_ui()
29+
.arg("add")
30+
.arg_line("my-package1 my-package2@0.4.1 --no-public")
31+
.current_dir(cwd)
32+
.masquerade_as_nightly_cargo(&["public-dependency"])
33+
.assert()
34+
.success()
35+
.stdout_matches_path(curr_dir!().join("stdout.log"))
36+
.stderr_matches_path(curr_dir!().join("stderr.log"));
37+
38+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
39+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cargo-features = ["public-dependency"]
2+
[workspace]
3+
4+
[package]
5+
name = "cargo-list-test-fixture"
6+
version = "0.0.0"
7+
8+
[dependencies]
9+
my-package1 = "99999.0.0"
10+
my-package2 = "0.4.1"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Updating `dummy-registry` index
2+
Adding my-package1 v99999.0.0 to dependencies.
3+
Adding my-package2 v0.4.1 to dependencies.

tests/testsuite/cargo_add/overwrite_no_public/stdout.log

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cargo-features = ["public-dependency"]
2+
[workspace]
3+
4+
[package]
5+
name = "cargo-list-test-fixture"
6+
version = "0.0.0"
7+
8+
[dependencies]
9+
my-package1 = { version = "99999.0.0", public = false }
10+
my-package2 = { version = "0.4.1", public = false }

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

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use cargo_test_support::curr_dir;
6+
7+
#[cargo_test]
8+
fn case() {
9+
cargo_test_support::registry::init();
10+
for name in ["my-package1", "my-package2"] {
11+
for ver in [
12+
"0.1.1+my-package",
13+
"0.2.0+my-package",
14+
"0.2.3+my-package",
15+
"0.4.1+my-package",
16+
"20.0.0+my-package",
17+
"99999.0.0+my-package",
18+
"99999.0.0-alpha.1+my-package",
19+
] {
20+
cargo_test_support::registry::Package::new(name, ver).publish();
21+
}
22+
}
23+
24+
let project = Project::from_template(curr_dir!().join("in"));
25+
let project_root = project.root();
26+
let cwd = &project_root;
27+
28+
snapbox::cmd::Command::cargo_ui()
29+
.arg("add")
30+
.arg_line("my-package1 my-package2@0.4.1 --public")
31+
.current_dir(cwd)
32+
.masquerade_as_nightly_cargo(&["public-dependency"])
33+
.assert()
34+
.success()
35+
.stdout_matches_path(curr_dir!().join("stdout.log"))
36+
.stderr_matches_path(curr_dir!().join("stderr.log"));
37+
38+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
39+
}

0 commit comments

Comments
 (0)