diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index ac5deed0e81a..f7298685814a 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -943,56 +943,53 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()> if matches!(shell.verbosity(), crate::core::shell::Verbosity::Quiet) { return Ok(()); } + let (activated, deactivated) = dep.features(); - if !activated.is_empty() || !deactivated.is_empty() { - let prefix = format!("{:>13}", " "); - let suffix = format_feature_version_suffix(&dep); + if activated.is_empty() && deactivated.is_empty() { + return Ok(()); + } - shell.write_stderr(format_args!("{}Features{}:\n", prefix, suffix), &style::NOP)?; + let prefix = format!("{:>13}", " "); + let suffix = format_features_version_suffix(&dep); - const MAX_FEATURE_PRINTS: usize = 50; + shell.write_stderr(format_args!("{prefix}Features{suffix}:\n"), &style::NOP)?; - let mut activated_printed = 0; - let total_activated = activated.len(); - for feat in activated { - if activated_printed >= MAX_FEATURE_PRINTS { - let remaining = total_activated - activated_printed; - shell.write_stderr( - format_args!("{prefix}... {remaining} more activated features\n"), - &style::NOP, - )?; - break; - } + const MAX_FEATURE_PRINTS: usize = 30; + let total_activated = activated.len(); + let total_deactivated = deactivated.len(); + if total_activated <= MAX_FEATURE_PRINTS { + for feat in activated { shell.write_stderr(&prefix, &style::NOP)?; shell.write_stderr('+', &style::GOOD)?; - shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?; - activated_printed += 1; + shell.write_stderr(format_args!(" {feat}\n"), &style::NOP)?; } + } + else { + shell.write_stderr( + format_args!("{prefix}{total_activated} activated features\n"), + &style::NOP, + )?; + } - let mut deactivated_printed = 0; - let total_deactivated = deactivated.len(); + if total_activated + total_deactivated <= MAX_FEATURE_PRINTS { for feat in deactivated { - if activated_printed + deactivated_printed >= MAX_FEATURE_PRINTS { - let remaining = total_deactivated - deactivated_printed; - shell.write_stderr( - format_args!("{prefix}... {remaining} more deactivated features\n"), - &style::NOP, - )?; - break; - } - shell.write_stderr(&prefix, &style::NOP)?; shell.write_stderr('-', &style::ERROR)?; - shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?; - deactivated_printed += 1; + shell.write_stderr(format_args!(" {feat}\n"), &style::NOP)?; } } + else { + shell.write_stderr( + format_args!("{prefix}{total_deactivated} deactivated features\n"), + &style::NOP, + )?; + } Ok(()) } -fn format_feature_version_suffix(dep: &DependencyUI) -> String { +fn format_features_version_suffix(dep: &DependencyUI) -> String { if let Some(version) = &dep.available_version { let mut version = version.clone(); version.build = Default::default(); diff --git a/tests/testsuite/cargo_add/features_too_many_activated/in/Cargo.toml b/tests/testsuite/cargo_add/features_activated_over_limit/in/Cargo.toml similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_activated/in/Cargo.toml rename to tests/testsuite/cargo_add/features_activated_over_limit/in/Cargo.toml diff --git a/tests/testsuite/cargo_add/features_too_many_activated/in/src/lib.rs b/tests/testsuite/cargo_add/features_activated_over_limit/in/src/lib.rs similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_activated/in/src/lib.rs rename to tests/testsuite/cargo_add/features_activated_over_limit/in/src/lib.rs diff --git a/tests/testsuite/cargo_add/features_too_many_activated/mod.rs b/tests/testsuite/cargo_add/features_activated_over_limit/mod.rs similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_activated/mod.rs rename to tests/testsuite/cargo_add/features_activated_over_limit/mod.rs diff --git a/tests/testsuite/cargo_add/features_too_many_activated/out/Cargo.toml b/tests/testsuite/cargo_add/features_activated_over_limit/out/Cargo.toml similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_activated/out/Cargo.toml rename to tests/testsuite/cargo_add/features_activated_over_limit/out/Cargo.toml diff --git a/tests/testsuite/cargo_add/features_activated_over_limit/stderr.log b/tests/testsuite/cargo_add/features_activated_over_limit/stderr.log new file mode 100644 index 000000000000..9288319aa395 --- /dev/null +++ b/tests/testsuite/cargo_add/features_activated_over_limit/stderr.log @@ -0,0 +1,5 @@ + Updating `dummy-registry` index + Adding your-face v99999.0.0 to dependencies. + Features: + 100 activated features + 100 deactivated features diff --git a/tests/testsuite/cargo_add/features_too_many_activated/stdout.log b/tests/testsuite/cargo_add/features_activated_over_limit/stdout.log similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_activated/stdout.log rename to tests/testsuite/cargo_add/features_activated_over_limit/stdout.log diff --git a/tests/testsuite/cargo_add/features_too_many_few_activated/in/Cargo.toml b/tests/testsuite/cargo_add/features_deactivated_over_limit/in/Cargo.toml similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_few_activated/in/Cargo.toml rename to tests/testsuite/cargo_add/features_deactivated_over_limit/in/Cargo.toml diff --git a/tests/testsuite/cargo_add/features_too_many_few_activated/in/src/lib.rs b/tests/testsuite/cargo_add/features_deactivated_over_limit/in/src/lib.rs similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_few_activated/in/src/lib.rs rename to tests/testsuite/cargo_add/features_deactivated_over_limit/in/src/lib.rs diff --git a/tests/testsuite/cargo_add/features_too_many_few_activated/mod.rs b/tests/testsuite/cargo_add/features_deactivated_over_limit/mod.rs similarity index 96% rename from tests/testsuite/cargo_add/features_too_many_few_activated/mod.rs rename to tests/testsuite/cargo_add/features_deactivated_over_limit/mod.rs index 4b7114c16904..b2ed6f87d860 100644 --- a/tests/testsuite/cargo_add/features_too_many_few_activated/mod.rs +++ b/tests/testsuite/cargo_add/features_deactivated_over_limit/mod.rs @@ -8,7 +8,7 @@ use cargo_test_support::curr_dir; #[cargo_test] fn case() { const MANY_FEATURES_COUNT: usize = 200; - const ACTIVATED_FEATURES_COUNT: usize = 10; + const ACTIVATED_FEATURES_COUNT: usize = 30; cargo_test_support::registry::init(); let mut test_package = diff --git a/tests/testsuite/cargo_add/features_deactivated_over_limit/out/Cargo.toml b/tests/testsuite/cargo_add/features_deactivated_over_limit/out/Cargo.toml new file mode 100644 index 000000000000..b94cde668a65 --- /dev/null +++ b/tests/testsuite/cargo_add/features_deactivated_over_limit/out/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] + +[package] +name = "cargo-list-test-fixture" +version = "0.0.0" + +[dependencies] +your-face = { version = "99999.0.0", features = ["eyes000", "eyes001", "eyes002", "eyes003", "eyes004", "eyes005", "eyes006", "eyes007", "eyes008", "eyes009", "eyes010", "eyes011", "eyes012", "eyes013", "eyes014", "eyes015", "eyes016", "eyes017", "eyes018", "eyes019", "eyes020", "eyes021", "eyes022", "eyes023", "eyes024", "eyes025", "eyes026", "eyes027", "eyes028", "eyes029"] } diff --git a/tests/testsuite/cargo_add/features_too_many_activated/stderr.log b/tests/testsuite/cargo_add/features_deactivated_over_limit/stderr.log similarity index 59% rename from tests/testsuite/cargo_add/features_too_many_activated/stderr.log rename to tests/testsuite/cargo_add/features_deactivated_over_limit/stderr.log index 05e69dbc7bca..7f74e6bf0805 100644 --- a/tests/testsuite/cargo_add/features_too_many_activated/stderr.log +++ b/tests/testsuite/cargo_add/features_deactivated_over_limit/stderr.log @@ -31,25 +31,4 @@ + eyes027 + eyes028 + eyes029 - + eyes030 - + eyes031 - + eyes032 - + eyes033 - + eyes034 - + eyes035 - + eyes036 - + eyes037 - + eyes038 - + eyes039 - + eyes040 - + eyes041 - + eyes042 - + eyes043 - + eyes044 - + eyes045 - + eyes046 - + eyes047 - + eyes048 - + eyes049 - ... 50 more activated features - ... 100 more deactivated features + 170 deactivated features diff --git a/tests/testsuite/cargo_add/features_too_many_few_activated/stdout.log b/tests/testsuite/cargo_add/features_deactivated_over_limit/stdout.log similarity index 100% rename from tests/testsuite/cargo_add/features_too_many_few_activated/stdout.log rename to tests/testsuite/cargo_add/features_deactivated_over_limit/stdout.log diff --git a/tests/testsuite/cargo_add/features_too_many_few_activated/out/Cargo.toml b/tests/testsuite/cargo_add/features_too_many_few_activated/out/Cargo.toml deleted file mode 100644 index 82e0197df5a7..000000000000 --- a/tests/testsuite/cargo_add/features_too_many_few_activated/out/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] - -[package] -name = "cargo-list-test-fixture" -version = "0.0.0" - -[dependencies] -your-face = { version = "99999.0.0", features = ["eyes000", "eyes001", "eyes002", "eyes003", "eyes004", "eyes005", "eyes006", "eyes007", "eyes008", "eyes009"] } diff --git a/tests/testsuite/cargo_add/features_too_many_few_activated/stderr.log b/tests/testsuite/cargo_add/features_too_many_few_activated/stderr.log deleted file mode 100644 index c76c35caea21..000000000000 --- a/tests/testsuite/cargo_add/features_too_many_few_activated/stderr.log +++ /dev/null @@ -1,54 +0,0 @@ - Updating `dummy-registry` index - Adding your-face v99999.0.0 to dependencies. - Features: - + eyes000 - + eyes001 - + eyes002 - + eyes003 - + eyes004 - + eyes005 - + eyes006 - + eyes007 - + eyes008 - + eyes009 - - eyes010 - - eyes011 - - eyes012 - - eyes013 - - eyes014 - - eyes015 - - eyes016 - - eyes017 - - eyes018 - - eyes019 - - eyes020 - - eyes021 - - eyes022 - - eyes023 - - eyes024 - - eyes025 - - eyes026 - - eyes027 - - eyes028 - - eyes029 - - eyes030 - - eyes031 - - eyes032 - - eyes033 - - eyes034 - - eyes035 - - eyes036 - - eyes037 - - eyes038 - - eyes039 - - eyes040 - - eyes041 - - eyes042 - - eyes043 - - eyes044 - - eyes045 - - eyes046 - - eyes047 - - eyes048 - - eyes049 - ... 150 more deactivated features diff --git a/tests/testsuite/cargo_add/mod.rs b/tests/testsuite/cargo_add/mod.rs index 47a595cd9299..8c03b30dce67 100644 --- a/tests/testsuite/cargo_add/mod.rs +++ b/tests/testsuite/cargo_add/mod.rs @@ -18,12 +18,12 @@ mod dev_prefer_existing_version; mod dry_run; mod empty_dep_table; mod features; +mod features_activated_over_limit; +mod features_deactivated_over_limit; mod features_empty; mod features_multiple_occurrences; mod features_preserve; mod features_spaced_values; -mod features_too_many_activated; -mod features_too_many_few_activated; mod features_unknown; mod features_unknown_no_features; mod git;