forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#12837 - epage:remove, r=weihanglo
fix(remove): Preserve feature comments ### What does this PR try to resolve? We've been having a hard time balancing leaving the feature list in a good looking start and preserving formatting. With our new formatting policy (rust-lang#12836), we can just choose to preserve formatting instead. Fixes rust-lang#11743 ### How should we test and review this PR? The first commit copies an existing test. The second is where the fun begins, customizing the test for some weird cases. The follow up commits do the slow walk for improving it. We ended up preserving some line-trailing comments because they come after the comma and toml_edit treats that as part of the prefix of the next item. Tracking removal of that was going to require us to determine if the newline existed in the suffix or in the next item's prefix and edit accordingly and I decided to skip that to keep this initial implementation simpler. ### Additional information
- Loading branch information
Showing
10 changed files
with
165 additions
and
8 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
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
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 |
---|---|---|
|
@@ -17,4 +17,4 @@ toml = "0.1" | |
clippy = "0.4" | ||
|
||
[features] | ||
std = ["semver/std"] | ||
std = [ "semver/std"] |
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 |
---|---|---|
|
@@ -20,4 +20,4 @@ clippy = "0.4" | |
regex = "0.1.1" | ||
|
||
[features] | ||
std = ["semver/std"] | ||
std = [ "semver/std"] |
42 changes: 42 additions & 0 deletions
42
tests/testsuite/cargo_remove/optional_dep_feature_formatting/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,42 @@ | ||
[package] | ||
name = "cargo-remove-test-fixture" | ||
version = "0.1.0" | ||
|
||
[[bin]] | ||
name = "main" | ||
path = "src/main.rs" | ||
|
||
[build-dependencies] | ||
semver = "0.1.0" | ||
|
||
[dependencies] | ||
docopt = { version = "0.6", optional = true } | ||
rustc-serialize = { version = "0.4", optional = true } | ||
semver = "0.1" | ||
toml = { version = "0.1", optional = true } | ||
clippy = { version = "0.4", optional = true } | ||
|
||
[dev-dependencies] | ||
regex = "0.1.1" | ||
serde = "1.0.90" | ||
|
||
[features] | ||
std = [ | ||
# Leading clippy | ||
"dep:clippy", # trailing clippy | ||
|
||
# Leading docopt | ||
"dep:docopt", # trailing docopt | ||
|
||
# Leading rustc-serialize | ||
"dep:rustc-serialize", # trailing rustc-serialize | ||
|
||
# Leading serde/std | ||
"serde/std", # trailing serde/std | ||
|
||
# Leading semver/std | ||
"semver/std", # trailing semver/std | ||
|
||
# Leading toml | ||
"dep:toml", # trailing toml | ||
] |
1 change: 1 addition & 0 deletions
1
tests/testsuite/cargo_remove/optional_dep_feature_formatting/in/src/lib.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 @@ | ||
|
35 changes: 35 additions & 0 deletions
35
tests/testsuite/cargo_remove/optional_dep_feature_formatting/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,35 @@ | ||
use cargo_test_support::compare::assert_ui; | ||
use cargo_test_support::curr_dir; | ||
use cargo_test_support::CargoCommand; | ||
use cargo_test_support::Project; | ||
|
||
#[cargo_test] | ||
fn case() { | ||
cargo_test_support::registry::init(); | ||
cargo_test_support::registry::Package::new("clippy", "0.4.0+my-package").publish(); | ||
cargo_test_support::registry::Package::new("docopt", "0.6.2+my-package").publish(); | ||
cargo_test_support::registry::Package::new("regex", "0.1.1+my-package").publish(); | ||
cargo_test_support::registry::Package::new("rustc-serialize", "0.4.0+my-package").publish(); | ||
cargo_test_support::registry::Package::new("toml", "0.1.1+my-package").publish(); | ||
cargo_test_support::registry::Package::new("semver", "0.1.1") | ||
.feature("std", &[]) | ||
.publish(); | ||
cargo_test_support::registry::Package::new("serde", "1.0.90") | ||
.feature("std", &[]) | ||
.publish(); | ||
|
||
let project = Project::from_template(curr_dir!().join("in")); | ||
let project_root = project.root(); | ||
let cwd = &project_root; | ||
|
||
snapbox::cmd::Command::cargo_ui() | ||
.arg("remove") | ||
.args(["docopt", "toml"]) | ||
.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); | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/testsuite/cargo_remove/optional_dep_feature_formatting/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,40 @@ | ||
[package] | ||
name = "cargo-remove-test-fixture" | ||
version = "0.1.0" | ||
|
||
[[bin]] | ||
name = "main" | ||
path = "src/main.rs" | ||
|
||
[build-dependencies] | ||
semver = "0.1.0" | ||
|
||
[dependencies] | ||
rustc-serialize = { version = "0.4", optional = true } | ||
semver = "0.1" | ||
clippy = { version = "0.4", optional = true } | ||
|
||
[dev-dependencies] | ||
regex = "0.1.1" | ||
serde = "1.0.90" | ||
|
||
[features] | ||
std = [ | ||
# Leading clippy | ||
"dep:clippy", # trailing clippy | ||
|
||
# Leading docopt | ||
# trailing docopt | ||
|
||
# Leading rustc-serialize | ||
"dep:rustc-serialize", # trailing rustc-serialize | ||
|
||
# Leading serde/std | ||
"serde/std", # trailing serde/std | ||
|
||
# Leading semver/std | ||
"semver/std", # trailing semver/std | ||
|
||
# Leading toml | ||
# trailing toml | ||
] |
2 changes: 2 additions & 0 deletions
2
tests/testsuite/cargo_remove/optional_dep_feature_formatting/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,2 @@ | ||
Removing docopt from dependencies | ||
Removing toml from dependencies |
Empty file.