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

Breaking endless loop on cyclic features in added dependency in cargo-add #11805

Merged
merged 1 commit into from
Mar 6, 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
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ impl DependencyUI {
.get(next)
.into_iter()
.flatten()
.map(|s| s.as_str()),
.map(|s| s.as_str())
.filter(|s| !activated.contains(s)),
);
activated.extend(
self.available_features
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/cyclic_features/in
25 changes: 25 additions & 0 deletions tests/testsuite/cargo_add/cyclic_features/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 case() {
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("test_cyclic_features")
.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);
}
8 changes: 8 additions & 0 deletions tests/testsuite/cargo_add/cyclic_features/out/Cargo.toml
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]
test_cyclic_features = "0.1.1"
5 changes: 5 additions & 0 deletions tests/testsuite/cargo_add/cyclic_features/stderr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Updating `dummy-registry` index
Adding test_cyclic_features v0.1.1 to dependencies.
Features:
+ feature-one
+ feature-two
Empty file.
7 changes: 7 additions & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod add_normalized_name_external;
mod build;
mod build_prefer_existing_version;
mod change_rename_target;
mod cyclic_features;
mod default_features;
mod deprecated_default_features;
mod deprecated_section;
Expand Down Expand Up @@ -165,6 +166,12 @@ fn add_registry_packages(alt: bool) {
cargo_test_support::registry::Package::new("test_nonbreaking", "0.1.1")
.alternative(alt)
.publish();
cargo_test_support::registry::Package::new("test_cyclic_features", "0.1.1")
.alternative(alt)
.feature("default", &["feature-one", "feature-two"])
.feature("feature-one", &["feature-two"])
.feature("feature-two", &["feature-one"])
.publish();

// Normalization
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4")
Expand Down