From 18f7dfe0f584d779506991d93483b40815d24296 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 2 Jul 2022 23:04:00 -0500 Subject: [PATCH] fix(add): Don't panic with `--offline` For some reason, I defined my own `--offline` flag and it didn't get updated with the global `--offline` flag, so it started failing. Fixes #10814 --- src/bin/cargo/commands/add.rs | 3 --- tests/testsuite/cargo_add/mod.rs | 1 + .../cargo_add/offline_empty_cache/in | 1 + .../cargo_add/offline_empty_cache/mod.rs | 25 +++++++++++++++++++ .../offline_empty_cache/out/Cargo.toml | 5 ++++ .../cargo_add/offline_empty_cache/stderr.log | 1 + .../cargo_add/offline_empty_cache/stdout.log | 0 7 files changed, 33 insertions(+), 3 deletions(-) create mode 120000 tests/testsuite/cargo_add/offline_empty_cache/in create mode 100644 tests/testsuite/cargo_add/offline_empty_cache/mod.rs create mode 100644 tests/testsuite/cargo_add/offline_empty_cache/out/Cargo.toml create mode 100644 tests/testsuite/cargo_add/offline_empty_cache/stderr.log create mode 100644 tests/testsuite/cargo_add/offline_empty_cache/stdout.log diff --git a/src/bin/cargo/commands/add.rs b/src/bin/cargo/commands/add.rs index 01d178add7b..32c7699e775 100644 --- a/src/bin/cargo/commands/add.rs +++ b/src/bin/cargo/commands/add.rs @@ -81,9 +81,6 @@ Example uses: .takes_value(true) .value_name("SPEC") .help("Package to modify"), - clap::Arg::new("offline") - .long("offline") - .help("Run without accessing the network") ]) .arg_quiet() .arg_dry_run("Don't actually write the manifest") diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs index 0ae817dd4be..75213d9789d 100644 --- a/tests/testsuite/cargo_add/mod.rs +++ b/tests/testsuite/cargo_add/mod.rs @@ -56,6 +56,7 @@ mod namever; mod no_args; mod no_default_features; mod no_optional; +mod offline_empty_cache; mod optional; mod overwrite_default_features; mod overwrite_default_features_with_no_default_features; diff --git a/tests/testsuite/cargo_add/offline_empty_cache/in b/tests/testsuite/cargo_add/offline_empty_cache/in new file mode 120000 index 00000000000..6c6a27fcfb5 --- /dev/null +++ b/tests/testsuite/cargo_add/offline_empty_cache/in @@ -0,0 +1 @@ +../add-basic.in \ No newline at end of file diff --git a/tests/testsuite/cargo_add/offline_empty_cache/mod.rs b/tests/testsuite/cargo_add/offline_empty_cache/mod.rs new file mode 100644 index 00000000000..5bac2b06546 --- /dev/null +++ b/tests/testsuite/cargo_add/offline_empty_cache/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 offline_empty_cache() { + 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("--offline my-package") + .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/tests/testsuite/cargo_add/offline_empty_cache/out/Cargo.toml b/tests/testsuite/cargo_add/offline_empty_cache/out/Cargo.toml new file mode 100644 index 00000000000..3ecdb668167 --- /dev/null +++ b/tests/testsuite/cargo_add/offline_empty_cache/out/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" diff --git a/tests/testsuite/cargo_add/offline_empty_cache/stderr.log b/tests/testsuite/cargo_add/offline_empty_cache/stderr.log new file mode 100644 index 00000000000..e0260b79515 --- /dev/null +++ b/tests/testsuite/cargo_add/offline_empty_cache/stderr.log @@ -0,0 +1 @@ +error: the crate `my-package` could not be found in registry index. diff --git a/tests/testsuite/cargo_add/offline_empty_cache/stdout.log b/tests/testsuite/cargo_add/offline_empty_cache/stdout.log new file mode 100644 index 00000000000..e69de29bb2d