-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.js
68 lines (61 loc) · 2.08 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
var hexy = require("./hexy.js")
const testcases = require("./test/testcases.js")
var testcase_id = [ 0, 0 ] // some tests have multiple variants (distinguished by the intput). To make the navigation easier, the tests are numbered as [line.subtest]
var failed = 0
var executed = 0
var iterations = 1
if (process.argv.includes("perf")) {
iterations = 100000
}
var execute_first_X_tests = null
if (process.argv.includes("baseline")) { // baselining against version 0.3.2, which
execute_first_X_tests = 29 // had 29 test lines (65 testcases total), that
} // are preserved at the top of the list of tests
var verbose = false
if (process.argv.includes("-v")) {
verbose = true
}
function check(should, is) {
if (should !== is) {
console.log("\x1b[31m FAILED testcase # " + testcase_id + "\x1b[0m")
console.log(" EXPECTED")
console.log(should)
console.log(" ACTUALLY RETURNED")
console.log(is)
console.log("more detailed view of EXPECTED:")
console.log(hexy.hexy(should))
console.log("more detailed view of ACTUALLY RETURNED:")
console.log(hexy.hexy(is))
failed++
} else if (verbose) {
console.log(is)
}
executed++
}
for (var rep = 0; rep < iterations; rep++) {
for (var tc = 0; tc < (execute_first_X_tests || testcases.length); tc++) {
if ('inputs' in testcases[tc]) {
for (var ii = 0; ii < testcases[tc].inputs.length; ii++) {
testcase_id = [tc, ii]
check(testcases[tc].result, hexy.hexy(testcases[tc].inputs[ii], testcases[tc].params))
}
} else {
testcase_id = tc
check(testcases[tc].result, hexy.hexy(testcases[tc].input, testcases[tc].params))
}
}
}
function checkVersion () {
const fs = require("fs")
const pkg = fs.readFileSync("package.json")
const version = JSON.parse(pkg).version
check(version, hexy.Hexy.VERSION)
}
checkVersion()
console.log("Executed: " + executed + ", Failed: " + failed)
if (iterations > 1) {
console.log("This was a perf run over " + iterations + " iterations")
}
if (failed != 0) {
process.exit(1)
}