Skip to content

Commit f2c5276

Browse files
committed
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
2 parents 64c803f + 18f7dfe commit f2c5276

File tree

7 files changed

+33
-3
lines changed

7 files changed

+33
-3
lines changed

src/bin/cargo/commands/add.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ Example uses:
8181
.takes_value(true)
8282
.value_name("SPEC")
8383
.help("Package to modify"),
84-
clap::Arg::new("offline")
85-
.long("offline")
86-
.help("Run without accessing the network")
8784
])
8885
.arg_quiet()
8986
.arg_dry_run("Don't actually write the manifest")

tests/testsuite/cargo_add/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ mod namever;
5656
mod no_args;
5757
mod no_default_features;
5858
mod no_optional;
59+
mod offline_empty_cache;
5960
mod optional;
6061
mod overwrite_default_features;
6162
mod overwrite_default_features_with_no_default_features;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../add-basic.in
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use crate::cargo_add::init_registry;
6+
use cargo_test_support::curr_dir;
7+
8+
#[cargo_test]
9+
fn offline_empty_cache() {
10+
init_registry();
11+
let project = Project::from_template(curr_dir!().join("in"));
12+
let project_root = project.root();
13+
let cwd = &project_root;
14+
15+
snapbox::cmd::Command::cargo_ui()
16+
.arg("add")
17+
.arg_line("--offline my-package")
18+
.current_dir(cwd)
19+
.assert()
20+
.code(101)
21+
.stdout_matches_path(curr_dir!().join("stdout.log"))
22+
.stderr_matches_path(curr_dir!().join("stderr.log"));
23+
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error: the crate `my-package` could not be found in registry index.

tests/testsuite/cargo_add/offline_empty_cache/stdout.log

Whitespace-only changes.

0 commit comments

Comments
 (0)