String cutoff error, prevents passing test
I apologize if this a quite obvious mistake on my part, but I have been staring at this for an hour. I don't know how this could possibly be a bug on your end, but it's worth a try.
The following test does not pass:
exports.testWhile = function(test){
test.expect(1);
var input = parseSingleStat("while(foo() < 1){bar();}");
var output = parse("var __t0 = foo(); while(__t0 < 1){bar(); var __t0 = foo(); }");
test.equal(deparse(output), deparse(tacifyFunctions.tacifyWhile(input)));
test.done();
}
The following test passes:
exports.testWhile = function(test){
test.expect(1);
var input = parseSingleStat("while(foo() < 1){bar();}");
var output = parse("var __t0 = foo(); while(__t0 < 1){bar(); var __t0 = foo(); }");
var e = deparse(output);
var o = deparse(tacifyFunctions.tacifyWhile(input));
test.equal(e, o);
test.done();
}
deparse returns a string. In the former case deparse(tacifyFunctions.tacifyWhile(input)) is returning a string
Here is output from the test
tests ✔ testNested ✖ testWhile
AssertionError: 'var __t0 = foo();\n\nwhile (__t0 < 1) {\n bar();\n var __t0 = foo();\n}' == 'while (__t0 < 1) {\n bar();\n var __t0 = foo();\n}'
at Object.assertWrapper as equal
at Object.exports.testWhile (/home/satshabad/CS/CS585/jaspect/tests/tests.js:53:8)
at Object.wrapTest (/usr/lib/node_modules/nodeunit/lib/core.js:235:16)
at wrapTest (/usr/lib/node_modules/nodeunit/lib/core.js:235:16)
at Object.exports.runTest (/usr/lib/node_modules/nodeunit/lib/core.js:69:9)
at exports.runSuite (/usr/lib/node_modules/nodeunit/lib/core.js:117:25)
at _concat (/usr/lib/node_modules/nodeunit/deps/async.js:508:13)
at async.forEachSeries.iterate (/usr/lib/node_modules/nodeunit/deps/async.js:118:13)
at async.forEachSeries.iterate (/usr/lib/node_modules/nodeunit/deps/async.js:129:25)
at _concat (/usr/lib/node_modules/nodeunit/deps/async.js:510:17)
FAILURES: 1/5 assertions failed (38ms)
I would appreciate any insight.
What happens when you comment out one of the tests? For example, if you comment out testNested, and run testWhile, does it suddenly start passing? My guess is you've got some global variables that are either being manipulated by foo(), or bar(), or parse(), or deparse(), or tacifyFunctions.tacifyWhile(), or parseSingleStat()
Just tried that out. No difference. foo() and bar() are just words in those strings. I was thinking it was a hoisting bug as well, but I can't see it. parse(), deparse() tacifyFunctions.tacifyWhile(), and parseSingleStat() are all pure functions. Well except that tacifyWhile(node) modifies node and returns it. Any other ideas?
first thing I'd try is modifying the deparse function to print out what it's return value is, and see what the 4 values are that get spit out for both cases.
well in the test call the two values are
expected = 'var __t0 = foo();\n\nwhile (__t0 < 1) {\n bar();\n var __t0 = foo();\n}'
and
ouput of deparse(tatifyWhile()) ='while (__t0 < 1) {\n bar();\n var __t0 = foo();\n}'
but this is only way I can reproduce that. Otherwise both are 'var __t0 = foo();\n\nwhile (__t0 < 1) {\n bar();\n var __t0 = foo();\n}'
The double line break is somehow the delimiter...
Can you paste the implementation of those functions somewhere so I can take a look at what it's doing? A bit off-topic, but why is this snippet parsing javascript code as a string?
I am writing some code to turn every statement in a JS file into three address code (TAC) form as part of a larger project creating an aspect oriented programming library for javascript. I have started by TACifying separate kinds of statements. I encounter this bug while writing the while statement tacifyer.
Here's tacifyWhile: https://github.com/Satshabad/jaspect/blob/master/tacify.js#L45
Here's where my deparse is defined: https://github.com/Satshabad/jaspect/blob/master/parser.js#L39
Here's parseSingleStatement: https://github.com/Satshabad/jaspect/blob/master/parser.js#L35
Hmm, I'm not sure. i've looked at the code. This doesn't seem like it has to do with nodeunit as far as I can tell.
It appears that uglify is generating slightly different output formatting for different calls to deparse. Maybe one way to solve this is to disable beautification when comparing the output strings? https://github.com/Satshabad/jaspect/blob/master/parser.js#L47
Hmmm, just tried it and there was no difference. It was the same output but in a different format. It couldn't be the way that nodeunit deals with multi line string comparison?
In any case thanks. This bug is making me question my own sanity.