From 516298fa5f193cc779c5325330f016658eb119d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Sun, 12 Apr 2015 14:51:26 +0100 Subject: [PATCH 1/2] adding the expect_exact clause, which instead of parsing code will just read a string for expects, making it suitable for testing OutputStream --- test/run-tests.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/run-tests.js b/test/run-tests.js index 94bf6ad9..c02761a5 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -84,7 +84,12 @@ function run_compress_tests() { warnings: false }); var cmp = new U.Compressor(options, true); - var expect = make_code(as_toplevel(test.expect), false); + var expect + if (test.expect) { + expect = make_code(as_toplevel(test.expect), false); + } else { + expect = test.expect_exact; + } var input = as_toplevel(test.input); var input_code = make_code(test.input); var output = input.transform(cmp); @@ -150,7 +155,7 @@ function parse_test(file) { } if (node instanceof U.AST_LabeledStatement) { assert.ok( - node.label.name == "input" || node.label.name == "expect", + node.label.name == "input" || node.label.name == "expect" || node.label.name == "expect_exact", tmpl("Unsupported label {name} [{line},{col}]", { name: node.label.name, line: node.label.start.line, @@ -162,7 +167,11 @@ function parse_test(file) { if (stat.body.length == 1) stat = stat.body[0]; else if (stat.body.length == 0) stat = new U.AST_EmptyStatement(); } - test[node.label.name] = stat; + if (node.label.name === "expect_exact") { + test[node.label.name] = stat.body.start.value + } else { + test[node.label.name] = stat; + } return true; } }); From 9f0b66ed201826026cdec59f9bcfb87e4b440bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Mon, 13 Apr 2015 19:05:35 +0100 Subject: [PATCH 2/2] Document how expect_exact works through an error message --- test/run-tests.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/run-tests.js b/test/run-tests.js index c02761a5..e2935c81 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -168,6 +168,10 @@ function parse_test(file) { else if (stat.body.length == 0) stat = new U.AST_EmptyStatement(); } if (node.label.name === "expect_exact") { + if (!(stat.TYPE === "SimpleStatement" && stat.body.TYPE === "String")) { + throw new Error("The value of the expect_exact clause should be a string! " + + "Like this: `expect_exact: \"some.exact.javascript;\"`"); + } test[node.label.name] = stat.body.start.value } else { test[node.label.name] = stat;