Skip to content

Commit

Permalink
Comment formatting review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Millin committed Sep 8, 2016
1 parent c878a3a commit c76157b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ Test.prototype.test = function (name, opts, cb) {
});
};

Test.prototype.comment = function () {
Test.prototype.comment = function (msg) {
var that = this;
var keys = Object.keys(arguments)
var msg = keys.length > 1 ? format.apply(null, arguments) : arguments[keys[0]];

// Previous behavior involved `toString` calls on objects, i.e. emitting `[object Object]`.
// `util.format`, however, will print stringified objects. To maintain backward compatibility
// check the args length and only call `util.format` if the invoker desires string expansion.
msg = arguments.length > 1 ? format.apply(null, arguments) : msg;

trim(msg).split('\n').forEach(function (aMsg) {
that.emit('result', trim(aMsg).replace(/^#\s*/, ''));
Expand Down
3 changes: 1 addition & 2 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ You may pass the same options that [`test()`](#testname-opts-cb) accepts.

## t.comment(message[, ...])

Print a message without breaking the tap output. Accepts optional args for `util.format`-style formatting.
(Useful when using e.g. `tap-colorize` where output is buffered & `console.log` will print in incorrect order vis-a-vis tap output.)
Print a message without breaking the tap output. Accepts optional args for `util.format`-style formatting. Useful when using e.g. `tap-colorize` where output is buffered & `console.log` will print in incorrect order vis-a-vis tap output.

## var htest = test.createHarness()

Expand Down
2 changes: 1 addition & 1 deletion test/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,4 @@ tap.test('formatted multiline string', function (assert) {
t.comment("tip\n%s\nt%s", "tap", "ape");
t.end();
});
});
});

0 comments on commit c76157b

Please sign in to comment.