/
test_utils.js
49 lines (42 loc) · 1.22 KB
/
test_utils.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
(function (global) {
var errorCount = 0;
var logDiv;
function shouldThrow(expression) {
try {
eval(expression);
} catch (e) {
log("PASS: '" + expression + "' did throw");
return;
}
reportError("FAIL: '" + expression + "' should have thrown");
}
function shouldNotThrow(expression) {
try {
eval(expression);
} catch (e) {
reportError("FAIL: '" + expression + "' should not have thrown");
return;
}
log("PASS: '" + expression + "' did not throw");
}
function getErrorCount() {
return errorCount;
}
function reportError(message) {
log(message);
errorCount++;
}
function log(message) {
if (!logDiv) {
logDiv = document.createElement("div");
document.body.appendChild(logDiv);
}
logDiv.appendChild(document.createTextNode(message));
logDiv.appendChild(document.createElement("br"));
}
global.shouldThrow = shouldThrow;
global.shouldNotThrow = shouldNotThrow;
global.getErrorCount = getErrorCount;
global.reportError = reportError;
global.log = log;
})(self);