Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit cargo add feature print #12662

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,45 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
} else {
"".to_owned()
};

shell.write_stderr(format_args!("{}Features{}:\n", prefix, suffix), &style::NOP)?;

const MAX_FEATURE_PRINTS: usize = 50;

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;
}

shell.write_stderr(&prefix, &style::NOP)?;
shell.write_stderr('+', &style::GOOD)?;
shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?;
activated_printed += 1;
}

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;
}

shell.write_stderr(&prefix, &style::NOP)?;
shell.write_stderr('-', &style::ERROR)?;
shell.write_stderr(format_args!(" {}\n", feat), &style::NOP)?;
deactivated_printed += 1;
}
}

Expand Down
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"
Empty file.
38 changes: 38 additions & 0 deletions tests/testsuite/cargo_add/features_too_many_activated/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;
use itertools::Itertools;

use cargo_test_support::curr_dir;

#[cargo_test]
fn case() {
const MANY_FEATURES_COUNT: usize = 200;
const ACTIVATED_FEATURES_COUNT: usize = 100;

cargo_test_support::registry::init();
let mut test_package =
cargo_test_support::registry::Package::new("your-face", "99999.0.0+my-package");
for i in 0..MANY_FEATURES_COUNT {
test_package.feature(format!("eyes{i:03}").as_str(), &[]);
}
test_package.publish();

let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

let features = (0..ACTIVATED_FEATURES_COUNT)
.map(|i| format!("eyes{i:03}"))
.join(",");
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line(format!("your-face --features {features}").as_str())
.current_dir(cwd)
.assert()
.success()
.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);
}
Original file line number Diff line number Diff line change
@@ -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", "eyes030", "eyes031", "eyes032", "eyes033", "eyes034", "eyes035", "eyes036", "eyes037", "eyes038", "eyes039", "eyes040", "eyes041", "eyes042", "eyes043", "eyes044", "eyes045", "eyes046", "eyes047", "eyes048", "eyes049", "eyes050", "eyes051", "eyes052", "eyes053", "eyes054", "eyes055", "eyes056", "eyes057", "eyes058", "eyes059", "eyes060", "eyes061", "eyes062", "eyes063", "eyes064", "eyes065", "eyes066", "eyes067", "eyes068", "eyes069", "eyes070", "eyes071", "eyes072", "eyes073", "eyes074", "eyes075", "eyes076", "eyes077", "eyes078", "eyes079", "eyes080", "eyes081", "eyes082", "eyes083", "eyes084", "eyes085", "eyes086", "eyes087", "eyes088", "eyes089", "eyes090", "eyes091", "eyes092", "eyes093", "eyes094", "eyes095", "eyes096", "eyes097", "eyes098", "eyes099"] }
55 changes: 55 additions & 0 deletions tests/testsuite/cargo_add/features_too_many_activated/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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
... 50 more activated features
... 100 more deactivated features
Empty file.
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"
Empty file.
38 changes: 38 additions & 0 deletions tests/testsuite/cargo_add/features_too_many_few_activated/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;
use itertools::Itertools;

use cargo_test_support::curr_dir;

#[cargo_test]
fn case() {
const MANY_FEATURES_COUNT: usize = 200;
const ACTIVATED_FEATURES_COUNT: usize = 10;

cargo_test_support::registry::init();
let mut test_package =
cargo_test_support::registry::Package::new("your-face", "99999.0.0+my-package");
for i in 0..MANY_FEATURES_COUNT {
test_package.feature(format!("eyes{i:03}").as_str(), &[]);
}
test_package.publish();

let project = Project::from_template(curr_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

let features = (0..ACTIVATED_FEATURES_COUNT)
.map(|i| format!("eyes{i:03}"))
.join(",");
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line(format!("your-face --features {features}").as_str())
.current_dir(cwd)
.assert()
.success()
.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);
}
Original file line number Diff line number Diff line change
@@ -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"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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
Empty file.
2 changes: 2 additions & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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;
Expand Down