-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (35 loc) · 920 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function log(msg) {
if (typeof console != "undefined")
console.log(msg);
}
function AssertException(message) {
this.message = message;
}
AssertException.prototype.toString = function() {
return 'AssertException: ' + this.message;
}
function assert(exp, message) {
if (!exp) {
throw new AssertException(message);
}
}
function testModule(module) {
var failed = 0;
var passed = 0;
for (var s in module) {
if (s.substr(0, 5) == "_test" && typeof module[s] == "function") {
try {
module[s].apply(module);
passed += 1;
}
catch (e) {
log(s + ": " + e.toString());
if (e["stack"] !== undefined) {
log(e.stack);
}
failed += 1;
}
}
}
log("test passed: " + passed + ", failed: " + failed);
}