I agree that no matter what, a lot of these functions are better broken
out into a utility library, but if the goal is to be able to use those
functions to share code with an output-checking script, see the next
section.
----
I don't know why I didn't notice it before, but you can actually easily
add
output checking to the current structure:
#--cut--
git checkout 4508897258b4781e # recent HEAD for branch master
git checkout -b issue6772044-test-output
cat > test-output.diff <<"END"
diff --git a/test/feature/out.js b/test/feature/out.js
new file mode 100644
index 0000000..aad1052
--- /dev/null
+++ b/test/feature/out.js
@@ -0,0 +1,7 @@
+// Test output.
+/*
+--cut--
+var a;
+--cut--
+*/
+var a;
diff --git a/test/testfeatures.js b/test/testfeatures.js
index 7a0a31a..87bf786 100644
--- a/test/testfeatures.js
+++ b/test/testfeatures.js
@@ -120,6 +120,7 @@ function testScript(filePath) {
var skip = false;
var shouldCompile = true;
var expectedErrors = [];
+ var testOutput = false;
forEachPrologLine(source, function(line) {
var m;
if (line.indexOf('// Only in browser.') === 0) {
@@ -132,6 +133,8 @@ function testScript(filePath) {
traceur.options.fromString(m[1]);
} else if ((m = /\/\/ Error:\s*(.+)/.exec(line))) {
expectedErrors.push(m[1]);
+ } else if (line.indexOf('// Test output.') === 0) {
+ testOutput = true;
}
});
@@ -175,6 +178,24 @@ function testScript(filePath) {
return false;
}
+ if (testOutput) {
+ var f = function(k, v) {
+ return k === 'location' ? undefined : v;
+ }
+ var SourceFile = traceur.syntax.SourceFile;
+ var compileFile = traceur.codegeneration.Compiler.compileFile;
+
+ var s1 = new SourceFile(filePath, source.split('--cut--')[1]);
+ var t1 = compileFile(reporter, s1, filePath);
+ var o1 = JSON.stringify(t1, f, 2);
+ var o2 = JSON.stringify(tree, f, 2);
+ if (o1 === o2)
+ return true;
+
+ failScript(filePath, 'Output mismatch.');
+ return false;
+ }
+
var TreeWriter = traceur.outputgeneration.TreeWriter;
var javascript = TreeWriter.write(tree, false);
END
git apply test-output.diff
node test/testfeatures.js
#--cut--
https://codereview.appspot.com/6772044/