Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Integrate Test262 #654

Merged
merged 11 commits into from
Aug 7, 2017
Merged

Integrate Test262 #654

merged 11 commits into from
Aug 7, 2017

Conversation

jugglinmike
Copy link
Contributor

Introduce a GNU Make target for retrieving TC-39's Test262 suite and
validating parsing of the files it contains. Interpret each file as a
parser test in accordance with that project's INTERPRETING.md
document. Allow for the specification of allowed failures via a
"whitelist" file so that the test suite may help prevent regressions in
this project in situations where this project has known bugs. Initialize
the "whitelist" file with a listing of all tests that are currently
failing. Extend the continuous integration environment's configuration
to automatically run these tests.

Q A
Bug fix? no
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets gh-633
License MIT

Hey @hzoo!

Here's my first attempt at integrating Test262. There's a lot of new code here,
so I'm prepared to make a log of changes according to review feedback.

One thing I would prefer to do is split the run_test262_utils.js file into
multiple files, possibly within a dedicated directory. There's not much
precedent for that within the scripts directory, so I thought I'd hold off on
that until I heard back from you.

I'd also like to point out that the code within the scripts directory is not
currently being linted by the npm "lint" command. I manually satisfied the
linter anyway, with one exception: trailing commas. (I'm developing in Node.js
current LTS release where trailing commas are not supported.) Is there anything
you would like to change about this?

Introduce a GNU Make target for retrieving TC-39's Test262 suite and
validating parsing of the files it contains. Interpret each file as a
parser test in accordance with that project's `INTERPRETING.md`
document. Allow for the specification of allowed failures via a
"whitelist" file so that the test suite may help prevent regressions in
this project in situations where this project has known bugs. Initialize
the "whitelist" file with a listing of all tests that are currently
failing. Extend the continuous integration environment's configuration
to automatically run these tests.
@nicolo-ribaudo
Copy link
Member

Travis reported this error:

