diff --git a/src/cargo/ops/cargo_add/mod.rs b/src/cargo/ops/cargo_add/mod.rs index 6bab52e4075..968d6068f6a 100644 --- a/src/cargo/ops/cargo_add/mod.rs +++ b/src/cargo/ops/cargo_add/mod.rs @@ -943,72 +943,69 @@ 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 = if let Some(version) = &dep.available_version { - let mut version = version.clone(); - version.build = Default::default(); - let version = version.to_string(); - // Avoid displaying the version if it will visually look like the version req that we - // showed earlier - let version_req = dep - .version() - .and_then(|v| semver::VersionReq::parse(v).ok()) - .and_then(|v| precise_version(&v)); - if version_req.as_deref() != Some(version.as_str()) { - format!(" as of v{version}") - } else { - "".to_owned() - } - } else { - "".to_owned() - }; + let suffix = format_features_version_suffix(&dep); - shell.write_stderr(format_args!("{}Features{}:\n", prefix, suffix), &style::NOP)?; + shell.write_stderr(format_args!("{prefix}Features{suffix}:\n"), &style::NOP)?; - const MAX_FEATURE_PRINTS: usize = 50; - - let mut activated_printed = 0; + const MAX_FEATURE_PRINTS: usize = 30; 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; - } + let total_deactivated = deactivated.len(); - shell.write_stderr(&prefix, &style::NOP)?; - shell.write_stderr('+', &style::GOOD)?; - shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?; - activated_printed += 1; + 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!(" {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(); - 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; + if total_activated + total_deactivated <= MAX_FEATURE_PRINTS { + for feat in deactivated { + shell.write_stderr(&prefix, &style::NOP)?; + shell.write_stderr('-', &style::ERROR)?; + shell.write_stderr(format_args!(" {feat}\n"), &style::NOP)?; } - - shell.write_stderr(&prefix, &style::NOP)?; - shell.write_stderr('-', &style::ERROR)?; - shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?; - deactivated_printed += 1; + } else { + shell.write_stderr( + format_args!("{prefix}{total_deactivated} deactivated features\n"), + &style::NOP, + )?; } } Ok(()) } +fn format_features_version_suffix(dep: &DependencyUI) -> String { + if let Some(version) = &dep.available_version { + let mut version = version.clone(); + version.build = Default::default(); + let version = version.to_string(); + // Avoid displaying the version if it will visually look like the version req that we + // showed earlier + let version_req = dep + .version() + .and_then(|v| semver::VersionReq::parse(v).ok()) + .and_then(|v| precise_version(&v)); + if version_req.as_deref() != Some(version.as_str()) { + format!(" as of v{version}") + } else { + "".to_owned() + } + } else { + "".to_owned() + } +} + // Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized. fn is_sorted(mut it: impl Iterator) -> bool { let Some(mut last) = it.next() else { 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 00000000000..9288319aa39 --- /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 4b7114c1690..b2ed6f87d86 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 00000000000..b94cde668a6 --- /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 05e69dbc7bc..7f74e6bf080 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 82e0197df5a..00000000000 --- 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 c76c35caea2..00000000000 --- 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 47a595cd929..8c03b30dce6 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;