Skip to content

Commit 369e165

Browse files
committed
Merge pull request #2 from tcr/johnnyman727-master
Adds test runner.
2 parents c3b0d0d + 674994e commit 369e165

File tree

6 files changed

+115
-13
lines changed

6 files changed

+115
-13
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "tinytap",
3-
"version": "0.1.0",
4-
"description": "Tiny tap parser and tools.",
5-
"main": "index.js",
3+
"version": "0.2.0",
4+
"description": "Tiny TAP tester and test runner.",
5+
"main": "./src/tester.js",
66
"bin": {
7-
"tinytap": "./tinytap.js"
7+
"tinytap": "./src/runner.js"
88
},
99
"dependencies": {
1010
"glob": "^4.0.0",
1111
"shell-quote": "^1.4.1"
1212
},
1313
"scripts": {
14-
"test": "echo \"Error: no test specified\" && exit 1"
14+
"test": "cd test; ./test.sh"
1515
},
1616
"author": "",
1717
"license": "MIT",

index.js renamed to src/parser.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ var fs = require('fs');
22
var Duplex = require('stream').Duplex;
33
var util = require('util');
44

5-
// console.log('tap tiny');
6-
75
function state (machine) {
86
var key = 'start';
97
return function caller () {

tinytap.js renamed to src/runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ var spawn = require('child_process').spawn;
44
var parse = require('shell-quote').parse;
55
var quote = require('shell-quote').quote;
66
var stream = require('stream');
7-
var tinytap = require('./');
87
var glob = require('glob');
98

9+
var tinytap = require('../src/parser');
10+
1011
var args = process.argv.slice(2);
1112
var list = [[null]];
1213

src/tester.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
module.exports = test
2+
3+
var tests = module.exports.tests = [];
4+
var ran = false
5+
var id = 0
6+
var fail = 0
7+
var pass = 0
8+
9+
function test(name, fn) {
10+
tests.push([name, fn]);
11+
if (ran) return;
12+
ran = true
13+
process.nextTick(run)
14+
}
15+
16+
var assert = require('assert');
17+
Error.captureStackTrace = function(){};
18+
19+
test.count = function (n) {
20+
console.log('1..' + Number(n));
21+
}
22+
23+
var t = Object.keys(assert).map(function (k) {
24+
if (typeof assert[k] !== 'function') return;
25+
return [k, function () {
26+
var s = null
27+
id++
28+
try {
29+
assert[k].apply(assert, arguments)
30+
pass ++
31+
console.log('ok', id, k)
32+
} catch (e) {
33+
34+
fail ++
35+
// ignore everything up to the run() function
36+
// Comment out until captureStackTrace is implemented
37+
// Error.captureStackTrace(e, t[k])
38+
s = e.stack
39+
if (s) {
40+
s = s.trim().split(/\n/)
41+
// bottom two frames are nextTick and this file
42+
s.pop()
43+
s.pop()
44+
}
45+
46+
if (s && !e.message)
47+
e.message = s[0]
48+
console.log('')
49+
console.log('not ok', id, s ? s.shift() : e.message)
50+
if (s && s.length) {
51+
s = s.map(function(s) {
52+
return s.trim() + '\n'
53+
})
54+
console.log('#' + s.join('# '))
55+
}
56+
console.log('')
57+
}
58+
}]
59+
}).reduce(function (set, kv) {
60+
set[kv[0]] = kv[1]
61+
return set
62+
}, {})
63+
64+
t.pass = function (m) {
65+
assert(true, m)
66+
}
67+
68+
t.fail = function (m) {
69+
assert(false, m)
70+
}
71+
72+
t.comment = function (m) {
73+
console.log('#', m.replace(/^#\s*/, ''), "\n")
74+
}
75+
76+
t.end = run
77+
78+
var children = []
79+
t.test = function(name, fn) {
80+
children.push([name, fn])
81+
}
82+
83+
function run () {
84+
if (children.length) {
85+
tests.unshift.apply(tests, children)
86+
children.length = 0
87+
}
88+
89+
var next = tests.shift();
90+
if (!next) {
91+
console.log('# pass', pass, pass + fail)
92+
console.log('# fail', fail, pass + fail)
93+
process.exit(fail)
94+
return
95+
}
96+
97+
var name = next[0];
98+
var fn = next[1];
99+
console.log('#', name);
100+
process.nextTick(function() {
101+
fn(t);
102+
})
103+
}

test.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cat colony.tap | node ../src/runner.js - > out.tap
2+
cat out.tap | node ../src/runner.js - > out2.tap
3+
diff out.tap out2.tap
4+
rm out.tap
5+
rm out2.tap

0 commit comments

Comments
 (0)