$ if [ "$JOB" = "test262-test" ]; then make test-test262; fi
node scripts/run_test262.js
{ Error: ENOENT: no such file or directory, stat '/home/travis/build/babel/babylon/build/test262/test'
    at Error (native)
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/home/travis/build/babel/babylon/build/test262/test' }

Is it intended?

})
.catch(function(err) {
console.error(err);
process.statusCode = 1;
Copy link
Member

Choose a reason for hiding this comment

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

This should be process.exitCode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. This is critical--thank you for spotting it.

@@ -0,0 +1,7972 @@
# This file lists tests that are known to produce incorrect results when parsed
# with Babyline:
Copy link
Member

Choose a reason for hiding this comment

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

nit: Babylon

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 30, 2017

I see there are a lot of failing tests which babylon actually supports via plugins, for example language/expressions/async-generator/args-trailing-comma-multiple.js.
I think there should be a way to specify which plugins enable for a given file/folder.
Maybe we should use the features flag?

@jugglinmike
Copy link
Contributor Author

I think there should be a way to specify which plugins enable for a given
file/folder. Maybe we should use the features flag?

I'd be open to try that, but at some point, I think we should consider
introducing a YAML parser. The ad-hoc regular expressions I've written seem
"close enough" for the current use case, but using RegExps to interpret dynamic
values like that is much more error prone. I've been trying to avoid adding any
dependencies for this patch, so I'm wondering how the project maintainers would
feel about a new "devDependency" on a YAML parser.

@jugglinmike
Copy link
Contributor Author

Alternatively, we could unconditionally enable all plugins for all tests. This is certainly less precision, but since Test262 generally doesn't include any "future hostile" tests, it may be an acceptable compromise.

@hzoo
Copy link
Member

hzoo commented Aug 1, 2017

We just did something like this for our printer tests (generator) babel/babel#6018 with explicit flags. We could do unconditional for all tests though for now, if someone runs the stage 0 preset, it would be the same thing and none of the plugins should be incompatible.

const sourceType = test.isModule ? "module" : "script";

try {
parse(test.content, { sourceType: sourceType });
Copy link
Member

@hzoo hzoo Aug 1, 2017

Choose a reason for hiding this comment

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

Just need to add the ones in https://github.com/babel/babylon#plugins (excluding flow/jsx/typescript/estree)

@hzoo
Copy link
Member

hzoo commented Aug 1, 2017

is there already a script/way to remove the whitelist tests automatically if things are fixed later?

const whitelistFile = path.join(__dirname, "test262_whitelist.txt");

Promise.all([utils.getTests(testDir), utils.getWhitelist(whitelistFile)])
.then(function([tests, whitelist]) {
Copy link
Member

Choose a reason for hiding this comment

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

This breaks in Node 4 (do we care?)

Copy link
Member

Choose a reason for hiding this comment

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

I think it's ok to only run on latest for these?

const badnews = [];
const badnewsDetails = [];

[
Copy link
Member

Choose a reason for hiding this comment

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

Lines starting with a [ are pretty scary, regardless of semicolons.

Maybe save this into a const, or make it the right side of a for of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For consistency, I'd prefer to keep a functional style. But I see your point. I've made this the right-hand side of a void expression--that will guard against ASI-related bugs, and it should also more clearly indicate to the reader that this literal value is not used beyond this statement.

badnews.push(desc);
badnewsDetails.push(desc + ":");
badnewsDetails.push(
...tests.map(function(test) {
Copy link
Member

Choose a reason for hiding this comment

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

This also breaks in Node 4 😄


function readDir(dirName) {
return new Promise(function(resolve, reject) {
fs.readdir(dirName, function(err, contents) {
Copy link
Member

Choose a reason for hiding this comment

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

Any objections to adding a devDependency on util.promisify?

It's available natively in Node >= 8, the package just shims it if it's missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't object, but I believe this question was @hzoo, so I'm going to hold off unless he agrees.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to run on anything other than latest node (8)? We can add it too if we really want to but I think it's fine to run one one version of node like we do for coverage and lint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me!

test.actualError = true;
}

test.result = test.expectedError ^ test.actualError ? "fail" : "pass";
Copy link
Member

Choose a reason for hiding this comment

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

Better to use !==.

return line.replace(/#.*$/, "").trim();
})
.filter(function(line) {
return line.length > 0;
Copy link
Member

Choose a reason for hiding this comment

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

.filter(Boolean) would work too but I guess this is clearer

@jugglinmike
Copy link
Contributor Author

is there already a script/way to remove the whitelist tests automatically if
things are fixed later?

There was not, but that's a good idea. Maintaining the white list in JSHint has
been a pain point for me. I've updated the patch to include a command-line
flag and dedicated Makefile target.

So I think that's everything--this should be ready for another round of review.

@jugglinmike
Copy link
Contributor Author

I've updated the job to run in the latest release of Node.js, and I've taken @Kovensky's advice regarding the "util.promisify" module. My thinking is that many contributors likely prefer to develop in the LTS release. Even though they may not all care to run this particular test suite, the module's dependency tree is light enough to be justify the convenience.

The babel-test job is failing. Is there something we should do about that in this patch?

@hzoo
Copy link
Member

hzoo commented Aug 6, 2017

There was not, but that's a good idea.

Like it would basically run the whitelist tests and if they pass correctly instead of erroring/not erroring it could tell you to remove them (or it is done automatically), similar to updating a snapshot/fixture

Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for this work! Will help us a lot for regressions in the future! And hopefully get us started on the path for test262 in the transforms as well actually; ideally we can further more make compat-table 2.0 with test262

@hzoo
Copy link
Member

hzoo commented Aug 6, 2017

oops I just merged babel/babel#6056, which means we need to update yarn at least?

either way unrelated to your pr

@jugglinmike
Copy link
Contributor Author

Whoops; before you updated the comment, I thought you were saying I should update the yarn lock file. I guess wasn't necessary, after all (I'm not familiar with that tool). Should I revert this latest commit?

@hzoo
Copy link
Member

hzoo commented Aug 6, 2017

I updated Babel to use a new feature in yarn; I think we have to add https://github.com/babel/babel/pull/6056/files#diff-354f30a63fb0907d4ad57269548329e3L15 since the yarn version it's using now is older. Not sure it's going to fix but it's an issue due to us targeting master. Either way it would of broke in someone else's PR

@hzoo
Copy link
Member

hzoo commented Aug 6, 2017

Yeah we don't need that commit, I can try this locally and push a change

Copy link
Member

@danez danez left a comment

Choose a reason for hiding this comment

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

Nice work. It's crazy how much tests are not working with babylon.

@danez
Copy link
Member

danez commented Aug 6, 2017

I just tested this also locally and it doesn't work and stops with EMFILE: too many open files. Seems reading all the tests async without limit is not a good idea, but works on travis for some reason.

@nicolo-ribaudo
Copy link
Member

We could use graceful-fs, which handles EMFILE errors automatically.

@hzoo
Copy link
Member

hzoo commented Aug 6, 2017

Yeah graceful-fs sounds good

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

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

Awesome @jugglinmike!

Note, I bumped our yarn version to support workspaces and switched to graceful-fs.

After this lands, we can drop the rest-parameter test262 test fixtures I added a while back

@hzoo
Copy link
Member

hzoo commented Aug 7, 2017

Thanks for starting this @jugglinmike!

@hzoo hzoo merged commit 0466504 into babel:master Aug 7, 2017

bootstrap-test262: clean
mkdir ./build
git clone https://github.com/tc39/test262.git ./build/test262
Copy link
Member

Choose a reason for hiding this comment

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

could we do a depth=x here as well?

@hzoo
Copy link
Member

hzoo commented Aug 7, 2017

screen shot 2017-08-06 at 9 25 41 pm

Copy link
Member

@chicoxyzzy chicoxyzzy left a comment

Choose a reason for hiding this comment

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

<3

@jugglinmike
Copy link
Contributor Author

It's been my pleasure :)

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

Successfully merging this pull request may close these issues.

7 participants