From 05ca6a8ff1821403e25771f0c5842443d4ef156a Mon Sep 17 00:00:00 2001 From: John Higgins Date: Mon, 18 Jul 2022 22:07:43 -0700 Subject: [PATCH 1/4] Made unactivated features that start with `_` not visible. --- src/cargo/ops/cargo_add/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index dff93e91b02..9757638e9b4 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -705,9 +705,17 @@ fn print_msg(shell: &mut Shell, dep: &Dependency, section: &[String]) -> CargoRe shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; } for feat in deactivated { - shell.write_stderr(&prefix, &ColorSpec::new())?; - shell.write_stderr('-', &ColorSpec::new().set_bold(true).set_fg(Some(Red)))?; - shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; + let is_hidden = feat + .chars() + .nth(0) + .map(|c| c == '_') + .unwrap_or(false); + + if !is_hidden { + shell.write_stderr(&prefix, &ColorSpec::new())?; + shell.write_stderr('-', &ColorSpec::new().set_bold(true).set_fg(Some(Red)))?; + shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; + } } } From a85a5d9cb5358fa82e0e9a90ca59f29f83806695 Mon Sep 17 00:00:00 2001 From: John Higgins Date: Mon, 18 Jul 2022 23:03:10 -0700 Subject: [PATCH 2/4] Formatted with `cargo fmt` --- src/cargo/ops/cargo_add/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index 9757638e9b4..8081656d4a2 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -705,11 +705,7 @@ fn print_msg(shell: &mut Shell, dep: &Dependency, section: &[String]) -> CargoRe shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; } for feat in deactivated { - let is_hidden = feat - .chars() - .nth(0) - .map(|c| c == '_') - .unwrap_or(false); + let is_hidden = feat.chars().nth(0).map(|c| c == '_').unwrap_or(false); if !is_hidden { shell.write_stderr(&prefix, &ColorSpec::new())?; From c4a747d43b863c2028166ff262b5e31dc0b298e9 Mon Sep 17 00:00:00 2001 From: John Higgins Date: Wed, 20 Jul 2022 16:54:36 -0700 Subject: [PATCH 3/4] Added tests for hiding hidden features. --- .../add_hidden_activated/in/Cargo.toml | 9 +++++++++ .../add_hidden_activated/in/src/main.rs | 3 +++ .../cargo_add/add_hidden_activated/mod.rs | 20 +++++++++++++++++++ .../cargo_add/add_hidden_activated/stderr.log | 5 +++++ .../cargo_add/add_hidden_activated/stdout.log | 0 .../add_hidden_unactivated/in/Cargo.toml | 9 +++++++++ .../add_hidden_unactivated/in/src/main.rs | 3 +++ .../cargo_add/add_hidden_unactivated/mod.rs | 20 +++++++++++++++++++ .../add_hidden_unactivated/stderr.log | 4 ++++ .../add_hidden_unactivated/stdout.log | 0 tests/testsuite/cargo_add/mod.rs | 8 ++++++++ 11 files changed, 81 insertions(+) create mode 100644 tests/testsuite/cargo_add/add_hidden_activated/in/Cargo.toml create mode 100644 tests/testsuite/cargo_add/add_hidden_activated/in/src/main.rs create mode 100644 tests/testsuite/cargo_add/add_hidden_activated/mod.rs create mode 100644 tests/testsuite/cargo_add/add_hidden_activated/stderr.log create mode 100644 tests/testsuite/cargo_add/add_hidden_activated/stdout.log create mode 100644 tests/testsuite/cargo_add/add_hidden_unactivated/in/Cargo.toml create mode 100644 tests/testsuite/cargo_add/add_hidden_unactivated/in/src/main.rs create mode 100644 tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs create mode 100644 tests/testsuite/cargo_add/add_hidden_unactivated/stderr.log create mode 100644 tests/testsuite/cargo_add/add_hidden_unactivated/stdout.log diff --git a/tests/testsuite/cargo_add/add_hidden_activated/in/Cargo.toml b/tests/testsuite/cargo_add/add_hidden_activated/in/Cargo.toml new file mode 100644 index 00000000000..a476bf737a5 --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_activated/in/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "main" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +hidden = { version = "0.1.0", path = "../hidden" } diff --git a/tests/testsuite/cargo_add/add_hidden_activated/in/src/main.rs b/tests/testsuite/cargo_add/add_hidden_activated/in/src/main.rs new file mode 100644 index 00000000000..e7a11a969c0 --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_activated/in/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/testsuite/cargo_add/add_hidden_activated/mod.rs b/tests/testsuite/cargo_add/add_hidden_activated/mod.rs new file mode 100644 index 00000000000..d78d53414fa --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_activated/mod.rs @@ -0,0 +1,20 @@ +use cargo_test_support::prelude::*; +use cargo_test_support::Project; +use cargo_test_support::curr_dir; + +use crate::cargo_add::init_registry; + +#[cargo_test] +fn add_hidden_activated() { + init_registry(); + let project = Project::from_template(curr_dir!().join("in")); + let cwd = &project.root(); + + snapbox::cmd::Command::cargo_ui() + .current_dir(cwd) + .args(&["add", "hidden-feature-test", "--features", "_secret"]) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); +} diff --git a/tests/testsuite/cargo_add/add_hidden_activated/stderr.log b/tests/testsuite/cargo_add/add_hidden_activated/stderr.log new file mode 100644 index 00000000000..882b103ce60 --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_activated/stderr.log @@ -0,0 +1,5 @@ + Updating `dummy-registry` index + Adding hidden-feature-test v99999.0.0 to dependencies. + Features: + + _secret + - not_secret diff --git a/tests/testsuite/cargo_add/add_hidden_activated/stdout.log b/tests/testsuite/cargo_add/add_hidden_activated/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/add_hidden_unactivated/in/Cargo.toml b/tests/testsuite/cargo_add/add_hidden_unactivated/in/Cargo.toml new file mode 100644 index 00000000000..a476bf737a5 --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_unactivated/in/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "main" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +hidden = { version = "0.1.0", path = "../hidden" } diff --git a/tests/testsuite/cargo_add/add_hidden_unactivated/in/src/main.rs b/tests/testsuite/cargo_add/add_hidden_unactivated/in/src/main.rs new file mode 100644 index 00000000000..e7a11a969c0 --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_unactivated/in/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs b/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs new file mode 100644 index 00000000000..72c574ff51c --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs @@ -0,0 +1,20 @@ +use cargo_test_support::prelude::*; +use cargo_test_support::Project; +use cargo_test_support::curr_dir; + +use crate::cargo_add::init_registry; + +#[cargo_test] +fn add_hidden_unactivated() { + init_registry(); + let project = Project::from_template(curr_dir!().join("in")); + let cwd = &project.root(); + + snapbox::cmd::Command::cargo_ui() + .current_dir(cwd) + .args(&["add", "hidden-feature-test"]) + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); +} diff --git a/tests/testsuite/cargo_add/add_hidden_unactivated/stderr.log b/tests/testsuite/cargo_add/add_hidden_unactivated/stderr.log new file mode 100644 index 00000000000..8edbe4f3549 --- /dev/null +++ b/tests/testsuite/cargo_add/add_hidden_unactivated/stderr.log @@ -0,0 +1,4 @@ + Updating `dummy-registry` index + Adding hidden-feature-test v99999.0.0 to dependencies. + Features: + - not_secret diff --git a/tests/testsuite/cargo_add/add_hidden_unactivated/stdout.log b/tests/testsuite/cargo_add/add_hidden_unactivated/stdout.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs index 1eb682ef2ed..8545b9bd15a 100644 --- a/tests/testsuite/cargo_add/mod.rs +++ b/tests/testsuite/cargo_add/mod.rs @@ -1,4 +1,6 @@ mod add_basic; +mod add_hidden_activated; +mod add_hidden_unactivated; mod add_multiple; mod add_normalized_name_external; mod build; @@ -185,4 +187,10 @@ fn add_registry_packages(alt: bool) { .feature("eyes", &[]) .feature("ears", &[]) .publish(); + + cargo_test_support::registry::Package::new("hidden-feature-test", "99999.0.0+my-package") + .alternative(alt) + .feature("_secret", &[]) + .feature("not_secret", &[]) + .publish(); } From 3c4fa0b5f9beb593b43c9c366862c72ccdab0eae Mon Sep 17 00:00:00 2001 From: John Higgins Date: Wed, 20 Jul 2022 17:10:42 -0700 Subject: [PATCH 4/4] Used `starts_with()` instead of string of calls. --- src/cargo/ops/cargo_add/mod.rs | 2 +- tests/testsuite/cargo_add/add_hidden_activated/mod.rs | 2 +- tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index 8081656d4a2..050307de05b 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -705,7 +705,7 @@ fn print_msg(shell: &mut Shell, dep: &Dependency, section: &[String]) -> CargoRe shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?; } for feat in deactivated { - let is_hidden = feat.chars().nth(0).map(|c| c == '_').unwrap_or(false); + let is_hidden = feat.starts_with('_'); if !is_hidden { shell.write_stderr(&prefix, &ColorSpec::new())?; diff --git a/tests/testsuite/cargo_add/add_hidden_activated/mod.rs b/tests/testsuite/cargo_add/add_hidden_activated/mod.rs index d78d53414fa..0d1e2d6f252 100644 --- a/tests/testsuite/cargo_add/add_hidden_activated/mod.rs +++ b/tests/testsuite/cargo_add/add_hidden_activated/mod.rs @@ -1,6 +1,6 @@ +use cargo_test_support::curr_dir; use cargo_test_support::prelude::*; use cargo_test_support::Project; -use cargo_test_support::curr_dir; use crate::cargo_add::init_registry; diff --git a/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs b/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs index 72c574ff51c..6bb6808c6f6 100644 --- a/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs +++ b/tests/testsuite/cargo_add/add_hidden_unactivated/mod.rs @@ -1,6 +1,6 @@ +use cargo_test_support::curr_dir; use cargo_test_support::prelude::*; use cargo_test_support::Project; -use cargo_test_support::curr_dir; use crate::cargo_add::init_registry;