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

Add tests for Hashbang comments #1983

Closed
wants to merge 3 commits into from

Conversation

@bmeck
Copy link
Member

commented Dec 3, 2018

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.

@@ -0,0 +1,10 @@
/*---

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

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.

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

I hate this requirement, btw.

This comment has been minimized.

Copy link
@bmeck

bmeck Dec 3, 2018

Author Member

is it fine to have them below the #!?

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

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_'));

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member
  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

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

can we also add assertions for hashbangs placed at the first part of a function block?

function fn() {#!
}

This comment has been minimized.

Copy link
@bmeck

bmeck Dec 3, 2018

Author Member

seems fine

#! SingleLineCommentChars[opt]
---*/

eval('#!\n');

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

assert this completes to undefined?

Extra: maybe add another test file to evaluate custom completions?

This comment has been minimized.

Copy link
@bmeck

bmeck Dec 3, 2018

Author Member

can you define "custom completions"?

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member
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
---*/

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

lol, this test is so fun!

please add the flags: [raw] so test runners won't add harness files

HashbangComment::
#! SingleLineCommentChars[opt]
flags: [module]
---*/

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

please add the flags: [raw] so test runners won't prepend the harness files

info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [module]

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

remove?

@@ -0,0 +1,10 @@
#! these characters should be treated as a comment

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

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
---*/

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

same case of raw mode, please add this to the other files accordingly.

@@ -0,0 +1,10 @@
#!

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

add other test files verifying these characters can't be escaped? one for # and another for !

This comment has been minimized.

This comment has been minimized.

Copy link
@leobalter

leobalter Jan 28, 2019

Member

cool! I'll work on some follow ups for this PR and this is a good material

@bmeck bmeck force-pushed the bmeck:hashbang branch from ae639b4 to 1f84c8f Dec 3, 2018

#! SingleLineCommentChars[opt]
---*/

assert.sameValue(eval('#!\n'), undefined);

This comment has been minimized.

Copy link
@leobalter

leobalter Dec 3, 2018

Member

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');
@leobalter

This comment has been minimized.

Copy link
Member

commented Dec 10, 2018

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.

@leobalter leobalter self-assigned this Dec 15, 2018

@anba

This comment has been minimized.

Copy link
Contributor

commented Dec 18, 2018

test/language/comments/hashbang-encoded-bang.js
test/language/comments/hashbang-encoded-hash.js
test/language/comments/hashbang-encoded-hashbang.js

  • Missing negative marker in yaml descriptor.

test/language/comments/hashbang-function-body.js

  • Missing var (or let or const) before ctor making this test throw a ReferenceError in strict mode.
@leobalter

This comment has been minimized.

Copy link
Member

commented Dec 18, 2018

@bmeck besides @anba feedback, would you mind adding two things?

  • the 2 copyright lines right before every file's /*--- (the frontmatter starter)?
  • In every file that has anything before the copyright lines, please add their names to the lint.exceptions (if you don't rebase your branch: lint.whitelist)?

examples to the exceptions list:

test/language/comments/hashbang-encoded-bang.js LICENSE
test/language/comments/hashbang-encoded-hash.js LICENSE
test/language/comments/hashbang-not-empty.js LICENSE
...

WDYT having these files in a separate folder? both test/language/hashbang/ or test/language/comments/hashbang/ works for me. I slightly prefer the first option, thou.

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.

@leobalter

This comment has been minimized.

Copy link
Member

commented Dec 18, 2018

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]

This comment has been minimized.

Copy link
@caitp

caitp Jan 10, 2019

Contributor

Could you please add feature front matter to each test?

features: [hashbang]

presumably

This comment has been minimized.

Copy link
@mathiasbynens

mathiasbynens Jan 28, 2019

Member

(and update features.txt accordingly)

@@ -0,0 +1,10 @@
#\u0021

This comment has been minimized.

Copy link
@caitp

caitp Jan 10, 2019

Contributor

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 yamlPattern add a fallback case to get YAML from the tail of the file to handle this

/*---
esid: pending
description: >
Hashbang comments should not be interpretted and should not generate DirectivePrologues.

This comment has been minimized.

Copy link
@jswalden

jswalden Jan 11, 2019

Contributor
Suggested change
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

This comment has been minimized.

Copy link
@caitp

caitp Jan 14, 2019

Contributor

Given the description, shouldn't this be a negative test expecting a SyntaxError?

@adrianheine

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2019

Support for this in test262-parser: smikes/test262-parser#14.

HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
---*/

This comment has been minimized.

Copy link
@adrianheine

adrianheine Jan 27, 2019

Contributor

Should be a negative test.

HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw]
---*/

This comment has been minimized.

Copy link
@adrianheine

adrianheine Jan 27, 2019

Contributor

Should be a negative test.

brn pushed a commit to brn/v8 that referenced this pull request Jan 30, 2019

[esnext] add support for hashbang syntax
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}
@leobalter leobalter referenced this pull request Feb 5, 2019

@leobalter leobalter closed this Feb 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.