annotate core-javascript/core-javascript-work/testtools.js @ 137:71b7fd796ddf core-javascript

Add testtools.js and testtools.rst (and supporting demo file).
author jf3243
date Mon, 31 Oct 2011 15:16:58 +0000
parents
children 20d76c716c9d 7f86f1a807f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
1 var telltail = 'global';
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
2 var _assertion_count = 0;
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
3
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
4 // Define a global function 'log'.
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
5 var log;
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
6 if (this.hasOwnProperty('jsArguments')){
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
7
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
8 log = function(s){
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
9 print(s + '\n');
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
10 };
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
11 } else {
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
12 log = print;
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
13 }
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
14
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
15 //
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
16 var TEST = function(title, code){
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
17
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
18 log( 'Testing: ' + title );
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
19 _assertion_count = 0;
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
20 code();
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
21 };
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
22
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
23 var assert = function(arg){
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
24 _assertion_count += 1;
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
25 if (!arg){
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
26 var msg = '! assert ' + _assertion_count + ' has failed';
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
27 log(msg);
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
28 }
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
29 };
71b7fd796ddf Add testtools.js and testtools.rst (and supporting demo file).
jf3243
parents:
diff changeset
30