-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 coverage for double trailing commas is poor #46238
Comments
Agh, I should've waited a bit longer before posting. My check did not take comments into account, so this may be a false alarm. I am hacking together a slightly more accurate test and will reopen if that test fails... |
test
that includes double trailing commas
After more accurate testing, this still appears to be a problem. #!/usr/bin/env python3
import re
# strip comments naively, under the assumption that tests which
# try to trip up comment parsers probably do not also test
# something such as double commas
BLOCK_COMMENT = re.compile('/\*(\*[^/]|[^*])*\*/', re.MULTILINE)
LINE_COMMENT = re.compile('//.*')
# Note: applied to a file's entire contents as a single string (with embedded newlines)
strip_comments = lambda s: BLOCK_COMMENT.sub('', LINE_COMMENT.sub('', s))
contents = [open(x.strip()).read() for x in open('files')]
contents = [strip_comments(s) for s in contents]
print("Test counts for trailing commas")
for end in ['\\]', '\\)', '\\}', '>']:
r = re.compile(f',\\s*{end}', re.MULTILINE)
print(f' ,{end[-1:]}:', len([x for x in map(r.findall, contents) if x]))
print("Test counts for double trailing commas")
for end in ['\\]', '\\)', '\\}', '>']:
r = re.compile(f',\\s*,\\s*{end}', re.MULTILINE)
print(f',,{end[-1:]}:', len([x for x in map(r.findall, contents) if x]))
|
IMO the theory applied to |
I think libcore and libstd are well in a position that they can at least afford to do it right, regardless of the ergonomics. The only disadvantage I can see is that it may make documentation look unruly for more complex macros; however, none of the macros currently existing in Put another way, I guess my feeling is that this should be applied to |
The most complex is probably |
One other thought: the possibility of a future (looking forward to that RFC, by the way 😉 ) |
triage: @ExpHP how do you feel about this coverage today? |
The coverage is still extremely poor. Checking today, tests currently exist for double trailing commas in only two places in the grammar:
There's still a plethora of places in the grammar where accidental One strategy may be to locate those test files which test interior And of course, it still is the case that each individual |
… r=joshtriplett Add test of matches macro for trailing commas Almost all macros are tested for trailing commas. The macro matches! was however not tested. This PR adds that test case. Related to rust-lang#46238
… r=joshtriplett Add test of matches macro for trailing commas Almost all macros are tested for trailing commas. The macro matches! was however not tested. This PR adds that test case. Related to rust-lang#46238
Theory
Every place in the grammar which supports trailing commas should be tested that it fails for double commas, lest Rust be locked into supporting it forever. A particularly notable case of this is for
macro_rules!
macros, many of which must manually implement their own trailing comma support (leading to more chances for mistakes).Reality
The text was updated successfully, but these errors were encountered: