mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 02:25:46 +00:00
Auto merge of #10849 - epage:inline, r=ehuss
test(add): Ensure comments are preserved A comment on killercup/cargo-edit#15 had me worried that `cargo add` was deleting comments now. It appears that isn't the case for inline tables. Standard tables however do delete comments. The work to make sure they don't conflicts with another need. When changing the source, we delete the old source fields and append the new which can cause some formatting to be carried over unnecessarily. For example, what would normally look like ```toml cargo-list-test-fixture-dependency = { optional = true, path = "../dependency", version = "0.0.0" } ``` When fixed to preserve comments with my naive solution looks like ```toml cargo-list-test-fixture-dependency = { optional = true , path = "../dependency", version = "0.0.0" } ``` Note that `optional = true` used to be last, so space separating it and `}` was kept, now separating it and `,`. More work will be needed to get this into an ideal state but we can at least have confidence with inline tables for now.
This commit is contained in:
commit
44684e0dca
|
@ -76,6 +76,7 @@ mod overwrite_optional;
|
|||
mod overwrite_optional_with_no_optional;
|
||||
mod overwrite_path_noop;
|
||||
mod overwrite_path_with_version;
|
||||
mod overwrite_preserves_inline_table;
|
||||
mod overwrite_rename_with_no_rename;
|
||||
mod overwrite_rename_with_rename;
|
||||
mod overwrite_rename_with_rename_noop;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[workspace]
|
||||
|
||||
[package]
|
||||
name = "cargo-list-test-fixture"
|
||||
version = "0.0.0"
|
||||
|
||||
[dependencies]
|
||||
your-face={version="99999.0.0",features=["eyes"]} # Hello world
|
|
@ -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 overwrite_preserves_inline_table() {
|
||||
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("your-face --features nose")
|
||||
.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);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
[workspace]
|
||||
|
||||
[package]
|
||||
name = "cargo-list-test-fixture"
|
||||
version = "0.0.0"
|
||||
|
||||
[dependencies]
|
||||
your-face={ version = "99999.0.0", features = ["eyes", "nose"] } # Hello world
|
|
@ -0,0 +1,7 @@
|
|||
Updating `dummy-registry` index
|
||||
Adding your-face v99999.0.0 to dependencies.
|
||||
Features:
|
||||
+ eyes
|
||||
+ nose
|
||||
- ears
|
||||
- mouth
|
Loading…
Reference in a new issue