Skip to content
Browse files

stdout and stderr logging display always regardless of errors in file

  • Loading branch information...
1 parent 58645c9 commit e06df94c597d08068b321d8cb4b6f3639bd51dc1 @jeffbski committed Dec 8, 2011
Showing with 29 additions and 23 deletions.
  1. +8 −2 README.md
  2. +4 −3 bin/tapr.js
  3. +14 −11 lib/tapper.js
  4. +1 −1 package.json
  5. +2 −4 test/simple.test.js
  6. +0 −2 test/simple2.test.js
View
10 README.md
@@ -7,7 +7,6 @@ Tapper (aka tapr) is a node.js tap runner which allows stdout and stderr mixed i
- More concise formatting of tap output (easier to find what you care about)
- Improve ability to write to stdout and stderr from tests or code
- - stdout/stderr is muted for successful tests, but displayed for files with failing tests
- Add optional colorized output
## Installing
@@ -24,7 +23,7 @@ Add to your project package.json
```javascript
"devDependencies": {
- "tapr" : "~0.1.0"
+ "tapr" : "~0.1.1"
}
```
@@ -53,6 +52,7 @@ Pull from github - http://github.com/jeffbski/tapper
## Status
+ - v0.1.1 - 2011-12-08 - change stdout/stderr to always output, not just for failed tests
- v0.1.0 - 2011-11-28 - tapr - change bin/tapper to bin/tapr for convenient typing. tapr is also short for tap runner
- v0.0.6 - 2011-11-22 - Tapper is based on the original tap code with minor changes. The runner will evolve with features as time permits but appears to be fully functional.
@@ -80,6 +80,12 @@ Stderr and stdout is muted except for files which have a failing test
![failed-tap](http://github.com/jeffbski/tapper/raw/master/doc/failed-tap.png)
+## Limitations
+
+ - stdout logging that looks like tap output (ok, not ok, #) will not be displayed unless errors in file, however all stderr logging will be displayed regardless so it is recommended.
+ - stdout/stderr appears before the test names and asserts due to how tap currently outputs data
+ - Asserts are summarized at the bottom
+
## License
- [MIT license](http://github.com/jeffbski/tapper/raw/master/LICENSE)
View
7 bin/tapr.js
@@ -4,9 +4,9 @@ var sprintf = require('sprintf').sprintf;
var clc = require('cli-color');
var optimist = require('optimist');
-var VERSION = '0.1.0';
+var VERSION = '0.1.1';
-var argv = optimist.usage('Usage: $0 fileOrDir {OPTIONS}', {
+var argv = optimist.usage('Usage: $0 path [path2 pathN] {OPTIONS}', {
'help': {
description: 'Show this usage screen',
boolean: true,
@@ -51,10 +51,11 @@ r.on("file", function (file, results, details) {
if (details.skip) {
console.log(" skipped: %s", details.skipTotal)
}
+ if (results.nonTapOutAndErr && results.nonTapOutAndErr.trim()) console.error(results.nonTapOutAndErr);
} else {
if (colorize) sdotsn = clc.red(sdotsn);
console.log(sdotsn);
- if (results.stderr && results.stderr.trim()) console.error(results.stderr);
+ if (results.fullOutAndErr && results.fullOutAndErr.trim()) console.error(results.fullOutAndErr);
console.error(formatFailedAsserts(details));
//console.error(details)
// console.log(" Command: %s", results.command)
View
25 lib/tapper.js
@@ -88,7 +88,8 @@ Runner.prototype.runFiles = function (files, dir, cb) {
var cp = child_process.spawn(cmd, args, { env: env, cwd: relDir })
, out = ""
- , err = ""
+ , fullOutAndErr = "" //used for combined stdout (tap and other) + stderr, used for failed
+ , nonTapOutAndErr = "" //filtered version of stdout + stderr, used for success
, tc = new TapConsumer
, childTests = [f]
@@ -114,10 +115,17 @@ Runner.prototype.runFiles = function (files, dir, cb) {
}
return accum;
}, []);
+ nonTapOutAndErr += (filtered.filter(nonTapOutput).join('\n')); // only non-tap stdout
if (self.colorize) filtered = filtered.map(colorizeTapOutput);
- err += filtered.join('\n');
- }); //Copy our stdout non-tap msgs to stderr
- cp.stderr.on("data", function (c) { err += c })
+ fullOutAndErr += filtered.join('\n'); // tap and non-tap output
+ });
+ cp.stderr.on("data", function (c) { //all stderr is used regardless of file error status
+ fullOutAndErr += c;
+ nonTapOutAndErr += c;
+ });
+
+ var TAP_OUT_RE = /^ok|^#|^not ok/;
+ function nonTapOutput(line) { return !line.match(TAP_OUT_RE); }
function colorizeTapOutput(line) {
var x = line;
@@ -130,13 +138,8 @@ Runner.prototype.runFiles = function (files, dir, cb) {
//childTests.forEach(function (c) { self.write(c) })
var res = { name: fileName
, ok: !code }
- if (err) {
- res.stderr = err;
- if (tc.results.ok && tc.results.tests === 0) {
- // perhaps a compilation error or something else failed...
- console.error(err)
- }
- }
+ if (fullOutAndErr) res.fullOutAndErr = fullOutAndErr;
+ if (nonTapOutAndErr) res.nonTapOutAndErr = nonTapOutAndErr;
res.command = [cmd].concat(args).map(JSON.stringify).join(" ")
self.emit("result", res)
self.emit("file", f, res, tc.results)
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "tapr",
"description": "Tapper (tapr) is a tap runner which allows stdout and stderr mixed in with the tap output and also presents detail output in a more concise fashion. Tapper also optionally adds color to the output. Core based on Isaac Z Schlueter original tap runner.",
- "version": "0.1.0",
+ "version": "0.1.1",
"author": "Jeff Barczewski <jeff.barczewski@gmail.com>",
"contributors": [
"Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
View
6 test/simple.test.js
@@ -2,8 +2,6 @@
var test = require('tap').test;
test('simple test', function (t) {
- //uncomment next line to see the logging, logs show up when file has errors
- //t.fail('failing so we can see the logs');
console.log('this should be logged to stdout');
console.error('this should go to stderr');
t.ok(true);
@@ -22,14 +20,14 @@ test('another simple test', function (t) {
});
test('showing some deeper stderr logging by inspect on tap.test', function (t) {
- console.error(t);
+ console.error('on stderr:', t);
t.ok(true);
t.equal('foo', 'foo');
t.end();
});
test('showing some deeper stdout logging by inspect on tap.test', function (t) {
- console.log(t);
+ console.log('on stdout:', t);
t.ok(true);
t.equal('foo', 'foo');
t.end();
View
2 test/simple2.test.js
@@ -2,8 +2,6 @@
var test = require('tap').test;
test('another simple test', function (t) {
- //uncomment next line to see the logging, logs show up when file has errors
- //t.equal('foo', 'bar', 'purposefully making this fail for example');
t.equal(true, true);
console.error('I will log to stderr here.');
t.end();

0 comments on commit e06df94

Please sign in to comment.
Something went wrong with that request. Please try again.