summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /src/tools/cargo/tests
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/cargo/tests')
-rw-r--r--src/tools/cargo/tests/testsuite/alt_registry.rs12
-rw-r--r--src/tools/cargo/tests/testsuite/artifact_dep.rs1
-rw-r--r--src/tools/cargo/tests/testsuite/bad_config.rs38
-rw-r--r--src/tools/cargo/tests/testsuite/build.rs2
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/Cargo.toml8
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/src/lib.rs1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/mod.rs25
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/out/Cargo.toml8
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stderr.log1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/mod.rs5
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/Cargo.toml6
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/mod.rs36
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/Cargo.toml9
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stderr.log2
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/Cargo.toml6
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs38
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/Cargo.toml6
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stderr.log4
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/Cargo.toml6
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/mod.rs35
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/Cargo.toml9
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stderr.log2
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/Cargo.toml6
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/mod.rs35
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/Cargo.toml9
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/src/lib.rs0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stderr.log3
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_env_config.rs100
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/README.md0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/src/lib.rs14
l---------src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/in1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/mod.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stderr.log1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stdout.log0
l---------src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/in1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/mod.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stderr.log1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stdout.log0
l---------src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/in1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/mod.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stderr.log1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/Cargo.toml20
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/README.md0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/mod.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/Cargo.toml20
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stderr.log1
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/mod.rs5
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/Cargo.toml15
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/README.md0
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/mod.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/Cargo.toml15
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stderr.log9
-rw-r--r--src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/check.rs26
-rw-r--r--src/tools/cargo/tests/testsuite/config.rs67
-rw-r--r--src/tools/cargo/tests/testsuite/features_namespaced.rs81
-rw-r--r--src/tools/cargo/tests/testsuite/fix.rs61
-rw-r--r--src/tools/cargo/tests/testsuite/git.rs89
-rw-r--r--src/tools/cargo/tests/testsuite/git_shallow.rs831
-rw-r--r--src/tools/cargo/tests/testsuite/https.rs2
-rw-r--r--src/tools/cargo/tests/testsuite/inheritable_workspace_fields.rs13
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/README.md0
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/mod.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml21
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs14
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stderr.log1
-rw-r--r--src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stdout.log0
-rw-r--r--src/tools/cargo/tests/testsuite/init/mod.rs1
-rw-r--r--src/tools/cargo/tests/testsuite/install.rs121
-rw-r--r--src/tools/cargo/tests/testsuite/lints.rs639
-rw-r--r--src/tools/cargo/tests/testsuite/main.rs4
-rw-r--r--src/tools/cargo/tests/testsuite/metadata.rs58
-rw-r--r--src/tools/cargo/tests/testsuite/mock-std/library/sysroot/Cargo.toml15
-rw-r--r--src/tools/cargo/tests/testsuite/mock-std/library/sysroot/src/lib.rs1
-rw-r--r--src/tools/cargo/tests/testsuite/mock-std/library/test/Cargo.toml7
-rw-r--r--src/tools/cargo/tests/testsuite/offline.rs38
-rw-r--r--src/tools/cargo/tests/testsuite/package.rs221
-rw-r--r--src/tools/cargo/tests/testsuite/patch.rs19
-rw-r--r--src/tools/cargo/tests/testsuite/profile_config.rs7
-rw-r--r--src/tools/cargo/tests/testsuite/profile_targets.rs22
-rw-r--r--src/tools/cargo/tests/testsuite/publish.rs12
-rw-r--r--src/tools/cargo/tests/testsuite/registry.rs137
-rw-r--r--src/tools/cargo/tests/testsuite/registry_auth.rs73
-rw-r--r--src/tools/cargo/tests/testsuite/rustup.rs262
-rw-r--r--src/tools/cargo/tests/testsuite/tree.rs55
-rw-r--r--src/tools/cargo/tests/testsuite/update.rs3
-rw-r--r--src/tools/cargo/tests/testsuite/vendor.rs5
-rw-r--r--src/tools/cargo/tests/testsuite/weak_dep_features.rs1
128 files changed, 3727 insertions, 194 deletions
diff --git a/src/tools/cargo/tests/testsuite/alt_registry.rs b/src/tools/cargo/tests/testsuite/alt_registry.rs
index 97da909b8..ac60ca92f 100644
--- a/src/tools/cargo/tests/testsuite/alt_registry.rs
+++ b/src/tools/cargo/tests/testsuite/alt_registry.rs
@@ -366,6 +366,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"repository": null,
"homepage": null,
"documentation": null,
+ "rust_version": null,
"vers": "0.0.1"
}"#,
"foo-0.0.1.crate",
@@ -515,6 +516,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"repository": null,
"homepage": null,
"documentation": null,
+ "rust_version": null,
"vers": "0.0.1"
}"#,
"foo-0.0.1.crate",
@@ -607,6 +609,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"repository": null,
"homepage": null,
"documentation": null,
+ "rust_version": null,
"vers": "0.0.1"
}"#,
"foo-0.0.1.crate",
@@ -899,6 +902,9 @@ fn alt_reg_metadata() {
"workspace_members": [
"foo 0.0.1 (path+file:[..]/foo)"
],
+ "workspace_default_members": [
+ "foo 0.0.1 (path+file:[..]/foo)"
+ ],
"resolve": null,
"target_directory": "[..]/foo/target",
"version": 1,
@@ -1099,6 +1105,9 @@ fn alt_reg_metadata() {
"workspace_members": [
"foo 0.0.1 (path+file:[..]/foo)"
],
+ "workspace_default_members": [
+ "foo 0.0.1 (path+file:[..]/foo)"
+ ],
"resolve": "{...}",
"target_directory": "[..]/foo/target",
"version": 1,
@@ -1262,6 +1271,9 @@ fn unknown_registry() {
"workspace_members": [
"foo 0.0.1 (path+file://[..]/foo)"
],
+ "workspace_default_members": [
+ "foo 0.0.1 (path+file://[..]/foo)"
+ ],
"resolve": "{...}",
"target_directory": "[..]/foo/target",
"version": 1,
diff --git a/src/tools/cargo/tests/testsuite/artifact_dep.rs b/src/tools/cargo/tests/testsuite/artifact_dep.rs
index ec6bb7103..08e413bf5 100644
--- a/src/tools/cargo/tests/testsuite/artifact_dep.rs
+++ b/src/tools/cargo/tests/testsuite/artifact_dep.rs
@@ -1956,6 +1956,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": "foo",
+ "rust_version": null,
"vers": "0.1.0"
}
"#,
diff --git a/src/tools/cargo/tests/testsuite/bad_config.rs b/src/tools/cargo/tests/testsuite/bad_config.rs
index ca51b101e..4434ea90d 100644
--- a/src/tools/cargo/tests/testsuite/bad_config.rs
+++ b/src/tools/cargo/tests/testsuite/bad_config.rs
@@ -780,8 +780,8 @@ fn empty_dependencies() {
p.cargo("check")
.with_stderr_contains(
"\
-warning: dependency (bar) specified without providing a local path, Git repository, or version \
-to use. This will be considered an error in future versions
+warning: dependency (bar) specified without providing a local path, Git repository, version, \
+or workspace dependency to use. This will be considered an error in future versions
",
)
.run();
@@ -1317,10 +1317,42 @@ fn bad_debuginfo() {
.with_status(101)
.with_stderr(
"\
+error: failed to parse manifest [..]
+
+Caused by:
+ invalid value: string \"a\", expected a boolean, 0, 1, 2, \"line-tables-only\", or \"line-directives-only\"
+ in `profile.dev.debug`
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn bad_debuginfo2() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.0"
+ authors = []
+
+ [profile.dev]
+ debug = 3.6
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("check")
+ .with_status(101)
+ .with_stderr(
+ "\
error: failed to parse manifest at `[..]`
Caused by:
- expected a boolean or an integer
+ invalid type: floating point `3.6`, expected a boolean, 0, 1, 2, \"line-tables-only\", or \"line-directives-only\"
in `profile.dev.debug`
",
)
diff --git a/src/tools/cargo/tests/testsuite/build.rs b/src/tools/cargo/tests/testsuite/build.rs
index 8a1b6ca86..7b555a71b 100644
--- a/src/tools/cargo/tests/testsuite/build.rs
+++ b/src/tools/cargo/tests/testsuite/build.rs
@@ -3885,7 +3885,7 @@ fn compiler_json_error_format() {
},
"profile": {
"debug_assertions": true,
- "debuginfo": null,
+ "debuginfo": 0,
"opt_level": "0",
"overflow_checks": true,
"test": false
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/Cargo.toml
new file mode 100644
index 000000000..cac16bb94
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/Cargo.toml
@@ -0,0 +1,8 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+
+[dependencies]
+your-face = { }
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/src/lib.rs
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/in/src/lib.rs
@@ -0,0 +1 @@
+
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/mod.rs
new file mode 100644
index 000000000..f6c507188
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/mod.rs
@@ -0,0 +1,25 @@
+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]
+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("add")
+ .arg_line("your-face --features eyes")
+ .current_dir(cwd)
+ .assert()
+ .code(101)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/out/Cargo.toml
new file mode 100644
index 000000000..cac16bb94
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/out/Cargo.toml
@@ -0,0 +1,8 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+
+[dependencies]
+your-face = { }
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stderr.log b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stderr.log
new file mode 100644
index 000000000..3acd7b944
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stderr.log
@@ -0,0 +1 @@
+error: unrecognized dependency source for `your-face`, expected a local path, Git repository, version, or workspace dependency to be specified
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stdout.log b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/empty_dep_table/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/mod.rs
index ca58474d2..cd7e94e09 100644
--- a/src/tools/cargo/tests/testsuite/cargo_add/mod.rs
+++ b/src/tools/cargo/tests/testsuite/cargo_add/mod.rs
@@ -15,6 +15,7 @@ mod dev;
mod dev_build_conflict;
mod dev_prefer_existing_version;
mod dry_run;
+mod empty_dep_table;
mod features;
mod features_empty;
mod features_multiple_occurrences;
@@ -101,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;
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/Cargo.toml
new file mode 100644
index 000000000..b24cd9deb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+rust-version = "1.68"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/in/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/mod.rs
new file mode 100644
index 000000000..9aa11eaac
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/mod.rs
@@ -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]
+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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/Cargo.toml
new file mode 100644
index 000000000..62164a344
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/Cargo.toml
@@ -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"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/out/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stderr.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stderr.log
new file mode 100644
index 000000000..430abe31b
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stderr.log
@@ -0,0 +1,2 @@
+ Updating `dummy-registry` index
+ Adding rust-version-user v0.2.1 to dependencies.
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stdout.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_ignore/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/Cargo.toml
new file mode 100644
index 000000000..ef6fce441
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+rust-version = "1.56"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/in/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs
new file mode 100644
index 000000000..6baad0e05
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/mod.rs
@@ -0,0 +1,38 @@
+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]
+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.1.1")
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/Cargo.toml
new file mode 100644
index 000000000..ef6fce441
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+rust-version = "1.56"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/out/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stderr.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stderr.log
new file mode 100644
index 000000000..babed5b23
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stderr.log
@@ -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 of 1.56
+help: use `--ignore-rust-version` to override this behavior
+note: the lowest rust-version available for `rust-version-user` is 1.66, used in version 0.1.1
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stdout.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_incompatible/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/Cargo.toml
new file mode 100644
index 000000000..d9358a5de
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+rust-version = "1.72"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/in/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/mod.rs
new file mode 100644
index 000000000..60e38960f
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/mod.rs
@@ -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]
+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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/Cargo.toml
new file mode 100644
index 000000000..f824b41c3
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/Cargo.toml
@@ -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"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/out/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stderr.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stderr.log
new file mode 100644
index 000000000..430abe31b
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stderr.log
@@ -0,0 +1,2 @@
+ Updating `dummy-registry` index
+ Adding rust-version-user v0.2.1 to dependencies.
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stdout.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_latest/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/Cargo.toml
new file mode 100644
index 000000000..6fd6f1232
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/Cargo.toml
@@ -0,0 +1,6 @@
+[workspace]
+
+[package]
+name = "cargo-list-test-fixture"
+version = "0.0.0"
+rust-version = "1.70"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/in/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/mod.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/mod.rs
new file mode 100644
index 000000000..60e38960f
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/mod.rs
@@ -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]
+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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/Cargo.toml
new file mode 100644
index 000000000..14737e328
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/Cargo.toml
@@ -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"
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/src/lib.rs
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/out/src/lib.rs
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stderr.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stderr.log
new file mode 100644
index 000000000..4c5988d0b
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stderr.log
@@ -0,0 +1,3 @@
+ Updating `dummy-registry` index
+warning: ignoring `rust-version-user@0.2.1` (which has a rust-version of 1.72) to satisfy this package's rust-version of 1.70 (use `--ignore-rust-version` to override)
+ Adding rust-version-user v0.1.0 to dependencies.
diff --git a/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stdout.log b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_add/rust_version_older/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_env_config.rs b/src/tools/cargo/tests/testsuite/cargo_env_config.rs
index d80c38d0e..dbb89664d 100644
--- a/src/tools/cargo/tests/testsuite/cargo_env_config.rs
+++ b/src/tools/cargo/tests/testsuite/cargo_env_config.rs
@@ -1,5 +1,6 @@
//! Tests for `[env]` config.
+use cargo_test_support::basic_manifest;
use cargo_test_support::{basic_bin_manifest, project};
#[cargo_test]
@@ -58,29 +59,31 @@ fn env_invalid() {
}
#[cargo_test]
-fn env_no_cargo_home() {
+fn env_no_disallowed() {
+ // Checks for keys that are not allowed in the [env] table.
let p = project()
- .file("Cargo.toml", &basic_bin_manifest("foo"))
- .file(
- "src/main.rs",
- r#"
- fn main() {
- }
- "#,
- )
- .file(
- ".cargo/config",
- r#"
- [env]
- CARGO_HOME = "/"
- "#,
- )
+ .file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
+ .file("src/lib.rs", "")
.build();
- p.cargo("check")
- .with_status(101)
- .with_stderr_contains("[..]setting the `CARGO_HOME` environment variable is not supported in the `[env]` configuration table")
- .run();
+ for disallowed in &["CARGO_HOME", "RUSTUP_HOME", "RUSTUP_TOOLCHAIN"] {
+ p.change_file(
+ ".cargo/config",
+ &format!(
+ r#"
+ [env]
+ {disallowed} = "foo"
+ "#
+ ),
+ );
+ p.cargo("check")
+ .with_status(101)
+ .with_stderr(&format!(
+ "[ERROR] setting the `{disallowed}` environment variable \
+ is not supported in the `[env]` configuration table"
+ ))
+ .run();
+ }
}
#[cargo_test]
@@ -179,3 +182,60 @@ fn env_no_override() {
.with_stdout_contains("CARGO_PKG_NAME:unchanged")
.run();
}
+
+#[cargo_test]
+fn env_applied_to_target_info_discovery_rustc() {
+ let wrapper = project()
+ .at("wrapper")
+ .file("Cargo.toml", &basic_manifest("wrapper", "1.0.0"))
+ .file(
+ "src/main.rs",
+ r#"
+ fn main() {
+ let mut args = std::env::args().skip(1);
+ let env_test = std::env::var("ENV_TEST").unwrap();
+ eprintln!("WRAPPER ENV_TEST:{env_test}");
+ let status = std::process::Command::new(&args.next().unwrap())
+ .args(args).status().unwrap();
+ std::process::exit(status.code().unwrap_or(1));
+ }
+ "#,
+ )
+ .build();
+ wrapper.cargo("build").run();
+ let wrapper = &wrapper.bin("wrapper");
+
+ let p = project()
+ .file("Cargo.toml", &basic_bin_manifest("foo"))
+ .file(
+ "src/main.rs",
+ r#"
+ fn main() {
+ eprintln!( "MAIN ENV_TEST:{}", std::env!("ENV_TEST") );
+ }
+ "#,
+ )
+ .file(
+ ".cargo/config",
+ r#"
+ [env]
+ ENV_TEST = "from-config"
+ "#,
+ )
+ .build();
+
+ p.cargo("run")
+ .env("RUSTC_WORKSPACE_WRAPPER", wrapper)
+ .with_stderr_contains("WRAPPER ENV_TEST:from-config")
+ .with_stderr_contains("MAIN ENV_TEST:from-config")
+ .run();
+
+ // Ensure wrapper also maintains the same overridden priority for envs.
+ p.cargo("clean").run();
+ p.cargo("run")
+ .env("ENV_TEST", "from-env")
+ .env("RUSTC_WORKSPACE_WRAPPER", wrapper)
+ .with_stderr_contains("WRAPPER ENV_TEST:from-env")
+ .with_stderr_contains("MAIN ENV_TEST:from-env")
+ .run();
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/Cargo.toml
new file mode 100644
index 000000000..b7a2e9036
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/Cargo.toml
@@ -0,0 +1,21 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
+version = "1.2.3"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/README.md b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/README.md
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/README.md
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table.in/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/in b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/in
new file mode 120000
index 000000000..aba551efe
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/in
@@ -0,0 +1 @@
+../inherit_workspace_package_table.in \ No newline at end of file
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/mod.rs
new file mode 100644
index 000000000..9b9642468
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/mod.rs
@@ -0,0 +1,22 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::curr_dir;
+use cargo_test_support::CargoCommand;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(curr_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("new")
+ .args(["crates/foo"])
+ .current_dir(cwd)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/Cargo.toml
new file mode 100644
index 000000000..b7a2e9036
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/Cargo.toml
@@ -0,0 +1,21 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
+version = "1.2.3"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/Cargo.toml
new file mode 100644
index 000000000..137ed1c87
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "foo"
+authors.workspace = true
+description.workspace = true
+edition.workspace = true
+homepage.workspace = true
+keywords.workspace = true
+readme.workspace = true
+rust-version.workspace = true
+categories.workspace = true
+documentation.workspace = true
+exclude.workspace = true
+include.workspace = true
+license.workspace = true
+publish.workspace = true
+repository.workspace = true
+version.workspace = true
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/src/main.rs
new file mode 100644
index 000000000..e7a11a969
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/crates/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/out/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stderr.log
new file mode 100644
index 000000000..90150cdf5
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stderr.log
@@ -0,0 +1 @@
+ Created binary (application) `crates/foo` package
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/in b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/in
new file mode 120000
index 000000000..aba551efe
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/in
@@ -0,0 +1 @@
+../inherit_workspace_package_table.in \ No newline at end of file
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/mod.rs
new file mode 100644
index 000000000..c3ac2d375
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/mod.rs
@@ -0,0 +1,22 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::curr_dir;
+use cargo_test_support::CargoCommand;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(curr_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("new")
+ .args(["crates/foo", "--edition", "2021"])
+ .current_dir(cwd)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/Cargo.toml
new file mode 100644
index 000000000..b7a2e9036
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/Cargo.toml
@@ -0,0 +1,21 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
+version = "1.2.3"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/Cargo.toml
new file mode 100644
index 000000000..abb427d43
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "foo"
+edition = "2021"
+authors.workspace = true
+description.workspace = true
+homepage.workspace = true
+keywords.workspace = true
+readme.workspace = true
+rust-version.workspace = true
+categories.workspace = true
+documentation.workspace = true
+exclude.workspace = true
+include.workspace = true
+license.workspace = true
+publish.workspace = true
+repository.workspace = true
+version.workspace = true
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/src/main.rs
new file mode 100644
index 000000000..e7a11a969
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/crates/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/out/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stderr.log
new file mode 100644
index 000000000..90150cdf5
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stderr.log
@@ -0,0 +1 @@
+ Created binary (application) `crates/foo` package
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_edition/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/in b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/in
new file mode 120000
index 000000000..aba551efe
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/in
@@ -0,0 +1 @@
+../inherit_workspace_package_table.in \ No newline at end of file
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/mod.rs
new file mode 100644
index 000000000..16ec66ea2
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/mod.rs
@@ -0,0 +1,22 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::curr_dir;
+use cargo_test_support::CargoCommand;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(curr_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("new")
+ .args(["crates/foo", "--registry", "foo"])
+ .current_dir(cwd)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/Cargo.toml
new file mode 100644
index 000000000..b7a2e9036
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/Cargo.toml
@@ -0,0 +1,21 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
+version = "1.2.3"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/Cargo.toml
new file mode 100644
index 000000000..642a64e46
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "foo"
+publish = ["foo"]
+authors.workspace = true
+description.workspace = true
+edition.workspace = true
+homepage.workspace = true
+keywords.workspace = true
+readme.workspace = true
+rust-version.workspace = true
+categories.workspace = true
+documentation.workspace = true
+exclude.workspace = true
+include.workspace = true
+license.workspace = true
+repository.workspace = true
+version.workspace = true
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/src/main.rs
new file mode 100644
index 000000000..e7a11a969
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/crates/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/out/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stderr.log
new file mode 100644
index 000000000..90150cdf5
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stderr.log
@@ -0,0 +1 @@
+ Created binary (application) `crates/foo` package
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_with_registry/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/Cargo.toml
new file mode 100644
index 000000000..112fef55c
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/Cargo.toml
@@ -0,0 +1,20 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/README.md b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/README.md
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/README.md
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/in/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/mod.rs
new file mode 100644
index 000000000..9b9642468
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/mod.rs
@@ -0,0 +1,22 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::curr_dir;
+use cargo_test_support::CargoCommand;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(curr_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("new")
+ .args(["crates/foo"])
+ .current_dir(cwd)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/Cargo.toml
new file mode 100644
index 000000000..112fef55c
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/Cargo.toml
@@ -0,0 +1,20 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/Cargo.toml
new file mode 100644
index 000000000..4fcf77121
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "foo"
+version = "0.1.0"
+authors.workspace = true
+description.workspace = true
+edition.workspace = true
+homepage.workspace = true
+keywords.workspace = true
+readme.workspace = true
+rust-version.workspace = true
+categories.workspace = true
+documentation.workspace = true
+exclude.workspace = true
+include.workspace = true
+license.workspace = true
+publish.workspace = true
+repository.workspace = true
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/src/main.rs
new file mode 100644
index 000000000..e7a11a969
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/crates/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/out/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stderr.log
new file mode 100644
index 000000000..90150cdf5
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stderr.log
@@ -0,0 +1 @@
+ Created binary (application) `crates/foo` package
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/inherit_workspace_package_table_without_version/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/mod.rs
new file mode 100644
index 000000000..762a70b34
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/mod.rs
@@ -0,0 +1,5 @@
+mod inherit_workspace_package_table;
+mod inherit_workspace_package_table_with_edition;
+mod inherit_workspace_package_table_with_registry;
+mod inherit_workspace_package_table_without_version;
+mod not_inherit_workspace_package_table_if_not_memebers;
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/Cargo.toml
new file mode 100644
index 000000000..2d204581c
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/Cargo.toml
@@ -0,0 +1,15 @@
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/README.md b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/README.md
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/README.md
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/in/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/mod.rs b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/mod.rs
new file mode 100644
index 000000000..cdddf0e64
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/mod.rs
@@ -0,0 +1,22 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::curr_dir;
+use cargo_test_support::CargoCommand;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(curr_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("new")
+ .args(["foo"])
+ .current_dir(cwd)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/Cargo.toml
new file mode 100644
index 000000000..2d204581c
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/Cargo.toml
@@ -0,0 +1,15 @@
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/Cargo.toml
new file mode 100644
index 000000000..4fcf77121
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "foo"
+version = "0.1.0"
+authors.workspace = true
+description.workspace = true
+edition.workspace = true
+homepage.workspace = true
+keywords.workspace = true
+readme.workspace = true
+rust-version.workspace = true
+categories.workspace = true
+documentation.workspace = true
+exclude.workspace = true
+include.workspace = true
+license.workspace = true
+publish.workspace = true
+repository.workspace = true
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/src/main.rs b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/src/main.rs
new file mode 100644
index 000000000..e7a11a969
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/src/lib.rs b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/out/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stderr.log b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stderr.log
new file mode 100644
index 000000000..03b1ff6db
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stderr.log
@@ -0,0 +1,9 @@
+warning: compiling this new package may not work due to invalid workspace configuration
+
+current package believes it's in a workspace when it's not:
+current: [ROOT]/case/foo/Cargo.toml
+workspace: [ROOT]/case/Cargo.toml
+
+this may be fixable by adding `foo` to the `workspace.members` array of the manifest located at: [ROOT]/case/Cargo.toml
+Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.
+ Created binary (application) `foo` package
diff --git a/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stdout.log b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/cargo_new/not_inherit_workspace_package_table_if_not_memebers/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/check.rs b/src/tools/cargo/tests/testsuite/check.rs
index bbcf750fb..7bc9a38a3 100644
--- a/src/tools/cargo/tests/testsuite/check.rs
+++ b/src/tools/cargo/tests/testsuite/check.rs
@@ -6,8 +6,8 @@ use crate::messages::raw_rustc_output;
use cargo_test_support::install::exe;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
-use cargo_test_support::tools;
use cargo_test_support::{basic_bin_manifest, basic_manifest, git, project};
+use cargo_test_support::{tools, wrapped_clippy_driver};
#[cargo_test]
fn check_success() {
@@ -1416,25 +1416,6 @@ fn check_fixable_mixed() {
#[cargo_test]
fn check_fixable_warning_for_clippy() {
- // A wrapper around `rustc` instead of calling `clippy`
- let clippy_driver = project()
- .at(cargo_test_support::paths::global_root().join("clippy-driver"))
- .file("Cargo.toml", &basic_manifest("clippy-driver", "0.0.1"))
- .file(
- "src/main.rs",
- r#"
- fn main() {
- let mut args = std::env::args_os();
- let _me = args.next().unwrap();
- let rustc = args.next().unwrap();
- let status = std::process::Command::new(rustc).args(args).status().unwrap();
- std::process::exit(status.code().unwrap_or(1));
- }
- "#,
- )
- .build();
- clippy_driver.cargo("build").run();
-
let foo = project()
.file(
"Cargo.toml",
@@ -1452,10 +1433,7 @@ fn check_fixable_warning_for_clippy() {
foo.cargo("check")
// We can't use `clippy` so we use a `rustc` workspace wrapper instead
- .env(
- "RUSTC_WORKSPACE_WRAPPER",
- clippy_driver.bin("clippy-driver"),
- )
+ .env("RUSTC_WORKSPACE_WRAPPER", wrapped_clippy_driver())
.with_stderr_contains("[..] (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)")
.run();
}
diff --git a/src/tools/cargo/tests/testsuite/config.rs b/src/tools/cargo/tests/testsuite/config.rs
index 92e1f4264..b0f9d167b 100644
--- a/src/tools/cargo/tests/testsuite/config.rs
+++ b/src/tools/cargo/tests/testsuite/config.rs
@@ -3,7 +3,7 @@
use cargo::core::{PackageIdSpec, Shell};
use cargo::util::config::{self, Config, Definition, SslVersionConfig, StringList};
use cargo::util::interning::InternedString;
-use cargo::util::toml::{self as cargo_toml, VecStringOrBool as VSOB};
+use cargo::util::toml::{self as cargo_toml, TomlDebugInfo, VecStringOrBool as VSOB};
use cargo::CargoResult;
use cargo_test_support::compare;
use cargo_test_support::{panic_error, paths, project, symlink_supported, t};
@@ -401,7 +401,7 @@ lto = false
opt_level: Some(cargo_toml::TomlOptLevel("s".to_string())),
lto: Some(cargo_toml::StringOrBool::Bool(true)),
codegen_units: Some(5),
- debug: Some(cargo_toml::U32OrBool::Bool(true)),
+ debug: Some(cargo_toml::TomlDebugInfo::Full),
debug_assertions: Some(true),
rpath: Some(true),
panic: Some("abort".to_string()),
@@ -444,7 +444,7 @@ fn profile_env_var_prefix() {
.build();
let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
assert_eq!(p.debug_assertions, None);
- assert_eq!(p.debug, Some(cargo_toml::U32OrBool::U32(1)));
+ assert_eq!(p.debug, Some(cargo_toml::TomlDebugInfo::Limited));
let config = ConfigBuilder::new()
.env("CARGO_PROFILE_DEV_DEBUG_ASSERTIONS", "false")
@@ -452,7 +452,7 @@ fn profile_env_var_prefix() {
.build();
let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
assert_eq!(p.debug_assertions, Some(false));
- assert_eq!(p.debug, Some(cargo_toml::U32OrBool::U32(1)));
+ assert_eq!(p.debug, Some(cargo_toml::TomlDebugInfo::Limited));
}
#[cargo_test]
@@ -1511,7 +1511,7 @@ fn all_profile_options() {
lto: Some(cargo_toml::StringOrBool::String("thin".to_string())),
codegen_backend: Some(InternedString::new("example")),
codegen_units: Some(123),
- debug: Some(cargo_toml::U32OrBool::U32(1)),
+ debug: Some(cargo_toml::TomlDebugInfo::Limited),
split_debuginfo: Some("packed".to_string()),
debug_assertions: Some(true),
rpath: Some(true),
@@ -1594,3 +1594,60 @@ known-hosts = [
Definition::Environment("CARGO_NET_SSH_KNOWN_HOSTS".to_string())
);
}
+
+#[cargo_test]
+fn debuginfo_parsing() {
+ let config = ConfigBuilder::new().build();
+ let p: cargo_toml::TomlProfile = config.get("profile.dev").unwrap();
+ assert_eq!(p.debug, None);
+
+ let env_test_cases = [
+ (TomlDebugInfo::None, ["false", "0", "none"].as_slice()),
+ (TomlDebugInfo::LineDirectivesOnly, &["line-directives-only"]),
+ (TomlDebugInfo::LineTablesOnly, &["line-tables-only"]),
+ (TomlDebugInfo::Limited, &["1", "limited"]),
+ (TomlDebugInfo::Full, &["true", "2", "full"]),
+ ];
+ for (expected, config_strs) in env_test_cases {
+ for &val in config_strs {
+ let config = ConfigBuilder::new()
+ .env("CARGO_PROFILE_DEV_DEBUG", val)
+ .build();
+ let debug: TomlDebugInfo = config.get("profile.dev.debug").unwrap();
+ assert_eq!(debug, expected, "failed to parse {val}");
+ }
+ }
+
+ let toml_test_cases = [
+ (TomlDebugInfo::None, ["false", "0", "\"none\""].as_slice()),
+ (
+ TomlDebugInfo::LineDirectivesOnly,
+ &["\"line-directives-only\""],
+ ),
+ (TomlDebugInfo::LineTablesOnly, &["\"line-tables-only\""]),
+ (TomlDebugInfo::Limited, &["1", "\"limited\""]),
+ (TomlDebugInfo::Full, &["true", "2", "\"full\""]),
+ ];
+ for (expected, config_strs) in toml_test_cases {
+ for &val in config_strs {
+ let config = ConfigBuilder::new()
+ .config_arg(format!("profile.dev.debug={val}"))
+ .build();
+ let debug: TomlDebugInfo = config.get("profile.dev.debug").unwrap();
+ assert_eq!(debug, expected, "failed to parse {val}");
+ }
+ }
+
+ let toml_err_cases = ["\"\"", "\"unrecognized\"", "3"];
+ for err_val in toml_err_cases {
+ let config = ConfigBuilder::new()
+ .config_arg(format!("profile.dev.debug={err_val}"))
+ .build();
+ let err = config
+ .get::<TomlDebugInfo>("profile.dev.debug")
+ .unwrap_err();
+ assert!(err
+ .to_string()
+ .ends_with("could not load config key `profile.dev.debug`"));
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/features_namespaced.rs b/src/tools/cargo/tests/testsuite/features_namespaced.rs
index 8ec2fc2e3..f24186c15 100644
--- a/src/tools/cargo/tests/testsuite/features_namespaced.rs
+++ b/src/tools/cargo/tests/testsuite/features_namespaced.rs
@@ -609,6 +609,7 @@ fn json_exposed() {
}
],
"workspace_members": "{...}",
+ "workspace_default_members": "{...}",
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
@@ -942,6 +943,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.1.0"
}
"#,
@@ -1057,6 +1059,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.1.0"
}
"#,
@@ -1213,3 +1216,81 @@ Caused by:
)
.run();
}
+
+#[cargo_test]
+fn dep_feature_when_hidden() {
+ // Checks for behavior with dep:bar and bar/feat syntax when there is no
+ // `bar` feature.
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = { path = "bar", optional = true }
+
+ [features]
+ f1 = ["dep:bar"]
+ f2 = ["bar/bar_feat"]
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .file(
+ "bar/Cargo.toml",
+ r#"
+ [package]
+ name = "bar"
+ version = "0.1.0"
+
+ [features]
+ bar_feat = []
+ "#,
+ )
+ .file("bar/src/lib.rs", "")
+ .build();
+
+ p.cargo("tree -f")
+ .arg("{p} features={f}")
+ .with_stdout(
+ "\
+foo v0.1.0 ([ROOT]/foo) features=",
+ )
+ .with_stderr("")
+ .run();
+
+ p.cargo("tree -F f1 -f")
+ .arg("{p} features={f}")
+ .with_stdout(
+ "\
+foo v0.1.0 ([ROOT]/foo) features=f1
+└── bar v0.1.0 ([ROOT]/foo/bar) features=
+",
+ )
+ .with_stderr("")
+ .run();
+
+ p.cargo("tree -F f2 -f")
+ .arg("{p} features={f}")
+ .with_stdout(
+ "\
+foo v0.1.0 ([ROOT]/foo) features=f2
+└── bar v0.1.0 ([ROOT]/foo/bar) features=bar_feat
+",
+ )
+ .with_stderr("")
+ .run();
+
+ p.cargo("tree --all-features -f")
+ .arg("{p} features={f}")
+ .with_stdout(
+ "\
+foo v0.1.0 ([ROOT]/foo) features=f1,f2
+└── bar v0.1.0 ([ROOT]/foo/bar) features=bar_feat
+",
+ )
+ .with_stderr("")
+ .run();
+}
diff --git a/src/tools/cargo/tests/testsuite/fix.rs b/src/tools/cargo/tests/testsuite/fix.rs
index 54a021c03..33de721cd 100644
--- a/src/tools/cargo/tests/testsuite/fix.rs
+++ b/src/tools/cargo/tests/testsuite/fix.rs
@@ -5,8 +5,8 @@ use cargo_test_support::compare::assert_match_exact;
use cargo_test_support::git::{self, init};
use cargo_test_support::paths::{self, CargoPathExt};
use cargo_test_support::registry::{Dependency, Package};
-use cargo_test_support::tools;
-use cargo_test_support::{basic_manifest, is_nightly, project};
+use cargo_test_support::{basic_manifest, is_nightly, project, Project};
+use cargo_test_support::{tools, wrapped_clippy_driver};
#[cargo_test]
fn do_not_fix_broken_builds() {
@@ -53,8 +53,7 @@ fn fix_broken_if_requested() {
.run();
}
-#[cargo_test]
-fn broken_fixes_backed_out() {
+fn rustc_shim_for_cargo_fix() -> Project {
// This works as follows:
// - Create a `rustc` shim (the "foo" project) which will pretend that the
// verification step fails.
@@ -109,7 +108,6 @@ fn broken_fixes_backed_out() {
fs::File::create(&first).unwrap();
}
}
-
let status = Command::new("rustc")
.args(env::args().skip(1))
.status()
@@ -142,11 +140,60 @@ fn broken_fixes_backed_out() {
// Build our rustc shim
p.cargo("build").cwd("foo").run();
- // Attempt to fix code, but our shim will always fail the second compile
+ p
+}
+
+#[cargo_test]
+fn broken_fixes_backed_out() {
+ let p = rustc_shim_for_cargo_fix();
+ // Attempt to fix code, but our shim will always fail the second compile.
+ p.cargo("fix --allow-no-vcs --lib")
+ .cwd("bar")
+ .env("__CARGO_FIX_YOLO", "1")
+ .env("RUSTC", p.root().join("foo/target/debug/foo"))
+ .with_stderr_contains(
+ "warning: failed to automatically apply fixes suggested by rustc \
+ to crate `bar`\n\
+ \n\
+ after fixes were automatically applied the compiler reported \
+ errors within these files:\n\
+ \n \
+ * src/lib.rs\n\
+ \n\
+ This likely indicates a bug in either rustc or cargo itself,\n\
+ and we would appreciate a bug report! You're likely to see \n\
+ a number of compiler warnings after this message which cargo\n\
+ attempted to fix but failed. If you could open an issue at\n\
+ https://github.com/rust-lang/rust/issues\n\
+ quoting the full output of this command we'd be very appreciative!\n\
+ Note that you may be able to make some more progress in the near-term\n\
+ fixing code with the `--broken-code` flag\n\
+ \n\
+ The following errors were reported:\n\
+ error: expected one of `!` or `::`, found `rust`\n\
+ ",
+ )
+ .with_stderr_contains("Original diagnostics will follow.")
+ .with_stderr_contains("[WARNING] variable does not need to be mutable")
+ .with_stderr_does_not_contain("[..][FIXED][..]")
+ .run();
+
+ // Make sure the fix which should have been applied was backed out
+ assert!(p.read_file("bar/src/lib.rs").contains("let mut x = 3;"));
+}
+
+#[cargo_test]
+fn broken_clippy_fixes_backed_out() {
+ let p = rustc_shim_for_cargo_fix();
+ // Attempt to fix code, but our shim will always fail the second compile.
+ // Also, we use `clippy` as a workspace wrapper to make sure that we properly
+ // generate the report bug text.
p.cargo("fix --allow-no-vcs --lib")
.cwd("bar")
.env("__CARGO_FIX_YOLO", "1")
.env("RUSTC", p.root().join("foo/target/debug/foo"))
+ // We can't use `clippy` so we use a `rustc` workspace wrapper instead
+ .env("RUSTC_WORKSPACE_WRAPPER", wrapped_clippy_driver())
.with_stderr_contains(
"warning: failed to automatically apply fixes suggested by rustc \
to crate `bar`\n\
@@ -160,7 +207,7 @@ fn broken_fixes_backed_out() {
and we would appreciate a bug report! You're likely to see \n\
a number of compiler warnings after this message which cargo\n\
attempted to fix but failed. If you could open an issue at\n\
- [..]\n\
+ https://github.com/rust-lang/rust-clippy/issues\n\
quoting the full output of this command we'd be very appreciative!\n\
Note that you may be able to make some more progress in the near-term\n\
fixing code with the `--broken-code` flag\n\
diff --git a/src/tools/cargo/tests/testsuite/git.rs b/src/tools/cargo/tests/testsuite/git.rs
index b170c204f..7c717e967 100644
--- a/src/tools/cargo/tests/testsuite/git.rs
+++ b/src/tools/cargo/tests/testsuite/git.rs
@@ -548,90 +548,6 @@ Caused by:
}
#[cargo_test]
-fn two_revs_same_deps() {
- let bar = git::new("meta-dep", |project| {
- project
- .file("Cargo.toml", &basic_manifest("bar", "0.0.0"))
- .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
- });
-
- let repo = git2::Repository::open(&bar.root()).unwrap();
- let rev1 = repo.revparse_single("HEAD").unwrap().id();
-
- // Commit the changes and make sure we trigger a recompile
- bar.change_file("src/lib.rs", "pub fn bar() -> i32 { 2 }");
- git::add(&repo);
- let rev2 = git::commit(&repo);
-
- let foo = project()
- .file(
- "Cargo.toml",
- &format!(
- r#"
- [package]
- name = "foo"
- version = "0.0.0"
- authors = []
-
- [dependencies.bar]
- git = '{}'
- rev = "{}"
-
- [dependencies.baz]
- path = "../baz"
- "#,
- bar.url(),
- rev1
- ),
- )
- .file(
- "src/main.rs",
- r#"
- extern crate bar;
- extern crate baz;
-
- fn main() {
- assert_eq!(bar::bar(), 1);
- assert_eq!(baz::baz(), 2);
- }
- "#,
- )
- .build();
-
- let _baz = project()
- .at("baz")
- .file(
- "Cargo.toml",
- &format!(
- r#"
- [package]
- name = "baz"
- version = "0.0.0"
- authors = []
-
- [dependencies.bar]
- git = '{}'
- rev = "{}"
- "#,
- bar.url(),
- rev2
- ),
- )
- .file(
- "src/lib.rs",
- r#"
- extern crate bar;
- pub fn baz() -> i32 { bar::bar() }
- "#,
- )
- .build();
-
- foo.cargo("build -v").run();
- assert!(foo.bin("foo").is_file());
- foo.process(&foo.bin("foo")).run();
-}
-
-#[cargo_test]
fn recompilation() {
let git_project = git::new("bar", |project| {
project
@@ -2795,7 +2711,7 @@ fn use_the_cli() {
[UPDATING] git repository `[..]`
[RUNNING] `git fetch [..]`
From [..]
- * [new ref] -> origin/HEAD
+ * [new ref] [..] -> origin/HEAD[..]
[CHECKING] dep1 [..]
[RUNNING] `rustc [..]`
[CHECKING] foo [..]
@@ -3421,6 +3337,9 @@ fn metadata_master_consistency() {
"workspace_members": [
"foo 0.1.0 [..]"
],
+ "workspace_default_members": [
+ "foo 0.1.0 [..]"
+ ],
"resolve": {
"nodes": [
{
diff --git a/src/tools/cargo/tests/testsuite/git_shallow.rs b/src/tools/cargo/tests/testsuite/git_shallow.rs
new file mode 100644
index 000000000..8045880cf
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/git_shallow.rs
@@ -0,0 +1,831 @@
+use crate::git_gc::find_index;
+use cargo_test_support::registry::Package;
+use cargo_test_support::{basic_manifest, git, paths, project};
+
+enum RepoMode {
+ Shallow,
+ Complete,
+}
+
+#[cargo_test]
+fn gitoxide_clones_shallow_two_revs_same_deps() {
+ perform_two_revs_same_deps(true)
+}
+
+fn perform_two_revs_same_deps(shallow: bool) {
+ let bar = git::new("meta-dep", |project| {
+ project
+ .file("Cargo.toml", &basic_manifest("bar", "0.0.0"))
+ .file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
+ });
+
+ let repo = git2::Repository::open(&bar.root()).unwrap();
+ let rev1 = repo.revparse_single("HEAD").unwrap().id();
+
+ // Commit the changes and make sure we trigger a recompile
+ bar.change_file("src/lib.rs", "pub fn bar() -> i32 { 2 }");
+ git::add(&repo);
+ let rev2 = git::commit(&repo);
+
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.0"
+ authors = []
+
+ [dependencies.bar]
+ git = '{}'
+ rev = "{}"
+
+ [dependencies.baz]
+ path = "../baz"
+ "#,
+ bar.url(),
+ rev1
+ ),
+ )
+ .file(
+ "src/main.rs",
+ r#"
+ extern crate bar;
+ extern crate baz;
+
+ fn main() {
+ assert_eq!(bar::bar(), 1);
+ assert_eq!(baz::baz(), 2);
+ }
+ "#,
+ )
+ .build();
+
+ let _baz = project()
+ .at("baz")
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "baz"
+ version = "0.0.0"
+ authors = []
+
+ [dependencies.bar]
+ git = '{}'
+ rev = "{}"
+ "#,
+ bar.url(),
+ rev2
+ ),
+ )
+ .file(
+ "src/lib.rs",
+ r#"
+ extern crate bar;
+ pub fn baz() -> i32 { bar::bar() }
+ "#,
+ )
+ .build();
+
+ let args = if shallow {
+ "build -v -Zgitoxide=fetch,shallow-deps"
+ } else {
+ "build -v"
+ };
+ foo.cargo(args)
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+ assert!(foo.bin("foo").is_file());
+ foo.process(&foo.bin("foo")).run();
+}
+
+#[cargo_test]
+fn two_revs_same_deps() {
+ perform_two_revs_same_deps(false)
+}
+
+#[cargo_test]
+fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_with_git2_fetch(
+) -> anyhow::Result<()> {
+ Package::new("bar", "1.0.0").publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+ p.cargo("fetch")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let shallow_repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
+ assert_eq!(
+ shallow_repo
+ .rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "shallow clones always start at depth of 1 to minimize download size"
+ );
+ assert!(shallow_repo.is_shallow());
+
+ Package::new("bar", "1.1.0").publish();
+ p.cargo("update")
+ .env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
+ .run();
+
+ let repo = gix::open_opts(
+ find_remote_index(RepoMode::Complete),
+ gix::open::Options::isolated(),
+ )?;
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 3,
+ "an entirely new repo was cloned which is never shallow"
+ );
+ assert!(!repo.is_shallow());
+ Ok(())
+}
+
+#[cargo_test]
+fn gitoxide_clones_git_dependency_with_shallow_protocol_and_git2_is_used_for_followup_fetches(
+) -> anyhow::Result<()> {
+ // Example where an old lockfile with an explicit branch="master" in Cargo.toml.
+ Package::new("bar", "1.0.0").publish();
+ let (bar, bar_repo) = git::new_repo("bar", |p| {
+ p.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
+ .file("src/lib.rs", "")
+ });
+
+ bar.change_file("src/lib.rs", "// change");
+ git::add(&bar_repo);
+ git::commit(&bar_repo);
+
+ {
+ let mut walk = bar_repo.revwalk()?;
+ walk.push_head()?;
+ assert_eq!(
+ walk.count(),
+ 2,
+ "original repo has initial commit and change commit"
+ );
+ }
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = {{ version = "1.0", git = "{}", branch = "master" }}
+ "#,
+ bar.url()
+ ),
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let db_clone = gix::open_opts(
+ find_bar_db(RepoMode::Shallow),
+ gix::open::Options::isolated(),
+ )?;
+ assert!(db_clone.is_shallow());
+ assert_eq!(
+ db_clone
+ .rev_parse_single("origin/master")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "db clones are shallow and have a shortened history"
+ );
+
+ let dep_checkout = gix::open_opts(
+ find_lexicographically_first_bar_checkout(),
+ gix::open::Options::isolated(),
+ )?;
+ assert!(dep_checkout.is_shallow());
+ assert_eq!(
+ dep_checkout.head_id()?.ancestors().all()?.count(),
+ 1,
+ "db checkouts are hard-linked clones with the shallow file copied separately."
+ );
+
+ bar.change_file("src/lib.rs", "// another change");
+ git::add(&bar_repo);
+ git::commit(&bar_repo);
+ {
+ let mut walk = bar_repo.revwalk()?;
+ walk.push_head()?;
+ assert_eq!(
+ walk.count(),
+ 3,
+ "original repo has initial commit and change commit, and another change"
+ );
+ }
+
+ p.cargo("update")
+ .env("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2", "0")
+ .run();
+
+ let db_clone = gix::open_opts(
+ find_bar_db(RepoMode::Complete),
+ gix::open::Options::isolated(),
+ )?;
+ assert_eq!(
+ db_clone
+ .rev_parse_single("origin/master")?
+ .ancestors()
+ .all()?
+ .count(),
+ 3,
+ "the db clone was re-initialized and has all commits"
+ );
+ assert!(
+ !db_clone.is_shallow(),
+ "shallow-ness was removed as git2 does not support it"
+ );
+ assert_eq!(
+ dep_checkout.head_id()?.ancestors().all()?.count(),
+ 1,
+ "the original dep checkout didn't change - there is a new one for each update we get locally"
+ );
+
+ let max_history_depth = glob::glob(
+ paths::home()
+ .join(".cargo/git/checkouts/bar-*/*/.git")
+ .to_str()
+ .unwrap(),
+ )?
+ .map(|path| -> anyhow::Result<usize> {
+ let dep_checkout = gix::open_opts(path?, gix::open::Options::isolated())?;
+ let depth = dep_checkout.head_id()?.ancestors().all()?.count();
+ assert_eq!(dep_checkout.is_shallow(), depth == 1, "the first checkout is done with gitoxide and shallow, the second one is git2 non-shallow");
+ Ok(depth)
+ })
+ .map(Result::unwrap)
+ .max()
+ .expect("two checkout repos");
+
+ assert_eq!(
+ max_history_depth, 3,
+ "the new checkout sees all commits of the non-shallow DB repository"
+ );
+
+ Ok(())
+}
+
+#[cargo_test]
+fn gitoxide_shallow_clone_followed_by_non_shallow_update() -> anyhow::Result<()> {
+ Package::new("bar", "1.0.0").publish();
+ let (bar, bar_repo) = git::new_repo("bar", |p| {
+ p.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
+ .file("src/lib.rs", "")
+ });
+
+ bar.change_file("src/lib.rs", "// change");
+ git::add(&bar_repo);
+ git::commit(&bar_repo);
+
+ {
+ let mut walk = bar_repo.revwalk()?;
+ walk.push_head()?;
+ assert_eq!(
+ walk.count(),
+ 2,
+ "original repo has initial commit and change commit"
+ );
+ }
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = {{ version = "1.0", git = "{}", branch = "master" }}
+ "#,
+ bar.url()
+ ),
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let shallow_db_clone = gix::open_opts(
+ find_bar_db(RepoMode::Shallow),
+ gix::open::Options::isolated(),
+ )?;
+ assert!(shallow_db_clone.is_shallow());
+ assert_eq!(
+ shallow_db_clone
+ .rev_parse_single("origin/master")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "db clones are shallow and have a shortened history"
+ );
+
+ let dep_checkout = gix::open_opts(
+ find_lexicographically_first_bar_checkout(),
+ gix::open::Options::isolated(),
+ )?;
+ assert!(dep_checkout.is_shallow());
+ assert_eq!(
+ dep_checkout.head_id()?.ancestors().all()?.count(),
+ 1,
+ "db checkouts are hard-linked clones with the shallow file copied separately."
+ );
+
+ bar.change_file("src/lib.rs", "// another change");
+ git::add(&bar_repo);
+ git::commit(&bar_repo);
+ {
+ let mut walk = bar_repo.revwalk()?;
+ walk.push_head()?;
+ assert_eq!(
+ walk.count(),
+ 3,
+ "original repo has initial commit and change commit, and another change"
+ );
+ }
+
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch") // shallow-deps is omitted intentionally
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let db_clone = gix::open_opts(
+ find_bar_db(RepoMode::Complete),
+ gix::open::Options::isolated(),
+ )?;
+ assert_eq!(
+ db_clone
+ .rev_parse_single("origin/master")?
+ .ancestors()
+ .all()?
+ .count(),
+ 3,
+ "we created an entirely new non-shallow clone"
+ );
+ assert!(!db_clone.is_shallow());
+ assert_eq!(
+ dep_checkout.head_id()?.ancestors().all()?.count(),
+ 1,
+ "the original dep checkout didn't change - there is a new one for each update we get locally"
+ );
+
+ let max_history_depth = glob::glob(
+ paths::home()
+ .join(".cargo/git/checkouts/bar-*/*/.git")
+ .to_str()
+ .unwrap(),
+ )?
+ .map(|path| -> anyhow::Result<usize> {
+ let path = path?;
+ let dep_checkout = gix::open_opts(&path, gix::open::Options::isolated())?;
+ assert_eq!(
+ dep_checkout.is_shallow(),
+ path.to_string_lossy().contains("-shallow"),
+ "checkouts of shallow db repos are shallow as well"
+ );
+ let depth = dep_checkout.head_id()?.ancestors().all()?.count();
+ Ok(depth)
+ })
+ .map(Result::unwrap)
+ .max()
+ .expect("two checkout repos");
+
+ assert_eq!(
+ max_history_depth, 3,
+ "we see the previous shallow checkout as well as new new unshallow one"
+ );
+
+ Ok(())
+}
+
+#[cargo_test]
+fn gitoxide_clones_registry_with_shallow_protocol_and_follow_up_fetch_maintains_shallowness(
+) -> anyhow::Result<()> {
+ Package::new("bar", "1.0.0").publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+ p.cargo("fetch")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "shallow clones always start at depth of 1 to minimize download size"
+ );
+ assert!(repo.is_shallow());
+
+ Package::new("bar", "1.1.0").publish();
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-index") // NOTE: the flag needs to be consistent or else a different index is created
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "subsequent shallow fetches wont' fetch what's inbetween, only the single commit that we need while leveraging existing commits"
+ );
+ assert!(repo.is_shallow());
+
+ Package::new("bar", "1.2.0").publish();
+ Package::new("bar", "1.3.0").publish();
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "shallow boundaries are moved with each fetch to maintain only a single commit of history"
+ );
+ assert!(repo.is_shallow());
+
+ Ok(())
+}
+
+/// If there is shallow *and* non-shallow clones, non-shallow will naturally be returned due to sort order.
+#[cargo_test]
+fn gitoxide_clones_registry_without_shallow_protocol_and_follow_up_fetch_uses_shallowness(
+) -> anyhow::Result<()> {
+ Package::new("bar", "1.0.0").publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+ p.cargo("fetch")
+ .arg("-Zgitoxide=fetch")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 2,
+ "initial commit and the first crate"
+ );
+ assert!(!repo.is_shallow());
+
+ Package::new("bar", "1.1.0").publish();
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let shallow_repo = gix::open_opts(
+ find_remote_index(RepoMode::Shallow),
+ gix::open::Options::isolated(),
+ )?;
+ assert_eq!(
+ shallow_repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "the follow up clones an entirely new index which is now shallow and which is in its own location"
+ );
+ assert!(shallow_repo.is_shallow());
+
+ Package::new("bar", "1.2.0").publish();
+ Package::new("bar", "1.3.0").publish();
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ assert_eq!(
+ shallow_repo
+ .rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "subsequent shallow fetches wont' fetch what's inbetween, only the single commit that we need while leveraging existing commits"
+ );
+ assert!(shallow_repo.is_shallow());
+
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 5,
+ "we can separately fetch the non-shallow index as well and it sees all commits"
+ );
+
+ Ok(())
+}
+
+#[cargo_test]
+fn gitoxide_git_dependencies_switch_from_branch_to_rev() -> anyhow::Result<()> {
+ // db exists from previous build, then dependency changes to refer to revision that isn't
+ // available in the shallow clone.
+
+ let (bar, bar_repo) = git::new_repo("bar", |p| {
+ p.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
+ .file("src/lib.rs", "")
+ });
+
+ // this commit would not be available in a shallow clone.
+ let first_commit_pre_change = bar_repo.head().unwrap().target().unwrap();
+
+ bar.change_file("src/lib.rs", "// change");
+ git::add(&bar_repo);
+ git::commit(&bar_repo);
+ let p = project()
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = {{ git = "{}", branch = "master" }}
+ "#,
+ bar.url(),
+ ),
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("check")
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let db_clone = gix::open_opts(
+ find_bar_db(RepoMode::Shallow),
+ gix::open::Options::isolated(),
+ )?;
+ assert!(db_clone.is_shallow());
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = {{ git = "{}", rev = "{}" }}
+ "#,
+ bar.url(),
+ first_commit_pre_change
+ ),
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("check")
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ assert!(
+ db_clone.is_shallow(),
+ "we maintain shallowness and never unshallow"
+ );
+
+ Ok(())
+}
+
+#[cargo_test]
+fn shallow_deps_work_with_revisions_and_branches_mixed_on_same_dependency() -> anyhow::Result<()> {
+ let (bar, bar_repo) = git::new_repo("bar", |p| {
+ p.file("Cargo.toml", &basic_manifest("bar", "1.0.0"))
+ .file("src/lib.rs", "")
+ });
+
+ // this commit would not be available in a shallow clone.
+ let first_commit_pre_change = bar_repo.head().unwrap().target().unwrap();
+
+ bar.change_file("src/lib.rs", "// change");
+ git::add(&bar_repo);
+ git::commit(&bar_repo);
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ &format!(
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar-renamed = {{ package = "bar", git = "{}", rev = "{}" }}
+ bar = {{ git = "{}", branch = "master" }}
+ "#,
+ bar.url(),
+ first_commit_pre_change,
+ bar.url(),
+ ),
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("check")
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let db_paths = glob::glob(paths::home().join(".cargo/git/db/bar-*").to_str().unwrap())?
+ .map(Result::unwrap)
+ .collect::<Vec<_>>();
+ assert_eq!(
+ db_paths.len(),
+ 1,
+ "only one db checkout source is used per dependency"
+ );
+ let db_clone = gix::open_opts(&db_paths[0], gix::open::Options::isolated())?;
+ assert!(
+ db_clone.is_shallow(),
+ "the repo is shallow while having all data it needs"
+ );
+
+ Ok(())
+}
+
+#[cargo_test]
+fn gitoxide_clones_registry_with_shallow_protocol_and_aborts_and_updates_again(
+) -> anyhow::Result<()> {
+ Package::new("bar", "1.0.0").publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+ p.cargo("fetch")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ let repo = gix::open_opts(find_index(), gix::open::Options::isolated())?;
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "shallow clones always start at depth of 1 to minimize download size"
+ );
+ assert!(repo.is_shallow());
+ let shallow_lock = repo.shallow_file().with_extension("lock");
+ // adding a lock file and deleting the original simulates a left-over clone that was aborted, leaving a lock file
+ // in place without ever having moved it to the right location.
+ std::fs::write(&shallow_lock, &[])?;
+ std::fs::remove_file(repo.shallow_file())?;
+
+ Package::new("bar", "1.1.0").publish();
+ p.cargo("update")
+ .arg("-Zgitoxide=fetch,shallow-index")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
+ .run();
+
+ assert!(!shallow_lock.is_file(), "the repository was re-initialized");
+ assert!(repo.is_shallow());
+ assert_eq!(
+ repo.rev_parse_single("origin/HEAD")?
+ .ancestors()
+ .all()?
+ .count(),
+ 1,
+ "it's a fresh shallow clone - otherwise it would have 2 commits if the previous shallow clone would still be present"
+ );
+
+ Ok(())
+}
+
+fn find_lexicographically_first_bar_checkout() -> std::path::PathBuf {
+ glob::glob(
+ paths::home()
+ .join(".cargo/git/checkouts/bar-*/*/.git")
+ .to_str()
+ .unwrap(),
+ )
+ .unwrap()
+ .next()
+ .unwrap()
+ .unwrap()
+ .to_owned()
+}
+
+fn find_remote_index(mode: RepoMode) -> std::path::PathBuf {
+ glob::glob(
+ paths::home()
+ .join(".cargo/registry/index/*")
+ .to_str()
+ .unwrap(),
+ )
+ .unwrap()
+ .map(Result::unwrap)
+ .filter(|p| p.to_string_lossy().ends_with("-shallow") == matches!(mode, RepoMode::Shallow))
+ .next()
+ .unwrap()
+}
+
+/// Find a checkout directory for bar, `shallow` or not.
+fn find_bar_db(mode: RepoMode) -> std::path::PathBuf {
+ glob::glob(paths::home().join(".cargo/git/db/bar-*").to_str().unwrap())
+ .unwrap()
+ .map(Result::unwrap)
+ .filter(|p| p.to_string_lossy().ends_with("-shallow") == matches!(mode, RepoMode::Shallow))
+ .next()
+ .unwrap()
+ .to_owned()
+}
diff --git a/src/tools/cargo/tests/testsuite/https.rs b/src/tools/cargo/tests/testsuite/https.rs
index 501eeae05..c7aec9111 100644
--- a/src/tools/cargo/tests/testsuite/https.rs
+++ b/src/tools/cargo/tests/testsuite/https.rs
@@ -30,7 +30,7 @@ fn self_signed_should_fail() {
.build();
// I think the text here depends on the curl backend.
let err_msg = if cfg!(target_os = "macos") {
- "unexpected return value from ssl handshake -9806; class=Ssl (16)"
+ "untrusted connection error; class=Ssl (16); code=Certificate (-17)"
} else if cfg!(unix) {
"the SSL certificate is invalid; class=Ssl (16); code=Certificate (-17)"
} else if cfg!(windows) {
diff --git a/src/tools/cargo/tests/testsuite/inheritable_workspace_fields.rs b/src/tools/cargo/tests/testsuite/inheritable_workspace_fields.rs
index 92c96b985..cc261a47f 100644
--- a/src/tools/cargo/tests/testsuite/inheritable_workspace_fields.rs
+++ b/src/tools/cargo/tests/testsuite/inheritable_workspace_fields.rs
@@ -201,6 +201,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"readme": null,
"readme_file": null,
"repository": "https://github.com/example/example",
+ "rust_version": "1.60",
"vers": "1.2.3"
}
"#,
@@ -376,6 +377,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.2.0"
}
"#,
@@ -503,6 +505,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.2.0"
}
"#,
@@ -734,6 +737,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"readme": "README.md",
"readme_file": "../README.md",
"repository": "https://github.com/example/example",
+ "rust_version": "1.60",
"vers": "1.2.3"
}
"#,
@@ -917,6 +921,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.2.0"
}
"#,
@@ -1269,7 +1274,9 @@ fn error_workspace_dependency_looked_for_workspace_itself() {
.with_stderr(
"\
[WARNING] [CWD]/Cargo.toml: unused manifest key: workspace.dependencies.dep.workspace
-[WARNING] [CWD]/Cargo.toml: dependency (dep) specified without providing a local path, Git repository, or version to use. This will be considered an error in future versions
+[WARNING] [CWD]/Cargo.toml: dependency (dep) specified without providing a local path, Git repository, version, \
+or workspace dependency to use. \
+This will be considered an error in future versions
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `dep` found
location searched: registry `crates-io`
@@ -1589,7 +1596,9 @@ fn cannot_inherit_in_patch() {
.with_stderr(
"\
[WARNING] [CWD]/Cargo.toml: unused manifest key: patch.crates-io.bar.workspace
-[WARNING] [CWD]/Cargo.toml: dependency (bar) specified without providing a local path, Git repository, or version to use. This will be considered an error in future versions
+[WARNING] [CWD]/Cargo.toml: dependency (bar) specified without providing a local path, Git repository, version, \
+or workspace dependency to use. \
+This will be considered an error in future versions
[UPDATING] `dummy-registry` index
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml
new file mode 100644
index 000000000..b7a2e9036
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/Cargo.toml
@@ -0,0 +1,21 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
+version = "1.2.3"
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/README.md b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/README.md
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/README.md
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs
new file mode 100644
index 000000000..43f0dac5e
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/crates/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Check that our file is not overwritten")
+}
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/in/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/mod.rs b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/mod.rs
new file mode 100644
index 000000000..4e1dda845
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/mod.rs
@@ -0,0 +1,22 @@
+use cargo_test_support::compare::assert_ui;
+use cargo_test_support::curr_dir;
+use cargo_test_support::CargoCommand;
+use cargo_test_support::Project;
+
+#[cargo_test]
+fn case() {
+ let project = Project::from_template(curr_dir!().join("in"));
+ let project_root = project.root();
+ let cwd = &project_root;
+
+ snapbox::cmd::Command::cargo_ui()
+ .arg("init")
+ .args(["crates/foo"])
+ .current_dir(cwd)
+ .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);
+}
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml
new file mode 100644
index 000000000..b7a2e9036
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/Cargo.toml
@@ -0,0 +1,21 @@
+[workspace]
+members = [
+ "crates/*",
+]
+
+[workspace.package]
+authors = ["Rustaceans"]
+description = "foo"
+edition = "2018"
+homepage = "foo"
+keywords = ["foo", "bar"]
+readme = "README.md"
+rust-version = "1.67.0"
+categories = ["algorithms"]
+documentation = "foo"
+exclude = ["foo"]
+include = ["foo"]
+license = "MIT OR Apache-2.0"
+publish = false
+repository = "foo"
+version = "1.2.3"
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml
new file mode 100644
index 000000000..137ed1c87
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "foo"
+authors.workspace = true
+description.workspace = true
+edition.workspace = true
+homepage.workspace = true
+keywords.workspace = true
+readme.workspace = true
+rust-version.workspace = true
+categories.workspace = true
+documentation.workspace = true
+exclude.workspace = true
+include.workspace = true
+license.workspace = true
+publish.workspace = true
+repository.workspace = true
+version.workspace = true
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs
new file mode 100644
index 000000000..43f0dac5e
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/crates/foo/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Check that our file is not overwritten")
+}
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs
new file mode 100644
index 000000000..7d12d9af8
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/out/src/lib.rs
@@ -0,0 +1,14 @@
+pub fn add(left: usize, right: usize) -> usize {
+ left + right
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn it_works() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+}
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stderr.log b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stderr.log
new file mode 100644
index 000000000..3847e4e4a
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stderr.log
@@ -0,0 +1 @@
+ Created binary (application) package
diff --git a/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stdout.log b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stdout.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/init/inherit_workspace_package_table/stdout.log
diff --git a/src/tools/cargo/tests/testsuite/init/mod.rs b/src/tools/cargo/tests/testsuite/init/mod.rs
index 99df9d39d..7853a1a0b 100644
--- a/src/tools/cargo/tests/testsuite/init/mod.rs
+++ b/src/tools/cargo/tests/testsuite/init/mod.rs
@@ -21,6 +21,7 @@ mod git_ignore_exists_no_conflicting_entries;
mod ignores_failure_to_format_source;
mod inferred_bin_with_git;
mod inferred_lib_with_git;
+mod inherit_workspace_package_table;
mod invalid_dir_name;
mod lib_already_exists_nosrc;
mod lib_already_exists_src;
diff --git a/src/tools/cargo/tests/testsuite/install.rs b/src/tools/cargo/tests/testsuite/install.rs
index dd9844f17..9b881dfdc 100644
--- a/src/tools/cargo/tests/testsuite/install.rs
+++ b/src/tools/cargo/tests/testsuite/install.rs
@@ -1416,6 +1416,46 @@ fn path_install_workspace_root_despite_default_members() {
}
#[cargo_test]
+fn git_install_workspace_root_despite_default_members() {
+ let p = git::repo(&paths::root().join("foo"))
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "ws-root"
+ version = "0.1.0"
+ authors = []
+
+ [workspace]
+ members = ["ws-member"]
+ default-members = ["ws-member"]
+ "#,
+ )
+ .file("src/main.rs", "fn main() {}")
+ .file(
+ "ws-member/Cargo.toml",
+ r#"
+ [package]
+ name = "ws-member"
+ version = "0.1.0"
+ authors = []
+ "#,
+ )
+ .file("ws-member/src/main.rs", "fn main() {}")
+ .build();
+
+ cargo_process("install --git")
+ .arg(p.url().to_string())
+ .arg("ws-root")
+ .with_stderr_contains(
+ "[INSTALLED] package `ws-root v0.1.0 ([..])` (executable `ws-root[EXE]`)",
+ )
+ // Particularly avoid "Installed package `ws-root v0.1.0 ([..]])` (executable `ws-member`)":
+ .with_stderr_does_not_contain("ws-member")
+ .run();
+}
+
+#[cargo_test]
fn dev_dependencies_no_check() {
Package::new("foo", "1.0.0").publish();
let p = project()
@@ -2287,3 +2327,84 @@ fn sparse_install() {
"#,
);
}
+
+#[cargo_test]
+fn self_referential() {
+ // Some packages build-dep on prior versions of themselves.
+ Package::new("foo", "0.0.1")
+ .file("src/lib.rs", "fn hello() {}")
+ .file("src/main.rs", "fn main() {}")
+ .file("build.rs", "fn main() {}")
+ .publish();
+ Package::new("foo", "0.0.2")
+ .file("src/lib.rs", "fn hello() {}")
+ .file("src/main.rs", "fn main() {}")
+ .file("build.rs", "fn main() {}")
+ .build_dep("foo", "0.0.1")
+ .publish();
+
+ cargo_process("install foo")
+ .with_stderr(
+ "\
+[UPDATING] `[..]` index
+[DOWNLOADING] crates ...
+[DOWNLOADED] foo v0.0.2 (registry [..])
+[INSTALLING] foo v0.0.2
+[DOWNLOADING] crates ...
+[DOWNLOADED] foo v0.0.1 (registry [..])
+[COMPILING] foo v0.0.1
+[COMPILING] foo v0.0.2
+[FINISHED] release [optimized] target(s) in [..]
+[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
+[INSTALLED] package `foo v0.0.2` (executable `foo[EXE]`)
+[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
+",
+ )
+ .run();
+ assert_has_installed_exe(cargo_home(), "foo");
+}
+
+#[cargo_test]
+fn ambiguous_registry_vs_local_package() {
+ // Correctly install 'foo' from a local package, even if that package also
+ // depends on a registry dependency named 'foo'.
+ Package::new("foo", "0.0.1")
+ .file("src/lib.rs", "fn hello() {}")
+ .publish();
+
+ let p = project()
+ .file("src/main.rs", "fn main() {}")
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+ edition = "2021"
+
+ [dependencies]
+ foo = "0.0.1"
+ "#,
+ )
+ .build();
+
+ cargo_process("install --path")
+ .arg(p.root())
+ .with_stderr(
+ "\
+[INSTALLING] foo v0.1.0 ([..])
+[UPDATING] `[..]` index
+[DOWNLOADING] crates ...
+[DOWNLOADED] foo v0.0.1 (registry [..])
+[COMPILING] foo v0.0.1
+[COMPILING] foo v0.1.0 ([..])
+[FINISHED] release [optimized] target(s) in [..]
+[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
+[INSTALLED] package `foo v0.1.0 ([..])` (executable `foo[EXE]`)
+[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
+",
+ )
+ .run();
+ assert_has_installed_exe(cargo_home(), "foo");
+}
diff --git a/src/tools/cargo/tests/testsuite/lints.rs b/src/tools/cargo/tests/testsuite/lints.rs
new file mode 100644
index 000000000..fb31da30a
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/lints.rs
@@ -0,0 +1,639 @@
+//! Tests for `[lints]`
+
+use cargo_test_support::project;
+use cargo_test_support::registry::Package;
+
+#[cargo_test]
+fn package_requires_option() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lints.rust]
+ unsafe_code = "forbid"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check")
+ .with_stderr(
+ "\
+warning: unused manifest key `lints` (may be supported in a future version)
+
+this Cargo does not support nightly features, but if you
+switch to nightly channel you can pass
+`-Zlints` to enable this feature.
+[CHECKING] [..]
+[FINISHED] [..]
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn workspace_requires_option() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [workspace.lints.rust]
+ unsafe_code = "forbid"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check")
+ .with_stderr(
+ "\
+warning: [CWD]/Cargo.toml: unused manifest key `lints` (may be supported in a future version)
+
+this Cargo does not support nightly features, but if you
+switch to nightly channel you can pass
+`-Zlints` to enable this feature.
+[CHECKING] [..]
+[FINISHED] [..]
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn dependency_warning_ignored() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies]
+ bar.path = "../bar"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ let _bar = project()
+ .at("bar")
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "bar"
+ version = "0.0.1"
+ authors = []
+
+ [lints.rust]
+ unsafe_code = "forbid"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check")
+ .with_stderr(
+ "\
+[CHECKING] [..]
+[CHECKING] [..]
+[FINISHED] [..]
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn malformed_on_stable() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ lints = 20
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check")
+ .with_stderr(
+ "\
+warning: unused manifest key `lints` (may be supported in a future version)
+
+this Cargo does not support nightly features, but if you
+switch to nightly channel you can pass
+`-Zlints` to enable this feature.
+[CHECKING] [..]
+[FINISHED] [..]
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn malformed_on_nightly() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ lints = 20
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr(
+ "\
+error: failed to parse manifest[..]
+
+Caused by:
+ invalid type: integer `20`, expected a map
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn fail_on_invalid_tool() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [workspace.lints.super-awesome-linter]
+ unsafe_code = "forbid"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr(
+ "\
+[..]
+
+Caused by:
+ unsupported `super-awesome-linter` in `[lints]`, must be one of rust, clippy, rustdoc
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn fail_on_tool_injection() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [workspace.lints.rust]
+ "clippy::cyclomatic_complexity" = "warn"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr(
+ "\
+[..]
+
+Caused by:
+ `lints.rust.clippy::cyclomatic_complexity` is not valid lint name; try `lints.clippy.cyclomatic_complexity`
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn fail_on_redundant_tool() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [workspace.lints.rust]
+ "rust::unsafe_code" = "forbid"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr(
+ "\
+[..]
+
+Caused by:
+ `lints.rust.rust::unsafe_code` is not valid lint name; try `lints.rust.unsafe_code`
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn fail_on_conflicting_tool() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [workspace.lints.rust]
+ "super-awesome-tool::unsafe_code" = "forbid"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr(
+ "\
+[..]
+
+Caused by:
+ `lints.rust.super-awesome-tool::unsafe_code` is not a valid lint name
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn package_lint_deny() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lints.rust]
+ "unsafe_code" = "deny"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+pub fn foo(num: i32) -> u32 {
+ unsafe { std::mem::transmute(num) }
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr_contains(
+ "\
+error: usage of an `unsafe` block
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn workspace_lint_deny() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lints]
+ workspace = true
+
+ [workspace.lints.rust]
+ "unsafe_code" = "deny"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+pub fn foo(num: i32) -> u32 {
+ unsafe { std::mem::transmute(num) }
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr_contains(
+ "\
+error: usage of an `unsafe` block
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn attribute_has_precedence() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lints.rust]
+ "unsafe_code" = "deny"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+#![allow(unsafe_code)]
+
+pub fn foo(num: i32) -> u32 {
+ unsafe { std::mem::transmute(num) }
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .arg("-v") // Show order of rustflags on failure
+ .masquerade_as_nightly_cargo(&["lints"])
+ .run();
+}
+
+#[cargo_test]
+fn rustflags_has_precedence() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lints.rust]
+ "unsafe_code" = "deny"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+pub fn foo(num: i32) -> u32 {
+ unsafe { std::mem::transmute(num) }
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .arg("-v") // Show order of rustflags on failure
+ .env("RUSTFLAGS", "-Aunsafe_code")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .run();
+}
+
+#[cargo_test]
+fn profile_rustflags_has_precedence() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ cargo-features = ["profile-rustflags"]
+
+ [package]
+ name = "foo"
+ version = "0.0.1"
+
+ [lints.rust]
+ "unsafe_code" = "deny"
+
+ [profile.dev]
+ rustflags = ["-A", "unsafe_code"]
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+pub fn foo(num: i32) -> u32 {
+ unsafe { std::mem::transmute(num) }
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .arg("-v") // Show order of rustflags on failure
+ .masquerade_as_nightly_cargo(&["lints", "profile-rustflags"])
+ .run();
+}
+
+#[cargo_test]
+fn build_rustflags_has_precedence() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+
+ [lints.rust]
+ "unsafe_code" = "deny"
+ "#,
+ )
+ .file(
+ ".cargo/config.toml",
+ r#"
+ [build]
+ rustflags = ["-A", "unsafe_code"]
+"#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+pub fn foo(num: i32) -> u32 {
+ unsafe { std::mem::transmute(num) }
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .arg("-v") // Show order of rustflags on failure
+ .masquerade_as_nightly_cargo(&["lints"])
+ .run();
+}
+
+#[cargo_test]
+fn without_priority() {
+ Package::new("reg-dep", "1.0.0").publish();
+
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ edition = "2018"
+ authors = []
+
+ [dependencies]
+ reg-dep = "1.0.0"
+
+ [lints.rust]
+ "rust-2018-idioms" = "deny"
+ "unused-extern-crates" = "allow"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+extern crate reg_dep;
+
+pub fn foo() -> u32 {
+ 2
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr_contains(
+ "\
+error: unused extern crate
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn with_priority() {
+ Package::new("reg-dep", "1.0.0").publish();
+
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ edition = "2018"
+ authors = []
+
+ [dependencies]
+ reg-dep = "1.0.0"
+
+ [lints.rust]
+ "rust-2018-idioms" = { level = "deny", priority = -1 }
+ "unused-extern-crates" = "allow"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+extern crate reg_dep;
+
+pub fn foo() -> u32 {
+ 2
+}
+",
+ )
+ .build();
+
+ foo.cargo("check -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .run();
+}
+
+#[cargo_test]
+fn rustdoc_lint() {
+ let foo = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [lints.rustdoc]
+ broken_intra_doc_links = "deny"
+ "#,
+ )
+ .file(
+ "src/lib.rs",
+ "
+/// [`bar`] doesn't exist
+pub fn foo() -> u32 {
+}
+",
+ )
+ .build();
+
+ foo.cargo("doc -Zlints")
+ .masquerade_as_nightly_cargo(&["lints"])
+ .with_status(101)
+ .with_stderr_contains(
+ "\
+error: unresolved link to `bar`
+",
+ )
+ .run();
+}
diff --git a/src/tools/cargo/tests/testsuite/main.rs b/src/tools/cargo/tests/testsuite/main.rs
index a1e293acd..170a22667 100644
--- a/src/tools/cargo/tests/testsuite/main.rs
+++ b/src/tools/cargo/tests/testsuite/main.rs
@@ -24,6 +24,7 @@ mod cargo_command;
mod cargo_config;
mod cargo_env_config;
mod cargo_features;
+mod cargo_new;
mod cargo_remove;
mod cargo_targets;
mod cfg;
@@ -59,6 +60,7 @@ mod generate_lockfile;
mod git;
mod git_auth;
mod git_gc;
+mod git_shallow;
mod glob_targets;
mod help;
mod https;
@@ -67,6 +69,7 @@ mod init;
mod install;
mod install_upgrade;
mod jobserver;
+mod lints;
mod list_availables;
mod local_registry;
mod locate_project;
@@ -119,6 +122,7 @@ mod rustdoc;
mod rustdoc_extern_html;
mod rustdocflags;
mod rustflags;
+mod rustup;
mod search;
mod shell_quoting;
mod source_replacement;
diff --git a/src/tools/cargo/tests/testsuite/metadata.rs b/src/tools/cargo/tests/testsuite/metadata.rs
index 547916e7a..ac2cec396 100644
--- a/src/tools/cargo/tests/testsuite/metadata.rs
+++ b/src/tools/cargo/tests/testsuite/metadata.rs
@@ -65,6 +65,7 @@ fn cargo_metadata_simple() {
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
+ "workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
@@ -164,6 +165,7 @@ crate-type = ["lib", "staticlib"]
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
+ "workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
@@ -257,6 +259,7 @@ optional_feat = []
}
],
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
+ "workspace_default_members": ["foo 0.5.0 (path+file:[..]foo)"],
"resolve": {
"nodes": [
{
@@ -587,6 +590,9 @@ fn cargo_metadata_with_deps_and_version() {
"workspace_members": [
"foo 0.5.0 (path+file:[..]foo)"
],
+ "workspace_default_members": [
+ "foo 0.5.0 (path+file:[..]foo)"
+ ],
"workspace_root": "[..]/foo",
"metadata": null
}"#,
@@ -668,6 +674,9 @@ name = "ex"
"workspace_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
+ "workspace_default_members": [
+ "foo 0.1.0 (path+file:[..]foo)"
+ ],
"resolve": {
"root": "foo 0.1.0 (path+file://[..]foo)",
"nodes": [
@@ -763,6 +772,9 @@ crate-type = ["rlib", "dylib"]
"workspace_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
+ "workspace_default_members": [
+ "foo 0.1.0 (path+file:[..]foo)"
+ ],
"resolve": {
"root": "foo 0.1.0 (path+file://[..]foo)",
"nodes": [
@@ -892,6 +904,7 @@ fn workspace_metadata() {
}
],
"workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
+ "workspace_default_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"],
"resolve": {
"nodes": [
{
@@ -1123,6 +1136,11 @@ fn workspace_metadata_with_dependencies_no_deps() {
"artifact 0.5.0 (path+file:[..]/foo/artifact)",
"baz 0.5.0 (path+file:[..]baz)"
],
+ "workspace_default_members": [
+ "bar 0.5.0 (path+file:[..]bar)",
+ "artifact 0.5.0 (path+file:[..]/foo/artifact)",
+ "baz 0.5.0 (path+file:[..]baz)"
+ ],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
@@ -1755,6 +1773,12 @@ fn workspace_metadata_with_dependencies_and_resolve() {
"bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
"non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)"
],
+ "workspace_default_members": [
+ "bar 0.5.0 (path+file://[..]/foo/bar)",
+ "artifact 0.5.0 (path+file://[..]/foo/artifact)",
+ "bin-only-artifact 0.5.0 (path+file://[..]/foo/bin-only-artifact)",
+ "non-artifact 0.5.0 (path+file://[..]/foo/non-artifact)"
+ ],
"workspace_root": "[..]/foo"
}
"#,
@@ -1953,6 +1977,7 @@ const MANIFEST_OUTPUT: &str = r#"
"documentation": null
}],
"workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
+ "workspace_default_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
@@ -2147,6 +2172,7 @@ fn package_metadata() {
}
],
"workspace_members": ["foo[..]"],
+ "workspace_default_members": ["foo[..]"],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
@@ -2222,6 +2248,7 @@ fn package_publish() {
}
],
"workspace_members": ["foo[..]"],
+ "workspace_default_members": ["foo[..]"],
"resolve": null,
"target_directory": "[..]foo/target",
"version": 1,
@@ -2317,6 +2344,9 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"workspace_members": [
"bar 0.5.0 (path+file:[..])"
],
+ "workspace_default_members": [
+ "bar 0.5.0 (path+file:[..])"
+ ],
"workspace_root": "[..]",
"metadata": null
}
@@ -2405,6 +2435,9 @@ fn package_edition_2018() {
"workspace_members": [
"foo 0.1.0 (path+file:[..])"
],
+ "workspace_default_members": [
+ "foo 0.1.0 (path+file:[..])"
+ ],
"workspace_root": "[..]",
"metadata": null
}
@@ -2553,6 +2586,9 @@ fn target_edition_2018() {
"workspace_members": [
"foo 0.1.0 (path+file:[..])"
],
+ "workspace_default_members": [
+ "foo 0.1.0 (path+file:[..])"
+ ],
"workspace_root": "[..]",
"metadata": null
}
@@ -2789,6 +2825,9 @@ fn rename_dependency() {
"workspace_members": [
"foo 0.0.1[..]"
],
+ "workspace_default_members": [
+ "foo 0.0.1[..]"
+ ],
"workspace_root": "[..]",
"metadata": null
}"#,
@@ -2889,6 +2928,9 @@ fn metadata_links() {
"workspace_members": [
"foo 0.5.0 [..]"
],
+ "workspace_default_members": [
+ "foo 0.5.0 [..]"
+ ],
"workspace_root": "[..]/foo",
"metadata": null
}
@@ -2979,6 +3021,9 @@ fn deps_with_bin_only() {
"workspace_members": [
"foo 0.1.0 ([..])"
],
+ "workspace_default_members": [
+ "foo 0.1.0 ([..])"
+ ],
"resolve": {
"nodes": [
{
@@ -3358,6 +3403,9 @@ fn filter_platform() {
"workspace_members": [
"foo 0.1.0 (path+file:[..]foo)"
],
+ "workspace_default_members": [
+ "foo 0.1.0 (path+file:[..]foo)"
+ ],
"resolve": {
"nodes": [
{
@@ -3477,6 +3525,7 @@ fn filter_platform() {
$NORMAL_DEP
],
"workspace_members": "{...}",
+ "workspace_default_members": "{...}",
"resolve": {
"nodes": [
{
@@ -3558,6 +3607,7 @@ fn filter_platform() {
$NORMAL_DEP
],
"workspace_members": "{...}",
+ "workspace_default_members": "{...}",
"resolve": {
"nodes": [
{
@@ -3642,6 +3692,7 @@ fn filter_platform() {
$NORMAL_DEP
],
"workspace_members": "{...}",
+ "workspace_default_members": "{...}",
"resolve": {
"nodes": [
{
@@ -3756,6 +3807,7 @@ fn dep_kinds() {
{
"packages": "{...}",
"workspace_members": "{...}",
+ "workspace_default_members": "{...}",
"target_directory": "{...}",
"version": 1,
"workspace_root": "{...}",
@@ -3871,6 +3923,7 @@ fn dep_kinds_workspace() {
{
"packages": "{...}",
"workspace_members": "{...}",
+ "workspace_default_members": "{...}",
"target_directory": "[..]/foo/target",
"version": 1,
"workspace_root": "[..]/foo",
@@ -4184,6 +4237,11 @@ fn workspace_metadata_with_dependencies_no_deps_artifact() {
"artifact 0.5.0 (path+file://[..]/foo/artifact)",
"baz 0.5.0 (path+file://[..]/foo/baz)"
],
+ "workspace_default_members": [
+ "bar 0.5.0 (path+file://[..]/foo/bar)",
+ "artifact 0.5.0 (path+file://[..]/foo/artifact)",
+ "baz 0.5.0 (path+file://[..]/foo/baz)"
+ ],
"workspace_root": "[..]/foo"
}
"#,
diff --git a/src/tools/cargo/tests/testsuite/mock-std/library/sysroot/Cargo.toml b/src/tools/cargo/tests/testsuite/mock-std/library/sysroot/Cargo.toml
new file mode 100644
index 000000000..615c894db
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/mock-std/library/sysroot/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "sysroot"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+proc_macro = { path = "../proc_macro" }
+std = { path = "../std" }
+test = { path = "../test" }
+
+[features]
+panic-unwind = []
+backtrace = []
+feature1 = ["std/feature1"]
+default = []
diff --git a/src/tools/cargo/tests/testsuite/mock-std/library/sysroot/src/lib.rs b/src/tools/cargo/tests/testsuite/mock-std/library/sysroot/src/lib.rs
new file mode 100644
index 000000000..7215576fc
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/mock-std/library/sysroot/src/lib.rs
@@ -0,0 +1 @@
+// Intentionally left blank.
diff --git a/src/tools/cargo/tests/testsuite/mock-std/library/test/Cargo.toml b/src/tools/cargo/tests/testsuite/mock-std/library/test/Cargo.toml
index 299db7bfd..b9f51eda7 100644
--- a/src/tools/cargo/tests/testsuite/mock-std/library/test/Cargo.toml
+++ b/src/tools/cargo/tests/testsuite/mock-std/library/test/Cargo.toml
@@ -5,14 +5,7 @@ authors = ["Alex Crichton <alex@alexcrichton.com>"]
edition = "2018"
[dependencies]
-proc_macro = { path = "../proc_macro" }
std = { path = "../std" }
panic_unwind = { path = "../panic_unwind" }
compiler_builtins = { path = "../compiler_builtins" }
registry-dep-using-std = { version = "*", features = ['mockbuild'] }
-
-[features]
-panic-unwind = []
-backtrace = []
-feature1 = ["std/feature1"]
-default = []
diff --git a/src/tools/cargo/tests/testsuite/offline.rs b/src/tools/cargo/tests/testsuite/offline.rs
index fe54fc59d..5f164dbeb 100644
--- a/src/tools/cargo/tests/testsuite/offline.rs
+++ b/src/tools/cargo/tests/testsuite/offline.rs
@@ -3,6 +3,7 @@
use cargo_test_support::{
basic_manifest, git, main_file, path2url, project,
registry::{Package, RegistryBuilder},
+ Execs,
};
use std::fs;
@@ -377,6 +378,15 @@ fn update_offline_not_cached_git() {
#[cargo_test]
fn cargo_compile_offline_with_cached_git_dep() {
+ compile_offline_with_cached_git_dep(false)
+}
+
+#[cargo_test]
+fn gitoxide_cargo_compile_offline_with_cached_git_dep_shallow_dep() {
+ compile_offline_with_cached_git_dep(true)
+}
+
+fn compile_offline_with_cached_git_dep(shallow: bool) {
let git_project = git::new("dep1", |project| {
project
.file("Cargo.toml", &basic_manifest("dep1", "0.5.0"))
@@ -420,7 +430,17 @@ fn cargo_compile_offline_with_cached_git_dep() {
)
.file("src/main.rs", "fn main(){}")
.build();
- prj.cargo("build").run();
+ let maybe_use_shallow = |mut cargo: Execs| -> Execs {
+ if shallow {
+ cargo
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&[
+ "unstable features must be available for -Z gitoxide",
+ ]);
+ }
+ cargo
+ };
+ maybe_use_shallow(prj.cargo("build")).run();
prj.change_file(
"Cargo.toml",
@@ -438,7 +458,7 @@ fn cargo_compile_offline_with_cached_git_dep() {
rev2
),
);
- prj.cargo("build").run();
+ maybe_use_shallow(prj.cargo("build")).run();
let p = project()
.file(
@@ -463,15 +483,15 @@ fn cargo_compile_offline_with_cached_git_dep() {
let git_root = git_project.root();
- p.cargo("build --offline")
- .with_stderr(format!(
- "\
+ let mut cargo = p.cargo("build --offline");
+ cargo.with_stderr(format!(
+ "\
[COMPILING] dep1 v0.5.0 ({}#[..])
[COMPILING] foo v0.5.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
- path2url(git_root),
- ))
- .run();
+ path2url(git_root),
+ ));
+ maybe_use_shallow(cargo).run();
assert!(p.bin("foo").is_file());
@@ -496,7 +516,7 @@ fn cargo_compile_offline_with_cached_git_dep() {
),
);
- p.cargo("build --offline").run();
+ maybe_use_shallow(p.cargo("build --offline")).run();
p.process(&p.bin("foo"))
.with_stdout("hello from cached git repo rev1\n")
.run();
diff --git a/src/tools/cargo/tests/testsuite/package.rs b/src/tools/cargo/tests/testsuite/package.rs
index 14bac6618..3b4328242 100644
--- a/src/tools/cargo/tests/testsuite/package.rs
+++ b/src/tools/cargo/tests/testsuite/package.rs
@@ -1775,6 +1775,142 @@ fn exclude_dot_files_and_directories_by_default() {
}
#[cargo_test]
+fn empty_readme_path() {
+ // Warn but don't fail if `readme` is empty.
+ // Issue #11522.
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "1.0.0"
+ readme = ""
+ license = "MIT"
+ description = "foo"
+ homepage = "foo"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("package --no-verify")
+ .with_stderr(
+ "\
+[WARNING] readme `` does not appear to exist (relative to `[..]/foo`).
+Please update the readme setting in the manifest at `[..]/foo/Cargo.toml`
+This may become a hard error in the future.
+[PACKAGING] foo v1.0.0 ([..]/foo)
+[PACKAGED] [..] files, [..] ([..] compressed)
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn invalid_readme_path() {
+ // Warn but don't fail if `readme` path is invalid.
+ // Issue #11522.
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "1.0.0"
+ readme = "DOES-NOT-EXIST"
+ license = "MIT"
+ description = "foo"
+ homepage = "foo"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("package --no-verify")
+ .with_stderr(
+ "\
+[WARNING] readme `DOES-NOT-EXIST` does not appear to exist (relative to `[..]/foo`).
+Please update the readme setting in the manifest at `[..]/foo/Cargo.toml`
+This may become a hard error in the future.
+[PACKAGING] foo v1.0.0 ([..]/foo)
+[PACKAGED] [..] files, [..] ([..] compressed)
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn readme_or_license_file_is_dir() {
+ // Test warning when `readme` or `license-file` is a directory, not a file.
+ // Issue #11522.
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "1.0.0"
+ readme = "./src"
+ license-file = "./src"
+ description = "foo"
+ homepage = "foo"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("package --no-verify")
+ .with_stderr(
+ "\
+[WARNING] license-file `./src` does not appear to exist (relative to `[..]/foo`).
+Please update the license-file setting in the manifest at `[..]/foo/Cargo.toml`
+This may become a hard error in the future.
+[WARNING] readme `./src` does not appear to exist (relative to `[..]/foo`).
+Please update the readme setting in the manifest at `[..]/foo/Cargo.toml`
+This may become a hard error in the future.
+[PACKAGING] foo v1.0.0 ([..]/foo)
+[PACKAGED] [..] files, [..] ([..] compressed)
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn empty_license_file_path() {
+ // Warn but don't fail if license-file is empty.
+ // Issue #11522.
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "1.0.0"
+ license-file = ""
+ description = "foo"
+ homepage = "foo"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("package --no-verify")
+ .with_stderr(
+ "\
+[WARNING] manifest has no license or license-file.
+See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
+[WARNING] license-file `` does not appear to exist (relative to `[..]/foo`).
+Please update the license-file setting in the manifest at `[..]/foo/Cargo.toml`
+This may become a hard error in the future.
+[PACKAGING] foo v1.0.0 ([..]/foo)
+[PACKAGED] [..] files, [..] ([..] compressed)
+",
+ )
+ .run();
+}
+
+#[cargo_test]
fn invalid_license_file_path() {
// Test warning when license-file points to a non-existent file.
let p = project()
@@ -2400,6 +2536,91 @@ See [..]
}
#[cargo_test]
+fn workspace_noconflict_readme() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [workspace]
+ members = ["bar"]
+ "#,
+ )
+ .file("README.md", "workspace readme")
+ .file(
+ "bar/Cargo.toml",
+ r#"
+ [package]
+ name = "bar"
+ version = "0.0.1"
+ repository = "https://github.com/bar/bar"
+ authors = []
+ license = "MIT"
+ description = "bar"
+ readme = "../README.md"
+ workspace = ".."
+ "#,
+ )
+ .file("bar/src/main.rs", "fn main() {}")
+ .file("bar/example/README.md", "# example readmdBar")
+ .build();
+
+ p.cargo("package")
+ .with_stderr(
+ "\
+[PACKAGING] bar v0.0.1 ([CWD]/bar)
+[VERIFYING] bar v0.0.1 ([CWD]/bar)
+[COMPILING] bar v0.0.1 ([CWD]/[..])
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[PACKAGED] [..] files, [..] ([..] compressed)
+",
+ )
+ .run();
+}
+
+#[cargo_test]
+fn workspace_conflict_readme() {
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [workspace]
+ members = ["bar"]
+ "#,
+ )
+ .file("README.md", "workspace readme")
+ .file(
+ "bar/Cargo.toml",
+ r#"
+ [package]
+ name = "bar"
+ version = "0.0.1"
+ repository = "https://github.com/bar/bar"
+ authors = []
+ license = "MIT"
+ description = "bar"
+ readme = "../README.md"
+ workspace = ".."
+ "#,
+ )
+ .file("bar/src/main.rs", "fn main() {}")
+ .file("bar/README.md", "# workspace member: Bar")
+ .build();
+
+ p.cargo("package")
+ .with_stderr(
+ "\
+warning: readme `../README.md` appears to be a path outside of the package, but there is already a file named `README.md` in the root of the package. The archived crate will contain the copy in the root of the package. Update the readme to point to the path relative to the root of the package to remove this warning.
+[PACKAGING] bar v0.0.1 ([CWD]/bar)
+[VERIFYING] bar v0.0.1 ([CWD]/bar)
+[COMPILING] bar v0.0.1 ([CWD]/[..])
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[PACKAGED] [..] files, [..] ([..] compressed)
+",
+ )
+ .run();
+}
+
+#[cargo_test]
fn workspace_overrides_resolver() {
let p = project()
.file(
diff --git a/src/tools/cargo/tests/testsuite/patch.rs b/src/tools/cargo/tests/testsuite/patch.rs
index 681c02416..f2f077d7d 100644
--- a/src/tools/cargo/tests/testsuite/patch.rs
+++ b/src/tools/cargo/tests/testsuite/patch.rs
@@ -2466,7 +2466,11 @@ fn can_update_with_alt_reg() {
}
#[cargo_test]
-fn old_git_patch() {
+fn gitoxide_clones_shallow_old_git_patch() {
+ perform_old_git_patch(true)
+}
+
+fn perform_old_git_patch(shallow: bool) {
// Example where an old lockfile with an explicit branch="master" in Cargo.toml.
Package::new("bar", "1.0.0").publish();
let (bar, bar_repo) = git::new_repo("bar", |p| {
@@ -2524,7 +2528,13 @@ dependencies = [
git::commit(&bar_repo);
// This *should* keep the old lock.
- p.cargo("tree")
+ let mut cargo = p.cargo("tree");
+ if shallow {
+ cargo
+ .arg("-Zgitoxide=fetch,shallow-deps")
+ .masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"]);
+ }
+ cargo
// .env("CARGO_LOG", "trace")
.with_stderr(
"\
@@ -2542,6 +2552,11 @@ foo v0.1.0 [..]
.run();
}
+#[cargo_test]
+fn old_git_patch() {
+ perform_old_git_patch(false)
+}
+
// From https://github.com/rust-lang/cargo/issues/7463
#[cargo_test]
fn patch_eq_conflict_panic() {
diff --git a/src/tools/cargo/tests/testsuite/profile_config.rs b/src/tools/cargo/tests/testsuite/profile_config.rs
index c59ed7a97..cf9807964 100644
--- a/src/tools/cargo/tests/testsuite/profile_config.rs
+++ b/src/tools/cargo/tests/testsuite/profile_config.rs
@@ -1,5 +1,6 @@
//! Tests for profiles defined in config files.
+use cargo::util::toml::TomlDebugInfo;
use cargo_test_support::paths::CargoPathExt;
use cargo_test_support::registry::Package;
use cargo_test_support::{basic_lib_manifest, paths, project};
@@ -436,7 +437,7 @@ fn named_config_profile() {
assert_eq!(p.name, "foo");
assert_eq!(p.codegen_units, Some(2)); // "foo" from config
assert_eq!(p.opt_level, "1"); // "middle" from manifest
- assert_eq!(p.debuginfo.to_option(), Some(1)); // "bar" from config
+ assert_eq!(p.debuginfo.to_option(), Some(TomlDebugInfo::Limited)); // "bar" from config
assert_eq!(p.debug_assertions, true); // "dev" built-in (ignore build-override)
assert_eq!(p.overflow_checks, true); // "dev" built-in (ignore package override)
@@ -445,7 +446,7 @@ fn named_config_profile() {
assert_eq!(bo.name, "foo");
assert_eq!(bo.codegen_units, Some(6)); // "foo" build override from config
assert_eq!(bo.opt_level, "0"); // default to zero
- assert_eq!(bo.debuginfo.to_option(), Some(1)); // SAME as normal
+ assert_eq!(bo.debuginfo.to_option(), Some(TomlDebugInfo::Limited)); // SAME as normal
assert_eq!(bo.debug_assertions, false); // "foo" build override from manifest
assert_eq!(bo.overflow_checks, true); // SAME as normal
@@ -454,7 +455,7 @@ fn named_config_profile() {
assert_eq!(po.name, "foo");
assert_eq!(po.codegen_units, Some(7)); // "foo" package override from config
assert_eq!(po.opt_level, "1"); // SAME as normal
- assert_eq!(po.debuginfo.to_option(), Some(1)); // SAME as normal
+ assert_eq!(po.debuginfo.to_option(), Some(TomlDebugInfo::Limited)); // SAME as normal
assert_eq!(po.debug_assertions, true); // SAME as normal
assert_eq!(po.overflow_checks, false); // "middle" package override from manifest
}
diff --git a/src/tools/cargo/tests/testsuite/profile_targets.rs b/src/tools/cargo/tests/testsuite/profile_targets.rs
index b3235972c..0449e8ab3 100644
--- a/src/tools/cargo/tests/testsuite/profile_targets.rs
+++ b/src/tools/cargo/tests/testsuite/profile_targets.rs
@@ -83,16 +83,16 @@ fn profile_selection_build() {
// - bdep `panic` is not set because it thinks `build.rs` is a plugin.
// - build_script_build is built without panic because it thinks `build.rs` is a plugin.
// - We make sure that the build dependencies bar, bdep, and build.rs
- // are built without debuginfo.
+ // are built with debuginfo=0.
p.cargo("build -vv")
.with_stderr_unordered("\
[COMPILING] bar [..]
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
-[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
+[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
[COMPILING] bdep [..]
-[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
+[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
[COMPILING] foo [..]
-[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 [..]
+[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
[RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build`
[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0
[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
@@ -100,9 +100,6 @@ fn profile_selection_build() {
[FINISHED] dev [unoptimized + debuginfo] [..]
"
)
- .with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
- .with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
- .with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
.run();
p.cargo("build -vv")
.with_stderr_unordered(
@@ -158,7 +155,7 @@ fn profile_selection_build_all_targets() {
// - Benchmark dependencies are compiled in `dev` mode, which may be
// surprising. See issue rust-lang/cargo#4929.
// - We make sure that the build dependencies bar, bdep, and build.rs
- // are built without debuginfo.
+ // are built with debuginfo=0.
//
// - Dependency profiles:
// Pkg Target Profile Reason
@@ -184,11 +181,11 @@ fn profile_selection_build_all_targets() {
[COMPILING] bar [..]
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 [..]
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
-[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
+[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
[COMPILING] bdep [..]
-[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
+[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
[COMPILING] foo [..]
-[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 [..]
+[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
[RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build`
[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0
[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]`
@@ -202,9 +199,6 @@ fn profile_selection_build_all_targets() {
[FINISHED] dev [unoptimized + debuginfo] [..]
"
)
- .with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
- .with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
- .with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
.run();
p.cargo("build -vv")
.with_stderr_unordered(
diff --git a/src/tools/cargo/tests/testsuite/publish.rs b/src/tools/cargo/tests/testsuite/publish.rs
index 00a79fe73..45b7c7da5 100644
--- a/src/tools/cargo/tests/testsuite/publish.rs
+++ b/src/tools/cargo/tests/testsuite/publish.rs
@@ -25,6 +25,7 @@ const CLEAN_FOO_JSON: &str = r#"
"readme": null,
"readme_file": null,
"repository": "foo",
+ "rust_version": null,
"vers": "0.0.1"
}
"#;
@@ -49,6 +50,7 @@ fn validate_upload_foo() {
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.0.1"
}
"#,
@@ -77,6 +79,7 @@ fn validate_upload_li() {
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": "1.69",
"vers": "0.0.1"
}
"#,
@@ -1270,6 +1273,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.0.1"
}
"#,
@@ -1469,6 +1473,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.1.0"
}
"#,
@@ -1581,6 +1586,7 @@ You may press ctrl-c [..]
"readme": null,
"readme_file": null,
"repository": "foo",
+ "rust_version": null,
"vers": "0.1.0"
}
"#,
@@ -1756,6 +1762,9 @@ fn publish_with_missing_readme() {
.with_stderr(&format!(
"\
[UPDATING] [..]
+[WARNING] readme `foo.md` does not appear to exist (relative to `[..]/foo`).
+Please update the readme setting in the manifest at `[..]/foo/Cargo.toml`
+This may become a hard error in the future.
[PACKAGING] foo v0.1.0 [..]
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] foo v0.1.0 [..]
@@ -2046,6 +2055,7 @@ fn in_package_workspace() {
[package]
name = "li"
version = "0.0.1"
+ rust-version = "1.69"
description = "li"
license = "MIT"
"#,
@@ -2148,6 +2158,7 @@ fn in_package_workspace_with_members_with_features_old() {
[package]
name = "li"
version = "0.0.1"
+ rust-version = "1.69"
description = "li"
license = "MIT"
"#,
@@ -2243,6 +2254,7 @@ fn in_virtual_workspace_with_p() {
[package]
name = "li"
version = "0.0.1"
+ rust-version = "1.69"
description = "li"
license = "MIT"
"#,
diff --git a/src/tools/cargo/tests/testsuite/registry.rs b/src/tools/cargo/tests/testsuite/registry.rs
index 05ec9b158..bd5e42b45 100644
--- a/src/tools/cargo/tests/testsuite/registry.rs
+++ b/src/tools/cargo/tests/testsuite/registry.rs
@@ -2546,7 +2546,7 @@ fn package_lock_inside_package_is_overwritten() {
.join("bar-0.0.1")
.join(".cargo-ok");
- assert_eq!(ok.metadata().unwrap().len(), 2);
+ assert_eq!(ok.metadata().unwrap().len(), 7);
}
#[cargo_test]
@@ -2586,7 +2586,7 @@ fn package_lock_as_a_symlink_inside_package_is_overwritten() {
let librs = pkg_root.join("src/lib.rs");
// Is correctly overwritten and doesn't affect the file linked to
- assert_eq!(ok.metadata().unwrap().len(), 2);
+ assert_eq!(ok.metadata().unwrap().len(), 7);
assert_eq!(fs::read_to_string(librs).unwrap(), "pub fn f() {}");
}
@@ -3135,7 +3135,7 @@ fn corrupted_ok_overwritten() {
fs::write(&ok, "").unwrap();
assert_eq!(fs::read_to_string(&ok).unwrap(), "");
p.cargo("fetch").with_stderr("").run();
- assert_eq!(fs::read_to_string(&ok).unwrap(), "ok");
+ assert_eq!(fs::read_to_string(&ok).unwrap(), r#"{"v":1}"#);
}
#[cargo_test]
@@ -3166,7 +3166,7 @@ fn not_found_permutations() {
authors = []
[dependencies]
- a-b-c = "1.0"
+ a-b_c = "1.0"
"#,
)
.file("src/lib.rs", "")
@@ -3177,7 +3177,7 @@ fn not_found_permutations() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
-error: no matching package named `a-b-c` found
+error: no matching package named `a-b_c` found
location searched: registry `crates-io`
required by package `foo v0.0.1 ([ROOT]/foo)`
",
@@ -3190,7 +3190,6 @@ required by package `foo v0.0.1 ([ROOT]/foo)`
&[
"/index/a-/b-/a-b-c",
"/index/a-/b_/a-b_c",
- "/index/a_/b-/a_b-c",
"/index/a_/b_/a_b_c"
]
);
@@ -3404,3 +3403,129 @@ Caused by:
Please slow down
").run();
}
+
+#[cfg(unix)]
+#[cargo_test]
+fn set_mask_during_unpacking() {
+ use std::os::unix::fs::MetadataExt;
+
+ Package::new("bar", "1.0.0")
+ .file_with_mode("example.sh", 0o777, "#!/bin/sh")
+ .file_with_mode("src/lib.rs", 0o666, "")
+ .publish();
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("fetch")
+ .with_stderr(
+ "\
+[UPDATING] `dummy-registry` index
+[DOWNLOADING] crates ...
+[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
+",
+ )
+ .run();
+ let src_file_path = |path: &str| {
+ glob::glob(
+ paths::home()
+ .join(".cargo/registry/src/*/bar-1.0.0/")
+ .join(path)
+ .to_str()
+ .unwrap(),
+ )
+ .unwrap()
+ .next()
+ .unwrap()
+ .unwrap()
+ };
+
+ let umask = cargo::util::get_umask();
+ let metadata = fs::metadata(src_file_path("src/lib.rs")).unwrap();
+ assert_eq!(metadata.mode() & 0o777, 0o666 & !umask);
+ let metadata = fs::metadata(src_file_path("example.sh")).unwrap();
+ assert_eq!(metadata.mode() & 0o777, 0o777 & !umask);
+}
+
+#[cargo_test]
+fn unpack_again_when_cargo_ok_is_unrecognized() {
+ Package::new("bar", "1.0.0").publish();
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("fetch")
+ .with_stderr(
+ "\
+[UPDATING] `dummy-registry` index
+[DOWNLOADING] crates ...
+[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
+",
+ )
+ .run();
+
+ let src_file_path = |path: &str| {
+ glob::glob(
+ paths::home()
+ .join(".cargo/registry/src/*/bar-1.0.0/")
+ .join(path)
+ .to_str()
+ .unwrap(),
+ )
+ .unwrap()
+ .next()
+ .unwrap()
+ .unwrap()
+ };
+
+ // Change permissions to simulate the old behavior not respecting umask.
+ let lib_rs = src_file_path("src/lib.rs");
+ let cargo_ok = src_file_path(".cargo-ok");
+ let mut perms = fs::metadata(&lib_rs).unwrap().permissions();
+ assert!(!perms.readonly());
+ perms.set_readonly(true);
+ fs::set_permissions(&lib_rs, perms).unwrap();
+ let ok = fs::read_to_string(&cargo_ok).unwrap();
+ assert_eq!(&ok, r#"{"v":1}"#);
+
+ p.cargo("fetch").with_stderr("").run();
+
+ // Without changing `.cargo-ok`, a unpack won't be triggered.
+ let perms = fs::metadata(&lib_rs).unwrap().permissions();
+ assert!(perms.readonly());
+
+ // Write "ok" to simulate the old behavior and trigger the unpack again.
+ fs::write(&cargo_ok, "ok").unwrap();
+
+ p.cargo("fetch").with_stderr("").run();
+
+ // Permission has been restored and `.cargo-ok` is in the new format.
+ let perms = fs::metadata(lib_rs).unwrap().permissions();
+ assert!(!perms.readonly());
+ let ok = fs::read_to_string(&cargo_ok).unwrap();
+ assert_eq!(&ok, r#"{"v":1}"#);
+}
diff --git a/src/tools/cargo/tests/testsuite/registry_auth.rs b/src/tools/cargo/tests/testsuite/registry_auth.rs
index 7779e285a..97cdf6748 100644
--- a/src/tools/cargo/tests/testsuite/registry_auth.rs
+++ b/src/tools/cargo/tests/testsuite/registry_auth.rs
@@ -1,6 +1,7 @@
//! Tests for registry authentication.
-use cargo_test_support::registry::{Package, RegistryBuilder};
+use cargo_test_support::compare::match_contains;
+use cargo_test_support::registry::{Package, RegistryBuilder, Token};
use cargo_test_support::{project, Execs, Project};
fn cargo(p: &Project, s: &str) -> Execs {
@@ -517,3 +518,73 @@ Caused by:
)
.run();
}
+
+#[cargo_test]
+fn token_not_logged() {
+ // Checks that the token isn't displayed in debug output (for both HTTP
+ // index and registry API). Note that this doesn't fully verify the
+ // correct behavior since we don't have an HTTP2 server, and curl behaves
+ // significantly differently when using HTTP2.
+ let crates_io = RegistryBuilder::new()
+ .http_api()
+ .http_index()
+ .auth_required()
+ .token(Token::Plaintext("a-unique_token".to_string()))
+ .build();
+ Package::new("bar", "1.0.0").publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ bar = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+ let output = cargo(&p, "publish")
+ .replace_crates_io(crates_io.index_url())
+ .env("CARGO_HTTP_DEBUG", "true")
+ .env("CARGO_LOG", "trace")
+ .exec_with_output()
+ .unwrap();
+ let log = String::from_utf8(output.stderr).unwrap();
+ let lines = "\
+[UPDATING] crates.io index
+[PACKAGING] foo v0.1.0 [..]
+[VERIFYING] foo v0.1.0 [..]
+[DOWNLOADING] crates ...
+[DOWNLOADED] bar v1.0.0
+[COMPILING] bar v1.0.0
+[COMPILING] foo v0.1.0 [..]
+[FINISHED] [..]
+[PACKAGED] 3 files[..]
+[UPLOADING] foo v0.1.0[..]
+[UPLOADED] foo v0.1.0 to registry `crates-io`
+note: Waiting [..]
+";
+ for line in lines.lines() {
+ match_contains(line, &log, None).unwrap();
+ }
+ let authorizations: Vec<_> = log
+ .lines()
+ .filter(|line| {
+ line.contains("http-debug:") && line.to_lowercase().contains("authorization")
+ })
+ .collect();
+ assert!(authorizations.iter().all(|line| line.contains("REDACTED")));
+ // Total authorizations:
+ // 1. Initial config.json
+ // 2. config.json again for verification
+ // 3. /index/3/b/bar
+ // 4. /dl/bar/1.0.0/download
+ // 5. /api/v1/crates/new
+ // 6. config.json for the "wait for publish"
+ // 7. /index/3/f/foo for the "wait for publish"
+ assert_eq!(authorizations.len(), 7);
+ assert!(!log.contains("a-unique_token"));
+}
diff --git a/src/tools/cargo/tests/testsuite/rustup.rs b/src/tools/cargo/tests/testsuite/rustup.rs
new file mode 100644
index 000000000..aa93f546c
--- /dev/null
+++ b/src/tools/cargo/tests/testsuite/rustup.rs
@@ -0,0 +1,262 @@
+//! Tests for Cargo's behavior under Rustup.
+
+use cargo_test_support::paths::{home, root, CargoPathExt};
+use cargo_test_support::{cargo_process, process, project};
+use std::env;
+use std::env::consts::EXE_EXTENSION;
+use std::ffi::OsString;
+use std::fs;
+use std::path::{Path, PathBuf};
+
+/// Helper to generate an executable.
+fn make_exe(dest: &Path, name: &str, contents: &str, env: &[(&str, PathBuf)]) -> PathBuf {
+ let rs_name = format!("{name}.rs");
+ fs::write(
+ root().join(&rs_name),
+ &format!("fn main() {{ {contents} }}"),
+ )
+ .unwrap();
+ let mut pb = process("rustc");
+ env.iter().for_each(|(key, value)| {
+ pb.env(key, value);
+ });
+ pb.arg("--edition=2021")
+ .arg(root().join(&rs_name))
+ .exec()
+ .unwrap();
+ let exe = Path::new(name).with_extension(EXE_EXTENSION);
+ let output = dest.join(&exe);
+ fs::rename(root().join(&exe), &output).unwrap();
+ output
+}
+
+fn prepend_path(path: &Path) -> OsString {
+ let mut paths = vec![path.to_path_buf()];
+ paths.extend(env::split_paths(&env::var_os("PATH").unwrap_or_default()));
+ env::join_paths(paths).unwrap()
+}
+
+struct RustupEnvironment {
+ /// Path for ~/.cargo/bin
+ cargo_bin: PathBuf,
+ /// Path for ~/.rustup
+ rustup_home: PathBuf,
+ /// Path to the cargo executable in the toolchain directory
+ /// (~/.rustup/toolchain/test-toolchain/bin/cargo.exe).
+ cargo_toolchain_exe: PathBuf,
+}
+
+/// Creates an executable which prints a message and then runs the *real* rustc.
+fn real_rustc_wrapper(bin_dir: &Path, message: &str) -> PathBuf {
+ let real_rustc = cargo_util::paths::resolve_executable("rustc".as_ref()).unwrap();
+ // The toolchain rustc needs to call the real rustc. In order to do that,
+ // it needs to restore or clear the RUSTUP environment variables so that
+ // if rustup is installed, it will call the correct rustc.
+ let rustup_toolchain_setup = match std::env::var_os("RUSTUP_TOOLCHAIN") {
+ Some(t) => format!(
+ ".env(\"RUSTUP_TOOLCHAIN\", \"{}\")",
+ t.into_string().unwrap()
+ ),
+ None => format!(".env_remove(\"RUSTUP_TOOLCHAIN\")"),
+ };
+ let mut env = vec![("CARGO_RUSTUP_TEST_real_rustc", real_rustc)];
+ let rustup_home_setup = match std::env::var_os("RUSTUP_HOME") {
+ Some(h) => {
+ env.push(("CARGO_RUSTUP_TEST_RUSTUP_HOME", h.into()));
+ format!(".env(\"RUSTUP_HOME\", env!(\"CARGO_RUSTUP_TEST_RUSTUP_HOME\"))")
+ }
+ None => format!(".env_remove(\"RUSTUP_HOME\")"),
+ };
+ make_exe(
+ bin_dir,
+ "rustc",
+ &format!(
+ r#"
+ eprintln!("{message}");
+ let r = std::process::Command::new(env!("CARGO_RUSTUP_TEST_real_rustc"))
+ .args(std::env::args_os().skip(1))
+ {rustup_toolchain_setup}
+ {rustup_home_setup}
+ .status();
+ std::process::exit(r.unwrap().code().unwrap_or(2));
+ "#
+ ),
+ &env,
+ )
+}
+
+/// Creates a simulation of a rustup environment with `~/.cargo/bin` and
+/// `~/.rustup` directories populated with some executables that simulate
+/// rustup.
+fn simulated_rustup_environment() -> RustupEnvironment {
+ // Set up ~/.rustup/toolchains/test-toolchain/bin with a custom rustc and cargo.
+ let rustup_home = home().join(".rustup");
+ let toolchain_bin = rustup_home
+ .join("toolchains")
+ .join("test-toolchain")
+ .join("bin");
+ toolchain_bin.mkdir_p();
+ let rustc_toolchain_exe = real_rustc_wrapper(&toolchain_bin, "real rustc running");
+ let cargo_toolchain_exe = make_exe(
+ &toolchain_bin,
+ "cargo",
+ r#"panic!("cargo toolchain should not be called");"#,
+ &[],
+ );
+
+ // Set up ~/.cargo/bin with a typical set of rustup proxies.
+ let cargo_bin = home().join(".cargo").join("bin");
+ cargo_bin.mkdir_p();
+
+ let rustc_proxy = make_exe(
+ &cargo_bin,
+ "rustc",
+ &format!(
+ r#"
+ match std::env::args().next().unwrap().as_ref() {{
+ "rustc" => {{}}
+ arg => panic!("proxy only supports rustc, got {{arg:?}}"),
+ }}
+ eprintln!("rustc proxy running");
+ let r = std::process::Command::new(env!("CARGO_RUSTUP_TEST_rustc_toolchain_exe"))
+ .args(std::env::args_os().skip(1))
+ .status();
+ std::process::exit(r.unwrap().code().unwrap_or(2));
+ "#
+ ),
+ &[("CARGO_RUSTUP_TEST_rustc_toolchain_exe", rustc_toolchain_exe)],
+ );
+ fs::hard_link(
+ &rustc_proxy,
+ cargo_bin.join("cargo").with_extension(EXE_EXTENSION),
+ )
+ .unwrap();
+ fs::hard_link(
+ &rustc_proxy,
+ cargo_bin.join("rustup").with_extension(EXE_EXTENSION),
+ )
+ .unwrap();
+
+ RustupEnvironment {
+ cargo_bin,
+ rustup_home,
+ cargo_toolchain_exe,
+ }
+}
+
+#[cargo_test]
+fn typical_rustup() {
+ // Test behavior under a typical rustup setup with a normal toolchain.
+ let RustupEnvironment {
+ cargo_bin,
+ rustup_home,
+ cargo_toolchain_exe,
+ } = simulated_rustup_environment();
+
+ // Set up a project and run a normal cargo build.
+ let p = project().file("src/lib.rs", "").build();
+ // The path is modified so that cargo will call `rustc` from
+ // `~/.cargo/bin/rustc to use our custom rustup proxies.
+ let path = prepend_path(&cargo_bin);
+ p.cargo("check")
+ .env("RUSTUP_TOOLCHAIN", "test-toolchain")
+ .env("RUSTUP_HOME", &rustup_home)
+ .env("PATH", &path)
+ .with_stderr(
+ "\
+[CHECKING] foo v0.0.1 [..]
+real rustc running
+[FINISHED] [..]
+",
+ )
+ .run();
+
+ // Do a similar test, but with a toolchain link that does not have cargo
+ // (which normally would do a fallback to nightly/beta/stable).
+ cargo_toolchain_exe.rm_rf();
+ p.build_dir().rm_rf();
+
+ p.cargo("check")
+ .env("RUSTUP_TOOLCHAIN", "test-toolchain")
+ .env("RUSTUP_HOME", &rustup_home)
+ .env("PATH", &path)
+ .with_stderr(
+ "\
+[CHECKING] foo v0.0.1 [..]
+real rustc running
+[FINISHED] [..]
+",
+ )
+ .run();
+}
+
+// This doesn't work on Windows because Cargo forces the PATH to contain the
+// sysroot_libdir, which is actually `bin`, preventing the test from
+// overriding the bin directory.
+#[cargo_test(ignore_windows = "PATH can't be overridden on Windows")]
+fn custom_calls_other_cargo() {
+ // Test behavior when a custom subcommand tries to manipulate PATH to use
+ // a different toolchain.
+ let RustupEnvironment {
+ cargo_bin,
+ rustup_home,
+ cargo_toolchain_exe: _,
+ } = simulated_rustup_environment();
+
+ // Create a directory with a custom toolchain (outside of the rustup universe).
+ let custom_bin = root().join("custom-bin");
+ custom_bin.mkdir_p();
+ // `cargo` points to the real cargo.
+ let cargo_exe = cargo_test_support::cargo_exe();
+ fs::hard_link(&cargo_exe, custom_bin.join(cargo_exe.file_name().unwrap())).unwrap();
+ // `rustc` executes the real rustc.
+ real_rustc_wrapper(&custom_bin, "custom toolchain rustc running");
+
+ // A project that cargo-custom will try to build.
+ let p = project().file("src/lib.rs", "").build();
+
+ // Create a custom cargo subcommand.
+ // This will modify PATH to a custom toolchain and call cargo from that.
+ make_exe(
+ &cargo_bin,
+ "cargo-custom",
+ r#"
+ use std::env;
+ use std::process::Command;
+
+ eprintln!("custom command running");
+
+ let mut paths = vec![std::path::PathBuf::from(env!("CARGO_RUSTUP_TEST_custom_bin"))];
+ paths.extend(env::split_paths(&env::var_os("PATH").unwrap_or_default()));
+ let path = env::join_paths(paths).unwrap();
+
+ let status = Command::new("cargo")
+ .arg("check")
+ .current_dir(env!("CARGO_RUSTUP_TEST_project_dir"))
+ .env("PATH", path)
+ .status()
+ .unwrap();
+ assert!(status.success());
+ "#,
+ &[
+ ("CARGO_RUSTUP_TEST_custom_bin", custom_bin),
+ ("CARGO_RUSTUP_TEST_project_dir", p.root()),
+ ],
+ );
+
+ cargo_process("custom")
+ // Set these to simulate what would happen when running under rustup.
+ // We want to make sure that cargo-custom does not try to use the
+ // rustup proxies.
+ .env("RUSTUP_TOOLCHAIN", "test-toolchain")
+ .env("RUSTUP_HOME", &rustup_home)
+ .with_stderr(
+ "\
+custom command running
+[CHECKING] foo [..]
+custom toolchain rustc running
+[FINISHED] [..]
+",
+ )
+ .run();
+}
diff --git a/src/tools/cargo/tests/testsuite/tree.rs b/src/tools/cargo/tests/testsuite/tree.rs
index c3c1ca6d3..e2e74c4f9 100644
--- a/src/tools/cargo/tests/testsuite/tree.rs
+++ b/src/tools/cargo/tests/testsuite/tree.rs
@@ -1086,6 +1086,59 @@ fn duplicates_with_target() {
}
#[cargo_test]
+fn duplicates_with_proc_macro() {
+ Package::new("dupe-dep", "1.0.0").publish();
+ Package::new("dupe-dep", "2.0.0").publish();
+ Package::new("proc", "1.0.0")
+ .proc_macro(true)
+ .dep("dupe-dep", "1.0")
+ .publish();
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ proc = "1.0"
+ dupe-dep = "2.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+
+ p.cargo("tree")
+ .with_stdout(
+ "\
+foo v0.1.0 ([..]/foo)
+├── dupe-dep v2.0.0
+└── proc v1.0.0 (proc-macro)
+ └── dupe-dep v1.0.0
+",
+ )
+ .run();
+
+ p.cargo("tree --duplicates")
+ .with_stdout(
+ "\
+dupe-dep v1.0.0
+└── proc v1.0.0 (proc-macro)
+ └── foo v0.1.0 ([..]/foo)
+
+dupe-dep v2.0.0
+└── foo v0.1.0 ([..]/foo)
+",
+ )
+ .run();
+
+ p.cargo("tree --duplicates --edges no-proc-macro")
+ .with_stdout("")
+ .run();
+}
+
+#[cargo_test]
fn charset() {
let p = make_simple_proj();
p.cargo("tree --charset ascii")
@@ -1540,8 +1593,6 @@ somedep v1.0.0
"\
somedep v1.0.0
└── foo v0.1.0 ([..]/foo)
-
-somedep v1.0.0
",
)
.run();
diff --git a/src/tools/cargo/tests/testsuite/update.rs b/src/tools/cargo/tests/testsuite/update.rs
index 057c8fca4..1d3ee05b7 100644
--- a/src/tools/cargo/tests/testsuite/update.rs
+++ b/src/tools/cargo/tests/testsuite/update.rs
@@ -633,6 +633,9 @@ fn update_precise_first_run() {
"workspace_members": [
"bar 0.0.1 (path+file://[..]/foo)"
],
+ "workspace_default_members": [
+ "bar 0.0.1 (path+file://[..]/foo)"
+ ],
"workspace_root": "[..]/foo",
"metadata": null
}"#,
diff --git a/src/tools/cargo/tests/testsuite/vendor.rs b/src/tools/cargo/tests/testsuite/vendor.rs
index 21a1c097c..2b8b090c2 100644
--- a/src/tools/cargo/tests/testsuite/vendor.rs
+++ b/src/tools/cargo/tests/testsuite/vendor.rs
@@ -1051,10 +1051,11 @@ fn vendor_preserves_permissions() {
p.cargo("vendor --respect-source-config").run();
+ let umask = cargo::util::get_umask();
let metadata = fs::metadata(p.root().join("vendor/bar/src/lib.rs")).unwrap();
- assert_eq!(metadata.mode() & 0o777, 0o644);
+ assert_eq!(metadata.mode() & 0o777, 0o644 & !umask);
let metadata = fs::metadata(p.root().join("vendor/bar/example.sh")).unwrap();
- assert_eq!(metadata.mode() & 0o777, 0o755);
+ assert_eq!(metadata.mode() & 0o777, 0o755 & !umask);
}
#[cargo_test]
diff --git a/src/tools/cargo/tests/testsuite/weak_dep_features.rs b/src/tools/cargo/tests/testsuite/weak_dep_features.rs
index ee91114df..6f7c03547 100644
--- a/src/tools/cargo/tests/testsuite/weak_dep_features.rs
+++ b/src/tools/cargo/tests/testsuite/weak_dep_features.rs
@@ -601,6 +601,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
"readme": null,
"readme_file": null,
"repository": null,
+ "rust_version": null,
"vers": "0.1.0"
}
"#,