-
Notifications
You must be signed in to change notification settings - Fork 479
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
Add tests for Hashbang comments #1983
Conversation
@@ -0,0 +1,10 @@ | |||
/*--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I didn't have to say that, but we need to have the 2 lines of copyright on each test file.
I'm sorry this is a thing we'd need to get fixed in a meeting. Thanks for understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate this requirement, btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it fine to have them below the #!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure! I only need to "fix" the linter
assert.throws(SyntaxError, () => ctor('#!\n_','')); | ||
assert.throws(SyntaxError, () => ctor('#!\n_')); | ||
assert.throws(SyntaxError, () => new ctor('#!\n_','')); | ||
assert.throws(SyntaxError, () => new ctor('#!\n_')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.throws(SyntaxError, () => ctor('#!\n_',''), `${ctor.name} #1`);
assert.throws(SyntaxError, () => ctor('#!\n_'), `${ctor.name} #2`);
assert.throws(SyntaxError, () => new ctor('#!\n_',''), `${ctor.name} #3`);
assert.throws(SyntaxError, () => new ctor('#!\n_'), `${ctor.name} #4`);
WDYT? this helps mapping the assertions to whoever is consuming this test file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also add assertions for hashbangs placed at the first part of a function block?
function fn() {#!
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems fine
#! SingleLineCommentChars[opt] | ||
---*/ | ||
|
||
eval('#!\n'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert this completes to undefined?
Extra: maybe add another test file to evaluate custom completions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you define "custom completions"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.sameValue(eval('#!\n1`'), 1)
assert.sameValue(eval('#!2`'), undefined)
custom is a bad word, but any completion value that doesn't come from the hashbang comment
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, this test is so fun!
please add the flags: [raw]
so test runners won't add harness files
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [module] | ||
---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add the flags: [raw]
so test runners won't prepend the harness files
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [module] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
@@ -0,0 +1,10 @@ | |||
#! these characters should be treated as a comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely need to change the linter to not fail for this. I believe it will say you're missing the copyright lines here...
negative: | ||
phase: parse | ||
type: SyntaxError | ||
---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same case of raw mode, please add this to the other files accordingly.
@@ -0,0 +1,10 @@ | |||
#! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add other test files verifying these characters can't be escaped? one for #
and another for !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s try multiple types of escapes: https://github.com/v8/v8/blob/effb7ad728cf13da143fae41b03b0525f4ff65d5/test/cctest/test-parsing.cc#L11446-L11455
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! I'll work on some follow ups for this PR and this is a good material
#! SingleLineCommentChars[opt] | ||
---*/ | ||
|
||
assert.sameValue(eval('#!\n'), undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add here assertions to assert they are only available at the beginning?
assert.throws(SyntaxError, () => eval(' #!\n'), 'whitespace');
assert.throws(SyntaxError, () => eval('\n#!\n'), 'new line');
I'll work on the linter this week to not fail tests like this as we need the hashbang spec to be fully observed, The PR is already good to land as it is otherwise. |
test/language/comments/hashbang-encoded-bang.js
test/language/comments/hashbang-function-body.js
|
@bmeck besides @anba feedback, would you mind adding two things?
examples to the exceptions list:
WDYT having these files in a separate folder? both This way we can have a nice report of coverage only for hashbang through the folders organization and this should also allow some test runners to observe the full folder while the feature is still not yet implemented. |
I'm happy to work on the necessary changes here, the only info I would need is the appropriate name to use in the copyright header. |
info: | | ||
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add feature
front matter to each test?
features: [hashbang]
presumably
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and update features.txt
accordingly)
@@ -0,0 +1,10 @@ | |||
#\u0021 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is also incompatible with https://github.com/tc39/test262/blob/master/tools/packaging/parseTestRecord.py (which we use in v8) --- we might definitely need to adjust add a fallback case to get YAML from the tail of the file to handle thisyamlPattern
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should not be interpretted and should not generate DirectivePrologues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hashbang comments should not be interpretted and should not generate DirectivePrologues. | |
Hashbang comments should not be interpreted and should not generate DirectivePrologues. |
/*--- | ||
esid: pending | ||
description: > | ||
Hashbang comments should not be allowed to have encoded characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the description, shouldn't this be a negative test expecting a SyntaxError?
Support for this in test262-parser: smikes/test262-parser#14. |
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a negative test.
HashbangComment:: | ||
#! SingleLineCommentChars[opt] | ||
flags: [raw] | ||
---*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a negative test.
Implements https://tc39.github.io/proposal-hashbang/, which simply ignores the first line of a source file if it begins with '#!' (U+0023 U+0021). The test cases are influenced by tc39/test262#1983, which have not been pulled into test262 local-tests due to issues with parseTestRecord. BUG=v8:8523 R=gsathya@chromium.org, adamk@chromium.org, littledan@chromium.org Change-Id: I4ae40222298de768a170c7a1d45fec118ed5713c Reviewed-on: https://chromium-review.googlesource.com/c/1409527 Commit-Queue: Caitlin Potter <caitp@igalia.com> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Reviewed-by: Daniel Ehrenberg <littledan@chromium.org> Cr-Commit-Position: refs/heads/master@{#58838}
This adds tests around https://github.com/tc39/proposal-hashbang which is at Stage 3 but has not been merged nor has an esid. I tried to figure out if templates could work, but I was unsure about how whitespace worked with them so I left them as standalone files.