-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtt.js
More file actions
100 lines (86 loc) · 1.91 KB
/
tt.js
File metadata and controls
100 lines (86 loc) · 1.91 KB
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
// tiny node-tap lookalike.
module.exports = test
var tests = module.exports.tests = [];
var ran = false
var id = 0
var fail = 0
var pass = 0
function test(name, fn) {
tests.push([name, fn]);
if (ran) return;
ran = true
process.nextTick(run)
}
var assert = require('assert')
var t = Object.keys(assert).map(function (k) {
if (typeof assert[k] !== 'function') return;
return [k, function () {
var s = null
id++
try {
assert[k].apply(assert, arguments)
pass ++
console.log('ok %d %s', id, k)
console.log('')
} catch (e) {
fail ++
// ignore everything up to the run() function
Error.captureStackTrace(e, t[k])
s = e.stack
if (s) {
s = s.trim().split(/\n/)
// bottom two frames are nextTick and this file
s.pop()
s.pop()
}
if (s && !e.message)
e.message = s[0]
console.log('not ok %d %s', id, s ? s.shift() : e.message)
if (s && s.length) {
s = s.map(function(s) {
return s.trim() + '\n'
})
console.log('# ' + s.join('# '))
}
console.log('')
}
}]
}).reduce(function (set, kv) {
set[kv[0]] = kv[1]
return set
}, {})
t.pass = function (m) {
t.assert(true, m)
}
t.fail = function (m) {
t.assert(false, m)
}
t.comment = function (m) {
console.log('# %s\n', m.replace(/^#\s*/, ''))
}
t.end = run
var children = []
t.test = function(name, fn) {
children.push([name, fn])
}
function run() {
if (children.length) {
tests.unshift.apply(tests, children)
children.length = 0
}
var next = tests.shift();
if (!next) {
console.log('1..%d', id)
console.log('')
console.log('# pass %d/%d', pass, pass + fail)
console.log('# fail %d/%d', fail, pass + fail)
process.exit(fail)
return
}
var name = next[0];
var fn = next[1];
console.log('# %s\n', name);
process.nextTick(function() {
fn(t);
})
}