forked from jensnicolay/jipda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
98 lines (89 loc) · 1.76 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function t()
{
var result = TestSuite.runSuites(arguments.length === 0 ? undefined : arguments);
Test.displayTestResults(result);
}
function to()
{
b();
t(suiteObjectTests);
}
var Test = {};
Test.displayTestResults =
function (result)
{
var log = result.log.flatten();
log.forEach(
function (entry)
{
print ("===== " + entry.name + " =====");
print(entry.e);
if (entry.e.stack)
{
print(entry.e.stack);
}
});
print("SUCCESS: " + result.success);
print("FAIL : " + result.fail + " " + log.map(function (entry) { return entry.name; }));
print((result.time/1000) + " seconds");
}
function TestSuite(name)
{
this.name = name;
TestSuite.registrations.push(this);
}
TestSuite.registrations = [];
TestSuite.runSuites =
function (suites)
{
suites = suites || TestSuite.registrations;
var log = [];
var success = 0;
var fail = 0;
var start = Date.now();
for (var i = 0; i < suites.length; i++)
{
var result = suites[i].run();
success += result.success;
fail += result.fail;
log.push(result.log);
}
var end = Date.now();
return { success: success, fail: fail, log: log, time: (end - start)};
};
TestSuite.prototype.run =
function ()
{
var log = [];
var success = 0;
var fail = 0;
for (var name in this)
{
if (this.hasOwnProperty(name))
{
if (name.startsWith("test"))
{
print(this.name, name);
try
{
this[name].call(this);
success++;
}
catch (e)
{
fail++;
log.push({name: this.name + "." + name, e: e});
}
}
}
}
return { success: success, fail: fail, log: log };
}
//function propertiesEntrySet(obj)
//{
// return Object.keys(obj).map(
// function (key)
// {
// return [key, obj[key]];
// });
//}