Mercurial > js4py
comparison core-javascript/javascript-exercises/lib/testtools.js @ 182:a89af6d539ee javascript-exercises
$ hg mv javascript-exercises/testtools.js javascript-exercises/lib/
| author | jf3243 |
|---|---|
| date | Thu, 17 Nov 2011 15:46:42 +0000 |
| parents | core-javascript/javascript-exercises/testtools.js@19e88fb18c4e |
| children | 4a2f30b0a9d5 |
comparison
equal
deleted
inserted
replaced
| 181:f07846d74d8f | 182:a89af6d539ee |
|---|---|
| 1 var telltail = 'global'; | |
| 2 var _assertion_count = 0; | |
| 3 | |
| 4 // Define a global function 'log'. | |
| 5 var log; | |
| 6 if (this.writeln){ | |
| 7 log = writeln; | |
| 8 | |
| 9 } else { | |
| 10 log = function(s){ | |
| 11 print(s + '\n'); | |
| 12 }; | |
| 13 } | |
| 14 | |
| 15 // | |
| 16 var TEST = function(title, code){ | |
| 17 | |
| 18 var x; | |
| 19 | |
| 20 log( 'Testing: ' + title ); | |
| 21 _assertion_count = 0; | |
| 22 | |
| 23 try { | |
| 24 code(); | |
| 25 } catch (x) { | |
| 26 log('! Exception at ' + x.fileName +':' + x.lineNumber); | |
| 27 log('! [' + x.name + '] ' + x.message ); | |
| 28 } | |
| 29 | |
| 30 }; | |
| 31 | |
| 32 var assert = function(arg){ | |
| 33 _assertion_count += 1; | |
| 34 if (!arg){ | |
| 35 var msg = '! assert ' + _assertion_count + ' has failed'; | |
| 36 log(msg); | |
| 37 } | |
| 38 }; | |
| 39 | |
| 40 var submit = function(name){ | |
| 41 | |
| 42 var filename = name + '-exercises.js'; | |
| 43 var status = run(filename); | |
| 44 | |
| 45 if (!status){ | |
| 46 writeln("Could not find file '" + filename + "'"); | |
| 47 } | |
| 48 | |
| 49 }; |
