From 4ea9b9c028a205222ac9bb3912f6ce6214ab3276 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 15 Oct 2014 14:28:51 +1100 Subject: [PATCH] better exec tests --- lib/6to5/transform.js | 30 +++++++++++-------- test/_helper.js | 6 ++++ .../generators/for-of/{actual.js => exec.js} | 0 test/fixtures/syntax/generators/options.json | 3 -- .../generators/simple/{actual.js => exec.js} | 0 .../deep-nested/{actual.js => exec.js} | 0 .../{actual.js => exec.js} | 0 .../for-initializers/{actual.js => exec.js} | 0 .../in-class/{actual.js => exec.js} | 0 .../in-closure/{actual.js => exec.js} | 0 .../in-for-break-inner/{actual.js => exec.js} | 0 .../in-for-break-named/{actual.js => exec.js} | 0 .../in-for-break/{actual.js => exec.js} | 0 .../{actual.js => exec.js} | 0 .../{actual.js => exec.js} | 0 .../in-for-continue/{actual.js => exec.js} | 0 .../let-scoping/in-for/{in-for.js => exec.js} | 0 .../in-properties/{actual.js => exec.js} | 0 .../initializer-for-1/{actual.js => exec.js} | 0 .../initializer-for-2/{actual.js => exec.js} | 0 .../initializer-for-3/{actual.js => exec.js} | 0 .../initializer-for-in/{actual.js => exec.js} | 0 .../nested-conflict/{actual.js => exec.js} | 0 .../nested-function-1/{actual.js => exec.js} | 0 .../nested-function-2/{actual.js => exec.js} | 0 .../nested-function-3/{actual.js => exec.js} | 0 .../let-scoping/nested/{actual.js => exec.js} | 0 .../{actual.js => exec.js} | 0 .../no-initializer/{actual.js => exec.js} | 0 test/fixtures/syntax/let-scoping/options.json | 3 -- .../regress-1381/{actual.js => exec.js} | 0 .../with-for-in/{actual.js => exec.js} | 0 .../with-for/{actual.js => exec.js} | 0 .../with-switch/{actual.js => exec.js} | 0 34 files changed, 23 insertions(+), 19 deletions(-) rename test/fixtures/syntax/generators/for-of/{actual.js => exec.js} (100%) delete mode 100644 test/fixtures/syntax/generators/options.json rename test/fixtures/syntax/generators/simple/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/deep-nested/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/for-in-initializers/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/for-initializers/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-class/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-closure/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for-break-inner/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for-break-named/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for-break/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for-continue-inner/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for-continue-named/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for-continue/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-for/{in-for.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/in-properties/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/initializer-for-1/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/initializer-for-2/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/initializer-for-3/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/initializer-for-in/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/nested-conflict/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/nested-function-1/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/nested-function-2/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/nested-function-3/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/nested/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/no-initializer-global/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/no-initializer/{actual.js => exec.js} (100%) delete mode 100644 test/fixtures/syntax/let-scoping/options.json rename test/fixtures/syntax/let-scoping/regress-1381/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/with-for-in/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/with-for/{actual.js => exec.js} (100%) rename test/fixtures/syntax/let-scoping/with-switch/{actual.js => exec.js} (100%) diff --git a/lib/6to5/transform.js b/lib/6to5/transform.js index 4106dc6dcd..ec492bbb77 100644 --- a/lib/6to5/transform.js +++ b/lib/6to5/transform.js @@ -19,25 +19,29 @@ transform.test = function (task, assert) { var actual = task.actual; var expect = task.expect; var opts = task.options; - var exec = opts.exec; + var exec = task.exec; - opts.filename = actual.filename; + var getOpts = function (filename) { + return _.merge({ filename: filename }, opts); + }; - var actualCode = actual.code.trim(); + var execCode = exec.code.trim(); + var result; - var actualResult = transform(actualCode, opts); - var actualAst = actualResult.ast; - actualCode = recast.prettyPrint(actualAst).code; + if (execCode) { + result = transform(execCode, getOpts(exec.filename)); + execCode = result.code; - if (exec) { require("./polyfill"); - var fn = new Function("assert", actualCode); + var fn = new Function("assert", execCode); fn(assert); - } + } else { + var actualCode = actual.code.trim(); + var expectCode = expect.code.trim(); - var expectCode = expect.code.trim(); + result = transform(actualCode, getOpts(actual.filename)); + actualCode = recast.prettyPrint(result.ast).code; - if (!exec || (exec && expectCode)) { var expectAst = util.parse(expect, expectCode); var expectResult = recast.prettyPrint(expectAst); expectCode = expectResult.code; @@ -46,11 +50,11 @@ transform.test = function (task, assert) { } if (task.sourceMap) { - assert.deepEqual(task.sourceMap, actualResult.map); + assert.deepEqual(task.sourceMap, result.map); } if (task.sourceMappings) { - var consumer = new sourceMap.SourceMapConsumer(actualResult.map); + var consumer = new sourceMap.SourceMapConsumer(result.map); _.each(task.sourceMappings, function (mapping, i) { var pos = consumer.originalPositionFor(mapping.generated); diff --git a/test/_helper.js b/test/_helper.js index ee409100f8..1ea1a9a79d 100644 --- a/test/_helper.js +++ b/test/_helper.js @@ -65,9 +65,11 @@ exports.getTests = function () { var actualLocAlias = suiteName + "/" + taskName + "/actual.js"; var expectLocAlias = suiteName + "/" + taskName + "/expected.js"; + var execLocAlias = suiteName + "/" + taskName + "/exec.js"; var actualLoc = taskDir + "/actual.js"; var expectLoc = taskDir + "/expected.js"; + var execLoc = taskDir + "/exec.js"; var taskOpts = _.merge({ filename: actualLocAlias, @@ -80,6 +82,10 @@ exports.getTests = function () { var test = { title: humanise(taskName), options: taskOpts, + exec: { + code: readFile(execLoc), + filename: execLocAlias, + }, actual: { code: readFile(actualLoc), filename: actualLocAlias, diff --git a/test/fixtures/syntax/generators/for-of/actual.js b/test/fixtures/syntax/generators/for-of/exec.js similarity index 100% rename from test/fixtures/syntax/generators/for-of/actual.js rename to test/fixtures/syntax/generators/for-of/exec.js diff --git a/test/fixtures/syntax/generators/options.json b/test/fixtures/syntax/generators/options.json deleted file mode 100644 index 37997efa87..0000000000 --- a/test/fixtures/syntax/generators/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "exec": true -} diff --git a/test/fixtures/syntax/generators/simple/actual.js b/test/fixtures/syntax/generators/simple/exec.js similarity index 100% rename from test/fixtures/syntax/generators/simple/actual.js rename to test/fixtures/syntax/generators/simple/exec.js diff --git a/test/fixtures/syntax/let-scoping/deep-nested/actual.js b/test/fixtures/syntax/let-scoping/deep-nested/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/deep-nested/actual.js rename to test/fixtures/syntax/let-scoping/deep-nested/exec.js diff --git a/test/fixtures/syntax/let-scoping/for-in-initializers/actual.js b/test/fixtures/syntax/let-scoping/for-in-initializers/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/for-in-initializers/actual.js rename to test/fixtures/syntax/let-scoping/for-in-initializers/exec.js diff --git a/test/fixtures/syntax/let-scoping/for-initializers/actual.js b/test/fixtures/syntax/let-scoping/for-initializers/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/for-initializers/actual.js rename to test/fixtures/syntax/let-scoping/for-initializers/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-class/actual.js b/test/fixtures/syntax/let-scoping/in-class/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-class/actual.js rename to test/fixtures/syntax/let-scoping/in-class/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-closure/actual.js b/test/fixtures/syntax/let-scoping/in-closure/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-closure/actual.js rename to test/fixtures/syntax/let-scoping/in-closure/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for-break-inner/actual.js b/test/fixtures/syntax/let-scoping/in-for-break-inner/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for-break-inner/actual.js rename to test/fixtures/syntax/let-scoping/in-for-break-inner/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for-break-named/actual.js b/test/fixtures/syntax/let-scoping/in-for-break-named/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for-break-named/actual.js rename to test/fixtures/syntax/let-scoping/in-for-break-named/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for-break/actual.js b/test/fixtures/syntax/let-scoping/in-for-break/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for-break/actual.js rename to test/fixtures/syntax/let-scoping/in-for-break/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for-continue-inner/actual.js b/test/fixtures/syntax/let-scoping/in-for-continue-inner/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for-continue-inner/actual.js rename to test/fixtures/syntax/let-scoping/in-for-continue-inner/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for-continue-named/actual.js b/test/fixtures/syntax/let-scoping/in-for-continue-named/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for-continue-named/actual.js rename to test/fixtures/syntax/let-scoping/in-for-continue-named/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for-continue/actual.js b/test/fixtures/syntax/let-scoping/in-for-continue/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for-continue/actual.js rename to test/fixtures/syntax/let-scoping/in-for-continue/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-for/in-for.js b/test/fixtures/syntax/let-scoping/in-for/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-for/in-for.js rename to test/fixtures/syntax/let-scoping/in-for/exec.js diff --git a/test/fixtures/syntax/let-scoping/in-properties/actual.js b/test/fixtures/syntax/let-scoping/in-properties/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/in-properties/actual.js rename to test/fixtures/syntax/let-scoping/in-properties/exec.js diff --git a/test/fixtures/syntax/let-scoping/initializer-for-1/actual.js b/test/fixtures/syntax/let-scoping/initializer-for-1/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/initializer-for-1/actual.js rename to test/fixtures/syntax/let-scoping/initializer-for-1/exec.js diff --git a/test/fixtures/syntax/let-scoping/initializer-for-2/actual.js b/test/fixtures/syntax/let-scoping/initializer-for-2/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/initializer-for-2/actual.js rename to test/fixtures/syntax/let-scoping/initializer-for-2/exec.js diff --git a/test/fixtures/syntax/let-scoping/initializer-for-3/actual.js b/test/fixtures/syntax/let-scoping/initializer-for-3/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/initializer-for-3/actual.js rename to test/fixtures/syntax/let-scoping/initializer-for-3/exec.js diff --git a/test/fixtures/syntax/let-scoping/initializer-for-in/actual.js b/test/fixtures/syntax/let-scoping/initializer-for-in/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/initializer-for-in/actual.js rename to test/fixtures/syntax/let-scoping/initializer-for-in/exec.js diff --git a/test/fixtures/syntax/let-scoping/nested-conflict/actual.js b/test/fixtures/syntax/let-scoping/nested-conflict/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/nested-conflict/actual.js rename to test/fixtures/syntax/let-scoping/nested-conflict/exec.js diff --git a/test/fixtures/syntax/let-scoping/nested-function-1/actual.js b/test/fixtures/syntax/let-scoping/nested-function-1/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/nested-function-1/actual.js rename to test/fixtures/syntax/let-scoping/nested-function-1/exec.js diff --git a/test/fixtures/syntax/let-scoping/nested-function-2/actual.js b/test/fixtures/syntax/let-scoping/nested-function-2/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/nested-function-2/actual.js rename to test/fixtures/syntax/let-scoping/nested-function-2/exec.js diff --git a/test/fixtures/syntax/let-scoping/nested-function-3/actual.js b/test/fixtures/syntax/let-scoping/nested-function-3/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/nested-function-3/actual.js rename to test/fixtures/syntax/let-scoping/nested-function-3/exec.js diff --git a/test/fixtures/syntax/let-scoping/nested/actual.js b/test/fixtures/syntax/let-scoping/nested/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/nested/actual.js rename to test/fixtures/syntax/let-scoping/nested/exec.js diff --git a/test/fixtures/syntax/let-scoping/no-initializer-global/actual.js b/test/fixtures/syntax/let-scoping/no-initializer-global/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/no-initializer-global/actual.js rename to test/fixtures/syntax/let-scoping/no-initializer-global/exec.js diff --git a/test/fixtures/syntax/let-scoping/no-initializer/actual.js b/test/fixtures/syntax/let-scoping/no-initializer/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/no-initializer/actual.js rename to test/fixtures/syntax/let-scoping/no-initializer/exec.js diff --git a/test/fixtures/syntax/let-scoping/options.json b/test/fixtures/syntax/let-scoping/options.json deleted file mode 100644 index 37997efa87..0000000000 --- a/test/fixtures/syntax/let-scoping/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "exec": true -} diff --git a/test/fixtures/syntax/let-scoping/regress-1381/actual.js b/test/fixtures/syntax/let-scoping/regress-1381/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/regress-1381/actual.js rename to test/fixtures/syntax/let-scoping/regress-1381/exec.js diff --git a/test/fixtures/syntax/let-scoping/with-for-in/actual.js b/test/fixtures/syntax/let-scoping/with-for-in/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/with-for-in/actual.js rename to test/fixtures/syntax/let-scoping/with-for-in/exec.js diff --git a/test/fixtures/syntax/let-scoping/with-for/actual.js b/test/fixtures/syntax/let-scoping/with-for/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/with-for/actual.js rename to test/fixtures/syntax/let-scoping/with-for/exec.js diff --git a/test/fixtures/syntax/let-scoping/with-switch/actual.js b/test/fixtures/syntax/let-scoping/with-switch/exec.js similarity index 100% rename from test/fixtures/syntax/let-scoping/with-switch/actual.js rename to test/fixtures/syntax/let-scoping/with-switch/exec.js