/
runner.js
126 lines (109 loc) · 3.32 KB
/
runner.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var sys = require("sys");
process.mixin(GLOBAL, require("mjsunit"));
exports.run = function(testSuites) {
// Setup ARGS
var args = {};
var current = "";
for (var i=0; i<process.ARGV.length; i++)
{
current = process.ARGV[i];
if (current.substring(0,2) === "--") {
if (process.ARGV[i+1]) {
if (process.ARGV[i+1].substring(0,1) === "-") {
args[current.substring(2)] = true;
} else {
args[current.substring(2)] = process.ARGV[++i] || true;
}
} else {
args[current.substring(2)] = true;
}
} else if (current.substring(0,1) === "-") {
args[current.substring(1)] = process.ARGV[++i] || true;
}
}
var errors = [];
var total = 0;
var runTest = function(suiteName, suite, test) {
total++;
GLOBAL.builder.contentType = suite.contentType;
GLOBAL.builder.type = suite.type;
GLOBAL.builder.testDirectory = suiteName;
try {
suite.cases[test].call(GLOBAL);
} catch (e) {
suite.errors.push({ method: test, error: e});
errors.push({ method: test, error: e});
}
};
var runSuite = function(suiteName) {
testSuites[suiteName].total = 0;
testSuites[suiteName].errors = [];
for (var test in testSuites[suiteName].cases)
{
if (testSuites[suiteName].cases.hasOwnProperty(test)) {
testSuites[suiteName].total++;
runTest(suiteName, testSuites[suiteName], test);
}
}
}
if (args.suite) {
if (tests[args.suite]) {
if (args.test) {
runTest(args.suite, tests[args.suite], args.test);
} else {
runSuite(args.suite);
}
} else {
sys.puts("Invalid Suite Name\n\n Existing suites:")
for (var suiteName in tests) {
if (tests.hasOwnProperty(suiteName)) {
sys.puts(" " + suiteName);
}
}
sys.puts("");
process.exit(1);
}
} else {
for (suiteName in testSuites)
{
if (testSuites.hasOwnProperty(suiteName)) {
runSuite(suiteName);
}
}
}
if (args.verbose) {
for (var i = 0; i<errors.length; i++)
{
sys.puts('"' + errors[i].error.message + " (#" + errors[i].error.code + " " + errors[i].error.type + " in " + errors[i].method + ')');
sys.puts(errors[i].error.stack);
}
}
if (args.suite) {
sys.puts(" ");
sys.puts(errors.length + " of " + total + " failed (" + Math.round(((total-errors.length)/total)*100) + "% success)" );
sys.puts(" ");
} else {
var numerator, denominator, percent;
sys.puts("");
var padName = function(name) {
while(name.length < 13) {
name+=" ";
}
return name;
}
for (var suiteName in testSuites)
{
if (testSuites.hasOwnProperty(suiteName)) {
numerator = testSuites[suiteName].total - testSuites[suiteName].errors.length;
denominator = testSuites[suiteName].total;
percent = Math.round((numerator / denominator)*100,2) || 100;
sys.puts(padName(suiteName) + "\t" + numerator + "/" + denominator + "\t\t" + percent + "% passing");
}
}
sys.puts("--------------------------------------------");
numerator = total-errors.length;
denominator = total;
percent = Math.round((numerator / denominator)*100,2) || 100;
sys.puts("TOTALS:\t\t" + numerator + "/" + denominator + "\t\t" + percent + "% passing\r\n");
}
};