Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "tinytap",
"version": "0.1.0",
"description": "Tiny tap parser and tools.",
"main": "index.js",
"version": "0.2.0",
"description": "Tiny TAP tester and test runner.",
"main": "./src/tester.js",
"bin": {
"tinytap": "./tinytap.js"
"tinytap": "./src/runner.js"
},
"dependencies": {
"glob": "^4.0.0",
"shell-quote": "^1.4.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "cd test; ./test.sh"
},
"author": "",
"license": "MIT",
Expand Down
2 changes: 0 additions & 2 deletions index.js → src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ var fs = require('fs');
var Duplex = require('stream').Duplex;
var util = require('util');

// console.log('tap tiny');

function state (machine) {
var key = 'start';
return function caller () {
Expand Down
3 changes: 2 additions & 1 deletion tinytap.js → src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ var spawn = require('child_process').spawn;
var parse = require('shell-quote').parse;
var quote = require('shell-quote').quote;
var stream = require('stream');
var tinytap = require('./');
var glob = require('glob');

var tinytap = require('../src/parser');

var args = process.argv.slice(2);
var list = [[null]];

Expand Down
103 changes: 103 additions & 0 deletions src/tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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');
Error.captureStackTrace = function(){};

test.count = function (n) {
console.log('1..' + Number(n));
}

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', id, k)
} catch (e) {

fail ++
// ignore everything up to the run() function
// Comment out until captureStackTrace is implemented
// 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('')
console.log('not ok', 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) {
assert(true, m)
}

t.fail = function (m) {
assert(false, m)
}

t.comment = function (m) {
console.log('#', m.replace(/^#\s*/, ''), "\n")
}

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('# pass', pass, pass + fail)
console.log('# fail', fail, pass + fail)
process.exit(fail)
return
}

var name = next[0];
var fn = next[1];
console.log('#', name);
process.nextTick(function() {
fn(t);
})
}
5 changes: 0 additions & 5 deletions test.sh

This file was deleted.

5 changes: 5 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cat colony.tap | node ../src/runner.js - > out.tap
cat out.tap | node ../src/runner.js - > out2.tap
diff out.tap out2.tap
rm out.tap
rm out2.tap