Skip to content

Commit

Permalink
fix(add): Don't panic with --offline
Browse files Browse the repository at this point in the history
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
  • Loading branch information
epage committed Jul 3, 2022
1 parent 2aa12cb commit 18f7dfe
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/offline_empty_cache/in
25 changes: 25 additions & 0 deletions tests/testsuite/cargo_add/offline_empty_cache/mod.rs
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions tests/testsuite/cargo_add/offline_empty_cache/out/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/offline_empty_cache/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: the crate `my-package` could not be found in registry index.
Empty file.

0 comments on commit 18f7dfe

Please sign in to comment.