Skip to content

Commit

Permalink
improve output for errors thrown, create examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbski committed Nov 28, 2011
1 parent 75314d4 commit cb8fba7
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 26 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Tapper

Tapper is a tap runner which allows stdout and stderr mixed in with the tap output. Also tapper adds color to the output. Core based on Isaac Z Schlueter original tap runner.
Tapper (aka tapr) is a tap runner which allows stdout and stderr mixed in with the tap output. Also tapper adds color to the output. Core based on Isaac Z Schlueter original tap runner.


## Goals

- 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
- Output is muted for successful tests, but displayed for failing tests
- Add colorized output

- stdout/stderr is muted for successful tests, but displayed for files with failing tests
- Add optional colorized output

## Installing

```bash
npm install https://github.com/jeffbski/tapper/tarball/v0.0.7 # to install locally
npm install tapr
# OR
npm install -g https://github.com/jeffbski/tapper/tarball/v0.0.7 # to install globally
npm install -g tapr
```

OR
Expand All @@ -24,7 +24,7 @@ Add to your project package.json

```javascript
"devDependencies": {
"tapper" : "https://github.com/jeffbski/tapper/tarball/v0.0.7"
"tapper" : "~0.1.0"
}
```

Expand All @@ -41,19 +41,20 @@ Pull from github - http://github.com/jeffbski/tapper
## Usage

```bash
node_modules/.bin/tapper.js fileOrDir # if installed locally
node_modules/.bin/tapr.js fileOrDir # if installed locally
#OR
tapper fileOrDir # if installed globally
tapr fileOrDir # if installed globally
#
tapper # display usage
tapper --help # display usage
tapper --version # display version
tapper --no-color fileOrDir # run without color output
tapr # display usage
tapr --help # display usage
tapr --version # display version
tapr --no-color fileOrDir # run without color output
```

## Status

- 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.
- 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.

## License

Expand Down
13 changes: 10 additions & 3 deletions bin/tapper.js → bin/tapr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var sprintf = require('sprintf').sprintf;
var clc = require('cli-color');
var optimist = require('optimist');

var VERSION = '0.0.7';
var VERSION = '0.1.0';

var argv = optimist.usage('Usage: $0 fileOrDir {OPTIONS}', {
'help': {
Expand Down Expand Up @@ -94,9 +94,16 @@ function formatFailedAsserts(details) {
if (!details || !details.list) return '';
var failed = details.list.filter(function (x) { return (!x.ok); });
var msgs = failed.map(function (x) {
var msg = sprintf('Assert: "%s", \n\t found: %s \n\twanted: %s', x.name, x.found, x.wanted);
var msg, stack;
if (x.thrown) {
msg = sprintf('Error thrown: %s "%s" \n\tcode: %s, errno: %s\n', x.type, x.message, x.code, x.errno);
stack = ' ' + x.stack.join('\n '); // indent stack lines by two spaces
} else { //normal assertion failure
msg = sprintf('Assert: "%s", \n\t found: %s \n\twanted: %s', x.name, x.found, x.wanted);
stack = sprintf('\n\t%s:%s', x.file, x.line);
}
if (colorize) msg = clc.red(msg);
return msg + sprintf('\n\t%s:%s', x.file, x.line);
return msg + stack;
});
msgs.push(''); //cause newline
return msgs.join('\n');
Expand Down
11 changes: 11 additions & 0 deletions example/fail-stderr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

var test = require('tap').test;

test('failing example which writes to stderr', function (t) {
t.equal('foo', 'bar', 'purposefully making this fail for example');
console.error('I will log to stderr here.');
t.end();
});



16 changes: 16 additions & 0 deletions example/fail-stdout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

var test = require('tap').test;

test('failing example which writes to stdout', function (t) {
t.equal('cat', 'dog', 'purposefully making this fail for example');
console.error('I will log to stdout here.');
t.end();
});

test('successful example', function (t) {
t.equal(1, 1);
t.end();
});



13 changes: 13 additions & 0 deletions example/fail-throws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

var test = require('tap').test;

var obj = { };

test('failing example which throws', function (t) {
obj.boom(); //throws TypeError since boom is not a method of obj
t.ok(true);
t.end();
});



15 changes: 15 additions & 0 deletions example/success-stderr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

var test = require('tap').test;

test('successful example with stderr', function (t) {
//This stderr output will not display in the tapr output unless this
//file has at least one failing test. Makes it easy to ignore output
//except when you care about it.
console.error('this will not display unless a failure occurs in page');
t.equal(1, 1);
t.end();
});




4 changes: 2 additions & 2 deletions lib/tapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ Runner.prototype.runFiles = function (files, dir, cb) {
if (!inYaml) {
if (/^\s{2}---\s*$/.test(l)) {
inYaml = true;
} else { //not in yaml, not a --- line, so keep it
accum.push(l);
} else { //not in yaml, not a --- line, so keep it if not an excluded tap line
if (!/^(\d+\.\.\d+|#\s+tests\s+\d+|#\s+pass\s+\d+|#\s+fail\s+\d+)\s*$/.test(l)) accum.push(l);
}
} else { //in yaml
if (/^\s{2}\.\.\.\s*$/.test(l)) inYaml = false;
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tapper",
"description": "Tapper is a tap runner which allows stdout and stderr mixed in with the tap output. Also tapper adds color to the output. Core based on Isaac Z Schlueter original tap runner.",
"version": "0.0.6",
"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",
"author": "Jeff Barczewski <jeff.barczewski@gmail.com>",
"contributors": [
"Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
Expand All @@ -11,7 +11,7 @@
"bugs" : { "url": "http://github.com/jeffbski/tapper/issues" },
"licenses": [{ "type": "MIT", "url" : "http://github.com/jeffbski/tapper/raw/master/LICENSE" }],
"main": "lib/tapper",
"bin" : "bin/tapper.js",
"bin" : "bin/tapr.js",
"engines": { "node": "~v0.4.12" },
"dependencies": {
"cli-color": "~0.1.4",
Expand All @@ -25,11 +25,11 @@
"devDependencies": {
},
"scripts": {
"test": "bin/tapper.js test"
"test": "bin/tapr.js test"
},
"directories" : {
"lib" : "./lib",
"test" : "./test"
},
"keywords" : [ "assert", "test", "tap" ]
"keywords" : [ "assert", "test", "tap", "runner", "color" ]
}
4 changes: 2 additions & 2 deletions test/simple2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
var test = require('tap').test;

test('another simple test', function (t) {
t.plan(2);
t.ok(true);
//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();
Expand Down

0 comments on commit cb8fba7

Please sign in to comment.