Skip to content

Commit ddd2535

Browse files
author
James Halliday
committed
fix double-piping bug in the output
1 parent 463afd2 commit ddd2535

File tree

4 files changed

+86
-15
lines changed

4 files changed

+86
-15
lines changed

example/nested.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var falafel = require('falafel');
2+
var test = require('../');
3+
4+
test('nested array test', function (t) {
5+
t.plan(5);
6+
7+
var src = '(' + function () {
8+
var xs = [ 1, 2, [ 3, 4 ] ];
9+
var ys = [ 5, 6 ];
10+
g([ xs, ys ]);
11+
} + ')()';
12+
13+
var output = falafel(src, function (node) {
14+
if (node.type === 'ArrayExpression') {
15+
node.update('fn(' + node.source() + ')');
16+
}
17+
});
18+
19+
t.test(function (q) {
20+
q.plan(2);
21+
q.ok(true);
22+
23+
setTimeout(function () {
24+
q.ok(true);
25+
}, 3000);
26+
});
27+
28+
var arrays = [
29+
[ 3, 4 ],
30+
[ 1, 2, [ 3, 4 ] ],
31+
[ 5, 6 ],
32+
[ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ],
33+
];
34+
35+
Function(['fn','g'], output)(
36+
function (xs) {
37+
t.same(arrays.shift(), xs);
38+
return xs;
39+
},
40+
function (xs) {
41+
t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]);
42+
}
43+
);
44+
});
45+
46+
test('another', function (t) {
47+
t.plan(1);
48+
setTimeout(function () {
49+
t.ok(true);
50+
}, 100);
51+
});

index.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ exports.Test = Test;
99
function createHarness () {
1010
var pending = [];
1111
var running = false;
12+
13+
var began = false;
1214
var out = new Render();
1315

1416
return function (name, conf, cb) {
@@ -18,19 +20,11 @@ function createHarness () {
1820
}
1921
var t = new Test;
2022
t.name = name;
21-
var piped = false;
22-
23-
t.pipe = function () {
24-
piped = true;
25-
};
26-
27-
t.once('pipe', function () {
28-
piped = true;
29-
});
3023

3124
process.nextTick(function () {
32-
if (!piped) out.pipe(createDefaultStream());
33-
out.begin();
25+
if (!out.piped) out.pipe(createDefaultStream());
26+
if (!began) out.begin();
27+
began = true;
3428

3529
var run = function () {
3630
running = true;

lib/render.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ function Render () {
1212

1313
Render.prototype = new Stream;
1414

15+
Render.prototype.pipe = function () {
16+
this.piped = true;
17+
return Stream.prototype.pipe.apply(this, arguments);
18+
};
19+
1520
Render.prototype.begin = function () {
1621
this.emit('data', 'TAP version 13\n');
1722
};
1823

1924
Render.prototype.push = function (t) {
2025
var self = this;
21-
this.emit('data', '# ' + t.name + '\n');
26+
this.emit('data', Array(t.indent + 1).join(' ') + '# ' + t.name + '\n');
2227

2328
t.on('result', function (res) {
2429
self.emit('data', encodeResult(res, self.count + 1));
@@ -44,7 +49,7 @@ Render.prototype.close = function () {
4449
};
4550

4651
function encodeResult (res, count) {
47-
var output = '';
52+
var output = Array(res.indent + 1).join(' ');
4853
output += (res.ok ? 'ok ' : 'not ok ') + count;
4954
output += res.name ? ' ' + res.name.replace(/\s+/g, ' ') : '';
5055

lib/test.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,39 @@ module.exports = Test;
66

77
Test.prototype = new EventEmitter;
88

9-
function Test (name) {
9+
function Test (name, opts) {
10+
if (!opts) opts = {};
1011
EventEmitter.call(this);
1112

1213
this.name = name || '(anonymous)';
1314
this.assertCount = 0;
15+
this.indent = opts.indent || 0;
1416
}
1517

18+
Test.prototype.test = function (name, cb) {
19+
var self = this;
20+
21+
if (typeof name === 'function') {
22+
cb = name;
23+
name = '(anonymous)';
24+
}
25+
26+
/*
27+
var t = new Test(name);
28+
29+
t.on('plan', function (n) {
30+
self._plan += n;
31+
});
32+
*/
33+
};
34+
1635
Test.prototype.comment = function (msg) {
1736
this.result('\n' + msg.trim());
1837
};
1938

2039
Test.prototype.plan = function (n) {
2140
this._plan = n;
41+
this.emit('plan', n);
2242
};
2343

2444
Test.prototype.end = function () {
@@ -32,6 +52,7 @@ Test.prototype._assert = function assert (ok, opts) {
3252

3353
var res = {
3454
id : self.assertCount ++,
55+
indent : self.indent,
3556
ok : Boolean(ok),
3657
skip : defined(extra.skip, opts.skip),
3758
name : defined(extra.message, opts.message, '(unnamed assert)'),
@@ -81,7 +102,7 @@ Test.prototype.skip = function (msg, extra) {
81102
Test.prototype.ok
82103
= Test.prototype.true
83104
= Test.prototype.assert
84-
= function (value, msg) {
105+
= function (value, msg, extra) {
85106
this._assert(value, {
86107
message : msg,
87108
operator : 'ok',

0 commit comments

Comments
 (0)