Skip to content

Commit

Permalink
fixup! Tests for the export script
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter committed Aug 11, 2017
1 parent 1b52ae1 commit c147c1d
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 8 deletions.
File renamed without changes.
22 changes: 22 additions & 0 deletions js/src/tests/test/expected/export/reftest-and-frontmatter-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.


/*---
esid: sec-let-and-const-declarations
features: []
negative:
phase: runtime
type: SyntaxError
description: |
Outside AsyncFunction, |await| is a perfectly cromulent LexicalDeclaration variable
name. Therefore ASI doesn't apply, and so the |0| where a |=| was expected is a
syntax error.
---*/

eval(`
function f() {
let
await 0;
}
`);
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@


/*---
negative:
phase: early
type: SyntaxError
author: Jeff Walden <jwalden+code@mit.edu>
features: []
description: |
Outside AsyncFunction, |await| is a perfectly cromulent LexicalDeclaration variable
name. Therefore ASI doesn't apply, and so the |0| where a |=| was expected is a
syntax error.
author: Jeff Walden <jwalden+code@mit.edu>
features: []
negative:
phase: early
type: SyntaxError
esid: sec-let-and-const-declarations
---*/

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions js/src/tests/test/fixtures/export/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// not an empty file
File renamed without changes.
19 changes: 19 additions & 0 deletions js/src/tests/test/fixtures/export/reftest-and-frontmatter-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// |reftest| error:SyntaxError

/*---
esid: sec-let-and-const-declarations
description: >
Outside AsyncFunction, |await| is a perfectly cromulent LexicalDeclaration
variable name. Therefore ASI doesn't apply, and so the |0| where a |=| was
expected is a syntax error.
negative:
phase: runtime
type: SyntaxError
---*/

eval(`
function f() {
let
await 0;
}
`);
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ description: >
Outside AsyncFunction, |await| is a perfectly cromulent LexicalDeclaration
variable name. Therefore ASI doesn't apply, and so the |0| where a |=| was
expected is a syntax error.
negative:
phase: early
type: SyntaxError
---*/

function f() {
Expand Down
1 change: 1 addition & 0 deletions js/src/tests/test/fixtures/export/shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// not an empty file
57 changes: 57 additions & 0 deletions js/src/tests/test/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# Adapted from https://github.com/tc39/test262/blob/master/tools/generation/test/run.py

import shutil, subprocess, sys, os, unittest

testDir = os.path.dirname(os.path.relpath(__file__))
OUT_DIR = os.path.join(testDir, 'out')
EXPECTED_DIR = os.path.join(testDir, 'expected')
ex = os.path.join(testDir, '..', 'test262-export.py')

class TestExport(unittest.TestCase):
maxDiff = None

def fixture(self, name):
relpath = os.path.relpath(os.path.join(testDir, 'fixtures', name))
sp = subprocess.Popen(
[ex, relpath, '--out', OUT_DIR],
stdout=subprocess.PIPE)
stdout, stderr = sp.communicate()
return dict(stdout=stdout, stderr=stderr, returncode=sp.returncode)

def getFiles(self, path):
names = []
for root, _, fileNames in os.walk(path):
for fileName in filter(lambda x: x[0] != '.', fileNames):
names.append(os.path.join(root, fileName))
names.sort()
return names

def compareTrees(self, targetName):
expectedPath = os.path.join(EXPECTED_DIR, targetName)
actualPath = OUT_DIR

expectedFiles = self.getFiles(expectedPath)
actualFiles = self.getFiles(actualPath)

self.assertListEqual(
map(lambda x: os.path.relpath(x, expectedPath), expectedFiles),
map(lambda x: os.path.relpath(x, actualPath), actualFiles))

for expectedFile, actualFile in zip(expectedFiles, actualFiles):
with open(expectedFile) as expectedHandle:
with open(actualFile) as actualHandle:
self.assertMultiLineEqual(
expectedHandle.read(),
actualHandle.read())

def tearDown(self):
shutil.rmtree(OUT_DIR, ignore_errors=True)

def test_export(self):
result = self.fixture('export')
self.assertEqual(result['returncode'], 0)
self.compareTrees('export')

if __name__ == '__main__':
unittest.main()
Empty file.
Empty file.

0 comments on commit c147c1d

Please sign in to comment.