Mercurial > js4py
view core-javascript/javascript-exercises/testtools.js @ 170:fc3411a0efe9 javascript-exercises
Add content to README file.
| author | jf3243 |
|---|---|
| date | Thu, 10 Nov 2011 16:52:51 +0000 |
| parents | 2d78ae4f0dfa |
| children | 19e88fb18c4e |
line wrap: on
line source
var telltail = 'global'; var _assertion_count = 0; // Define a global function 'log'. var log; if (this.hasOwnProperty('jsArguments')){ log = function(s){ print(s + '\n'); }; } else { log = print; log = writeln; // Wrong, but get us working in jsdb.exe. } // 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 + "'"); } };
