Auto merge of #10817 - epage:fix, r=weihanglo

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.

The new test previously paniced and now it doesn't.

Fixes #10814
This commit is contained in:
bors 2022-07-03 05:41:45 +00:00
commit f2c52767ad
7 changed files with 33 additions and 3 deletions

View file

@ -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")

View file

@ -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;

View file

@ -0,0 +1 @@
../add-basic.in

View file

@ -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);
}

View file

@ -0,0 +1,5 @@
[workspace]
[package]
name = "cargo-list-test-fixture"
version = "0.0.0"

View file

@ -0,0 +1 @@
error: the crate `my-package` could not be found in registry index.