Skip to content

Commit

Permalink
Reduce stack size.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar authored and James Halliday committed Feb 1, 2014
1 parent 7fe6486 commit 3b05526
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,24 @@ Results.prototype.createStream = function () {
var self = this;
var output = resumer();
output.queue('TAP version 13\n');

nextTick(function () {
var t = getNextTest(self);
if (t) t.run()
else self.emit('done')

nextTick(function next() {
var t;
while (t = getNextTest(self)) {
t.run();
if (!t.ended) return t.once('end', function(){ nextTick(next); });
}
self.emit('done');
});
self._stream.pipe(output);

return output;
};

Results.prototype.push = function (t) {
var self = this;
self.tests.push(t);
self._watch(t);
t.once('end', function () {
var nt = getNextTest(self);
if (nt) nt.run()
else self.emit('done')
});
};

Results.prototype.only = function (name) {
Expand All @@ -69,7 +67,7 @@ Results.prototype._watch = function (t) {
}
write(encodeResult(res, self.count + 1));
self.count ++;

if (res.ok) self.pass ++
else self.fail ++
});
Expand All @@ -82,35 +80,35 @@ Results.prototype.close = function () {
if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED'));
self.closed = true;
var write = function (s) { self._stream.queue(s) };

write('\n1..' + self.count + '\n');
write('# tests ' + self.count + '\n');
write('# pass ' + self.pass + '\n');
if (self.fail) write('# fail ' + self.fail + '\n')
else write('\n# ok\n')

self._stream.queue(null);
};

function encodeResult (res, count) {
var output = '';
output += (res.ok ? 'ok ' : 'not ok ') + count;
output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';

if (res.skip) output += ' # SKIP';
else if (res.todo) output += ' # TODO';

output += '\n';
if (res.ok) return output;

var outer = ' ';
var inner = outer + ' ';
output += outer + '---\n';
output += inner + 'operator: ' + res.operator + '\n';

var ex = json.stringify(res.expected, getSerialize()) || '';
var ac = json.stringify(res.actual, getSerialize()) || '';

if (Math.max(ex.length, ac.length) > 65) {
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
Expand All @@ -130,14 +128,14 @@ function encodeResult (res, count) {
output += inner + lines[i] + '\n';
}
}

output += outer + '...\n';
return output;
}

function getSerialize () {
var seen = [];

return function (key, value) {
var ret = value;
if (typeof value === 'object' && value) {
Expand All @@ -148,7 +146,7 @@ function getSerialize () {
break;
}
}

if (found) ret = '[Circular]'
else seen.push(value)
}
Expand Down

0 comments on commit 3b05526

Please sign in to comment.