annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
138
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
1 var telltail = 'global';
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
2 var _assertion_count = 0;
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
3
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
4 // Define a global function 'log'.
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
5 var log;
171
19e88fb18c4e Modify testtools.js to work with Rhino (and hope still works with jsdb).
jf3243
parents: 168
diff changeset
6 if (this.writeln){
19e88fb18c4e Modify testtools.js to work with Rhino (and hope still works with jsdb).
jf3243
parents: 168
diff changeset
7 log = writeln;
156
b774913eb242 Remove trailing whitespace from js files (js2mode does not repsect delete-trailing-whitespace).
jf3243
parents: 152
diff changeset
8
171
19e88fb18c4e Modify testtools.js to work with Rhino (and hope still works with jsdb).
jf3243
parents: 168
diff changeset
9 } else {
138
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
10 log = function(s){
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
11 print(s + '\n');
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
12 };
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
13 }
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
14
156
b774913eb242 Remove trailing whitespace from js files (js2mode does not repsect delete-trailing-whitespace).
jf3243
parents: 152
diff changeset
15 //
138
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
16 var TEST = function(title, code){
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
17
152
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
18 var x;
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
19
138
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
20 log( 'Testing: ' + title );
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
21 _assertion_count = 0;
152
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
22
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
23 try {
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
24 code();
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
25 } catch (x) {
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
26 log('! Exception at ' + x.fileName +':' + x.lineNumber);
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
27 log('! [' + x.name + '] ' + x.message );
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
28 }
82f672a37506 In testtools.js catch and report exceptions.
jf3243
parents: 138
diff changeset
29
138
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
30 };
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
31
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
32 var assert = function(arg){
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
33 _assertion_count += 1;
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
34 if (!arg){
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
35 var msg = '! assert ' + _assertion_count + ' has failed';
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
36 log(msg);
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
37 }
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
38 };
20d76c716c9d core-javascript-work$ for NAME in * ; do perl -i -p -e 's/\n/ # use DOS line endings
Jonathan Fine <jfine@pytex.org>
parents: 137
diff changeset
39
168
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
40 var submit = function(name){
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
41
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
42 var filename = name + '-exercises.js';
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
43 var status = run(filename);
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
44
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
45 if (!status){
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
46 writeln("Could not find file '" + filename + "'");
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
47 }
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
48
2d78ae4f0dfa Make a start on interactive exercise environment and additional exercises.
jf3243
parents: 164
diff changeset
49 };