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

test: additional tests for format_cargo_toml #3

Open
wants to merge 1 commit into
base: cargo_toml
Choose a base branch
from

Conversation

CBenoit
Copy link

@CBenoit CBenoit commented Oct 7, 2023

Here are additional test cases for the "format_cargo_toml" feature

@CBenoit CBenoit force-pushed the cargo-toml-format-more-tests branch from 7281b1a to 290329a Compare October 8, 2023 00:25
Comment on lines +38 to +39
miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
addr2line = { version = "0.21.0", optional = true, default-features = false }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be sorted alphabetically

Suggested change
miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
addr2line = { version = "0.21.0", optional = true, default-features = false }
addr2line = { version = "0.21.0", optional = true, default-features = false }
miniz_oxide = { version = "0.7.0", optional = true, default-features = false }

Comment on lines +56 to +70
[features]
backtrace = [
"gimli-symbolize",
"addr2line/rustc-dep-of-std",
"object/rustc-dep-of-std",
"miniz_oxide/rustc-dep-of-std"
]
gimli-symbolize = []
# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = ["core/panic_immediate_abort"]
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
std_detect_env_override = ["std_detect/std_detect_env_override"]
# Enable std_detect default features for stdarch/crates/std_detect:
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
std_detect_file_io = ["std_detect/std_detect_file_io"]
Copy link
Author

@CBenoit CBenoit Oct 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Controversial) result for this section is not very satisfying:

  1. newlines were useful to group related features together
  2. the comment about the "std_detect" group is now below some the "std_detect_*" features, though the expectation was for it to be above "std_detect_dlsym_getauxval"

I’m not sure we can do much for 2); after all the comment was indeed above "std_detect_file_io", but for 1), maybe separated "groups" should stay separated?

That is, maybe something like should be considered "properly formatted":

[features]
backtrace = [
    "gimli-symbolize",
    "addr2line/rustc-dep-of-std",
    "object/rustc-dep-of-std",
    "miniz_oxide/rustc-dep-of-std"
]
gimli-symbolize = []

# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = ["core/panic_immediate_abort"]

# Enable std_detect default features for stdarch/crates/std_detect:
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml

std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
std_detect_env_override = ["std_detect/std_detect_env_override"]
std_detect_file_io = ["std_detect/std_detect_file_io"]

Maybe this could be configured with a new key in the rustfmt.toml file.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result for this section is not very satisfying

Indeed, but I'm also unsure how to improve it. For 1) How can we define "grouping" when the items need to be sorted? For 2) I think it can be manually tweaked after the sorting 🤪.

Copy link
Author

@CBenoit CBenoit Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we define "grouping" when the items need to be sorted?

I would define it as "items separated by newlines":

# First group
backtrace = [
    "gimli-symbolize",
    "addr2line/rustc-dep-of-std",
    "object/rustc-dep-of-std",
    "miniz_oxide/rustc-dep-of-std"
]
gimli-symbolize = []

# Second group
panic_immediate_abort = ["core/panic_immediate_abort"]

# Third group
# "Comment-only" group with no key

# Fourth group
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
std_detect_env_override = ["std_detect/std_detect_env_override"]
std_detect_file_io = ["std_detect/std_detect_file_io"]

Keys within a group are sorted alphabetically.

There are several avenues:

  • Make it the default behavior
  • Make it configurable
  • Don’t support this

That being said, here is probably not the best place to discuss this. This should probably be tracked with a follow-up issue when your PR lands on nightly.

For 2) I think it can be manually tweaked after the sorting 🤪.

Absolutely 😆

@@ -32,3 +32,7 @@ ac = 1

[a.z]
az = 1

# Very long (from std’s Cargo.toml)
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx")))' .dependencies]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were probably aware of this, but there is an extra white space here:

Suggested change
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx")))' .dependencies]
[target.'cfg(any(all(target_family = "wasm", target_os = "unknown"), target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx")))'.dependencies]

Copy link
Owner

@xxchan xxchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Would you like to take a look at the little bugs found? If not, I will take a look later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The test case is not minimal. It might be better to comment what's the intention of the test (and/or minimize it?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, it’s more like an integration test looking like a Cargo.toml from an actual project and the name is not reflecting that.
I’ll minimize this into multiple tests.

Comment on lines +56 to +70
[features]
backtrace = [
"gimli-symbolize",
"addr2line/rustc-dep-of-std",
"object/rustc-dep-of-std",
"miniz_oxide/rustc-dep-of-std"
]
gimli-symbolize = []
# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = ["core/panic_immediate_abort"]
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
std_detect_env_override = ["std_detect/std_detect_env_override"]
# Enable std_detect default features for stdarch/crates/std_detect:
# https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml
std_detect_file_io = ["std_detect/std_detect_file_io"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result for this section is not very satisfying

Indeed, but I'm also unsure how to improve it. For 1) How can we define "grouping" when the items need to be sorted? For 2) I think it can be manually tweaked after the sorting 🤪.

@CBenoit
Copy link
Author

CBenoit commented Oct 10, 2023

Thanks! Would you like to take a look at the little bugs found? If not, I will take a look later.

I’m willing to look into this more in depth, but I suspect one of the bug, the extra white space, may be addressed by #2, and I would rather wait for this to be merged before I try to modify the implementation and end up fixing conflicts.

Also, if these are not blockers for rust-lang#5240, I would be more comfortable with tracking and addressing them separately (I’ll open issues for that). I feel it’s easier for the rustfmt team to review smaller chunks instead of making rust-lang#5240 even bigger that it is already.

What do you think?

@xxchan xxchan force-pushed the cargo_toml branch 2 times, most recently from fbe6916 to c9e5a94 Compare October 24, 2023 16:28
@xxchan
Copy link
Owner

xxchan commented Oct 24, 2023

#2 is merged.

I prefer fixing minor issues earlier if we find them. The changes should be minimal and won't bring in much new code.

@CBenoit
Copy link
Author

CBenoit commented Oct 24, 2023

#2 is merged.

I prefer fixing minor issues earlier if we find them. The changes should be minimal and won't bring in much new code.

Okay, I’ll check again now that #2 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants