-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
7 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
tests/testsuite/cargo_add/overwrite_preserves_inline_table/in/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=["eyes"]} # Hello world |
Empty file.
25 changes: 25 additions & 0 deletions
25
tests/testsuite/cargo_add/overwrite_preserves_inline_table/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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); | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/testsuite/cargo_add/overwrite_preserves_inline_table/out/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ["eyes", "nose"] } # Hello world |
7 changes: 7 additions & 0 deletions
7
tests/testsuite/cargo_add/overwrite_preserves_inline_table/stderr.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Updating `dummy-registry` index | ||
Adding your-face v99999.0.0 to dependencies. | ||
Features: | ||
+ eyes | ||
+ nose | ||
- ears | ||
- mouth |
Empty file.