Repository navigation
Conversation
|
Nice! I'll review this gradually over this week |
There was a problem hiding this comment.
A quick first look over the changes.
I was wondering: should we add any handling for any in-flight changes/open PRs that will be using the old format? Currently any old-style // rustfmt-* line will just be silently ignored (but hopefully at least result in a test failure) which I think could cause confusion
| let reader = BufReader::new(file); | ||
| let pattern = r"^\s*//\s*rustfmt-([^:]+):\s*(\S+)"; | ||
| // Matches `//@ rustfmt-{name}: {value}` | ||
| let pattern = r"^\s*//@\s+rustfmt-(?P<name>[A-Za-z_]+)\s?:\s*(?P<value>\S+)$"; |
There was a problem hiding this comment.
Is there anything us from being stricter here, there are currently no comments in files that need the extra optional spaces
| let pattern = r"^\s*//@\s+rustfmt-(?P<name>[A-Za-z_]+)\s?:\s*(?P<value>\S+)$"; | |
| let pattern = r"^//@\s+rustfmt-(?P<name>[A-Za-z_]+):\s*(?P<value>\S+)$"; |
verified via
# no comments use a space between line start and `//`
git grep --perl-regexp '^\s+//@\s+rustfmt-(?P<name>[A-Za-z_]+)\s?:\s*(?P<value>\S+)$' -- tests/
# ^ changed '*' to '+'
# similarly, no comment uses a space between 'rustfmt-<name>' and then ':'
git grep --perl-regexp '^\s*//@\s+rustfmt-(?P<name>[A-Za-z_]+)\s+:\s*(?P<value>\S+)$' -- tests/
# ^ changed '?' to '+'There was a problem hiding this comment.
We could probably remove the second \s?, but I see some value in allowing arbitrary whitespace before the directive. Maybe we want to set the test directive in a nested comment instead of at the top of the file.
There was a problem hiding this comment.
We could probably remove the second
\s?, but I see some value in allowing arbitrary whitespace before the directive. Maybe we want to set the test directive in a nested comment instead of at the top of the file.
My preference is to limit things to what we know/expect we will need, then change it in the future if needed. But I'm not opposed to leaving it as-is.
|
|
||
| config.override_value(key, val); | ||
|
|
||
| if !config.was_option_set(key) { |
There was a problem hiding this comment.
what motivated adding this check/how can we end up in this situation?
There was a problem hiding this comment.
Just an extra check to make sure that values are actually getting set as we'd expect. I don't see any harm in keeping this check, but let me know if you think otherwise.
Replace `// rustfmt-*` test config comments with `//@ rustfmt-*`.
…}: {value}`
Panics if a test directive is malformed.
test authors will now get feedback when test directive: 1. are malformed 2. use invalid config option names 3. use invalid config values 4. somehow don't set configs
Make using `// rustfmt-{name}: {value}` a hard error. Also informs users that
they should be using `//@ rustfmt-{name}: {value}` instead.
8417490 to
64dca2f
Compare
@matthewhughes934 Thank you for the suggestion. I added a new check that will lead to a hard error if you're using the old directive syntax. |
|
|
||
| for file in &files { | ||
| let mut config = read_config(file); | ||
| let mut config = read_config(file).expect("config is valid"); |
There was a problem hiding this comment.
I think this causes confusing error messages, e.g. using //@ rustfmt-foo: true, the error printed is:
config is valid: "tests/source/doc.rs set unrecognized config option \"foo\""
Reading that: is the error telling me the config is valid?. The docs recommend using should, and I think that would work:
| let mut config = read_config(file).expect("config is valid"); | |
| let mut config = read_config(file).expect("config should be valid"); |
There was a problem hiding this comment.
Thoughts on updating all the expect calls to say something like "invalid config" or "expected valid config"?
There was a problem hiding this comment.
Thoughts on updating all the expect calls to say something like "invalid config" or "expected valid config"?
👍 sounds good to me
There was a problem hiding this comment.
Had to change this test because it used //@
There was a problem hiding this comment.
Same as the source file. Had to change this test because it used //@
There was a problem hiding this comment.
Need to double check, but I changed this from just Bar -> struct Bar because I was seeing parse errors. I think my editor changed the line ending and that might have accidentally changed the test. Will double check this one. Same goes for the tests/source/preserves_carriage_return_for_windows.rs test and their target files.
Discussed in Zulip #t-rustfmt > Stricter test directives?.
I updated the entire test suite to use
//@ rustfmt-*directives when setting configuration values for tests. There's also some validation to make sure that the directives aren't malformed.