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

cargo add check [dependencies] order without considering the dotted item #11612

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
.get_table(&dep_table)
.map(TomlItem::as_table)
.map_or(true, |table_option| {
table_option.map_or(true, |table| is_sorted(table.iter().map(|(name, _)| name)))
table_option.map_or(true, |table| {
is_sorted(
table
.get_values()
.iter()
.map(|(key, _)| key.first().unwrap().to_string()),
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
)
})
});
for dep in deps {
print_action_msg(&mut options.config.shell(), &dep, &dep_table)?;
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ mod quiet;
mod registry;
mod rename;
mod require_weak;
mod sorted_table_with_dotted_item;
mod target;
mod target_cfg;
mod unknown_inherited_feature;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"

[dependencies]
toml = "0.1.1"
versioned-package = "0.1.1"

[dependencies.my-build-package1]
version = "0.1.1"

Empty file.
25 changes: 25 additions & 0 deletions tests/testsuite/cargo_add/sorted_table_with_dotted_item/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 sorted_table_with_dotted_item() {
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("unrelateed-crate")
.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,14 @@
[workspace]

[package]
name = "cargo-list-test-fixture"
version = "0.0.0"

[dependencies]
toml = "0.1.1"
unrelateed-crate = "99999.0.0"
versioned-package = "0.1.1"

[dependencies.my-build-package1]
version = "0.1.1"

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Updating `dummy-registry` index
Adding unrelateed-crate v99999.0.0 to dependencies.
Empty file.