Mercurial > js4py
view core-javascript/javascript-exercises/testtools.js @ 171:19e88fb18c4e javascript-exercises
Modify testtools.js to work with Rhino (and hope still works with jsdb).
| author | jf3243 |
|---|---|
| date | Thu, 10 Nov 2011 17:06:52 +0000 |
| parents | 2d78ae4f0dfa |
| children |
line wrap: on
line source
var telltail = 'global'; var _assertion_count = 0; // Define a global function 'log'. var log; if (this.writeln){ log = writeln; } else { log = function(s){ print(s + '\n'); }; } // var TEST = function(title, code){ var x; log( 'Testing: ' + title ); _assertion_count = 0; try { code(); } catch (x) { log('! Exception at ' + x.fileName +':' + x.lineNumber); log('! [' + x.name + '] ' + x.message ); } }; var assert = function(arg){ _assertion_count += 1; if (!arg){ var msg = '! assert ' + _assertion_count + ' has failed'; log(msg); } }; var submit = function(name){ var filename = name + '-exercises.js'; var status = run(filename); if (!status){ writeln("Could not find file '" + filename + "'"); } };
