Skip to content

Commit

Permalink
feat: Upgrade TAP parser, overhaul formated output
Browse files Browse the repository at this point in the history
* Add `-v|--verbose` command line parameter and option to print succeeding assertions too
* Print total count of passed, failed, todo and skipped tests only if they are non-zero
* Print also todo and skipped tests, mismatch between planned and executed test count and bail-out message
* Format error information on multiple lines
* Fail the tests if no TAP output is printed on the console
* Upgrade the TAP parser
* Upgrade the rest of npm module dependencies

* Migrate from npm to pnpm
* Migrate from Travis to GitHub Actions

BREAKING CHANGE: The upgraded TAP parser 11.0 has different behaviour than the original 0.7. Programmatically, the "comment" event is triggered with the comment including the "# " prefix and the "results" event was renamed to "complete". Further optimisations of the formatted output reduce unnecessary text and render errors in a more legible way.
  • Loading branch information
prantlf committed Jun 5, 2022
1 parent a3efa12 commit afbd39d
Show file tree
Hide file tree
Showing 48 changed files with 1,631 additions and 508 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = false
insert_final_newline = true
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test or Release

on:
- push
- pull_request

jobs:
test-or-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: '>=6'
run_install: |
- args: [--frozen-lockfile, --no-verify-store-integrity]
- name: Test
run: npm test
- name: Publish
uses: cycjimmy/semantic-release-action@v2
with:
semantic_version: 18
branches: master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.DS_Store
node_modules
nom-debug.log
2 changes: 0 additions & 2 deletions .ncurc.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

* Trim too long assert messages to prevent line overflow ([6f9b1fb](https://github.com/prantlf/astrobench/commit/6f9b1fb2c6262115608e3392bd65f6e3957530d3))
* Upgrade npm modules, which were possible ([fb949e](https://github.com/prantlf/astrobench/commit/fb949e553b181092047961194d732b0a281d5deb))
* switch sprintf out for sprintf-js (Chris Apparicio <[email protected]>) ([1bb6b6e](https://github.com/prantlf/astrobench/commit/1bb6b6e7c2d1fe0770d4df70ade03e79b078d530))
* Switch `sprintf` out for `sprintf-js` (Chris Apparicio <[email protected]>) ([1bb6b6e](https://github.com/prantlf/astrobench/commit/1bb6b6e7c2d1fe0770d4df70ade03e79b078d530))

This is the first version released after forking the [original project](https://github.com/substack/faucet).
20 changes: 11 additions & 9 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
var faucet = require('../');
var minimist = require('minimist');
var defined = require('defined');
var tapeCmd = require.resolve('tape/bin/tape');

var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');

var argv = minimist(process.argv.slice(2));
var tap = faucet({
verbose: defined(argv.v, argv.verbose, false),
width: defined(argv.w, argv.width, process.stdout.isTTY
? process.stdout.columns - 5
: 0
Expand All @@ -27,28 +23,34 @@ if (!process.stdin.isTTY || argv._[0] === '-') {
return;
}

var { dirname, join } = require('path');
var tapeCmd = join(dirname(require.resolve('tape')), 'bin/tape');

var spawn = require('child_process').spawn;
var fs = require('fs');

var files = argv._.reduce(function (acc, file) {
if (fs.statSync(file).isDirectory()) {
return acc.concat(fs.readdirSync(file).map(function (x) {
return path.join(file, x);
return join(file, x);
}).filter(jsFile));
}
else return acc.concat(file);
}, []);

if (files.length === 0 && fs.existsSync('test')) {
files.push.apply(files, fs.readdirSync('test').map(function (x) {
return path.join('test', x);
return join('test', x);
}).filter(jsFile));
}
if (files.length === 0 && fs.existsSync('tests')) {
files.push.apply(files, fs.readdirSync('tests').map(function (x) {
return path.join('tests', x);
return join('tests', x);
}).filter(jsFile));
}

if (files.length === 0) {
console.error('usage: `faucet [FILES]` or `| faucet`\n');
console.error('usage: `faucet [-v|--verbose] [-w|--width=<number>] [FILES]`\n or `| faucet [-v|--verbose] [-w|--width=<number>]`\n');
console.error(
'No test files or stdin provided and no files in test/ or tests/'
+ ' directories found.'
Expand Down
26 changes: 26 additions & 0 deletions example/13/creative-liberties.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TAP version 13
ok - created Board
ok
ok
ok
ok
ok
ok
ok
---
message: "Board layout"
severity: comment
dump:
board:
- ' 16G 05C '
- ' G N C C C G '
- ' G C + '
- '10C 01G 03C '
- 'R N G G A G C C C '
- ' R G C + '
- ' 01G 17C 00C '
- ' G A G G N R R N R '
- ' G R G '
...
ok - board has 7 tiles + starter tile
1..9
4 changes: 4 additions & 0 deletions example/13/giving-up.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TAP version 13
1..573
not ok 1 - database handle
Bail out! Couldn't connect to database.
6 changes: 6 additions & 0 deletions example/13/got-spare-tuits.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TAP version 13
1..4
ok 1 - Creating test program
ok 2 - Test program runs, no error
not ok 3 - infinite loop # TODO halting problem unsolved
not ok 4 - infinite loop 2 # TODO halting problem unsolved
17 changes: 17 additions & 0 deletions example/13/named.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
TAP version 13
1..4
ok 1 - Input file opened
not ok 2 - First line of the input valid
---
message: 'First line invalid'
severity: fail
data:
got: 'Flirble'
expect: 'Fnible'
...
ok 3 - Read the rest of the file
not ok 4 - Summarized correctly # TODO Not written yet
---
message: "Can't make summary yet"
severity: todo
...
8 changes: 8 additions & 0 deletions example/13/skipping-a-few.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TAP version 13
1..5
ok 1 - approved operating system
# $^0 is solaris
ok 2 - # SKIP no /sys directory
ok 3 - # SKIP no /sys directory
ok 4 - # SKIP no /sys directory
ok 5 - # SKIP no /sys directory
2 changes: 2 additions & 0 deletions example/13/skipping-everything.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TAP version 13
1..0 # skip because English-to-French translator isn't installed
18 changes: 18 additions & 0 deletions example/13/unknown-amount-and-failures.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
TAP version 13
ok 1 - retrieving servers from the database
# need to ping 6 servers
ok 2 - pinged diamond
ok 3 - pinged ruby
not ok 4 - pinged saphire
---
message: 'hostname "saphire" unknown'
severity: fail
...
ok 5 - pinged onyx
not ok 6 - pinged quartz
---
message: 'timeout'
severity: fail
...
ok 7 - pinged gold
1..7
7 changes: 7 additions & 0 deletions example/13/unnamed.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TAP version 13
1..6
not ok
ok
not ok
ok
ok
9 changes: 9 additions & 0 deletions example/14/backwards-compatibility-and-parsing-notes.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TAP version 14
1..2

# skip: true
ok 1 - do it later # Skipped

# skip: true
# skip reason: "only run on windows"
ok 2 - works on windows # Skipped: only run on windows
15 changes: 15 additions & 0 deletions example/14/backwards-compatibility-and-parsing-notes2.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TAP version 14

# skip: true
# skip reason: "this test is skipped"
# description: ""
ok 1 # skip this test is skipped

# skip: false
# description: "not skipped: https://example.com/page.html\#skip is a url"
ok 2 not skipped: https://example.com/page.html#skip is a url

# skip: true
# skip reason: "case insensitive, so this is skipped"
# description: ""
ok 3 - #SkIp case insensitive, so this is skipped
12 changes: 12 additions & 0 deletions example/14/common-with-explanation.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TAP version 14
1..6
#
# Create a new Board and Tile, then place
# the Tile onto the board.
#
ok 1 - The object isa Board
ok 2 - Board size is zero
ok 3 - The object isa Tile
ok 4 - Get possible places to put the Tile
ok 5 - Placing the tile produces no error
ok 6 - Board size is 1
26 changes: 26 additions & 0 deletions example/14/creative-liberties.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TAP version 14
ok - created Board
ok
ok
ok
ok
ok
ok
ok
---
message: "Board layout"
severity: comment
dump:
board:
- ' 16G 05C '
- ' G N C C C G '
- ' G C + '
- '10C 01G 03C '
- 'R N G G A G C C C '
- ' R G C + '
- ' 01G 17C 00C '
- ' G A G G N R R N R '
- ' G R G '
...
ok - board has 7 tiles + starter tile
1..9
35 changes: 35 additions & 0 deletions example/14/escaping-examples.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
TAP version 14

# description: hello
# todo: true
ok 1 - hello # todo

# description: hello # todo
# todo: false
ok 2 - hello \# todo

# description: hello
# todo: true
# todo reason: hash # character
ok 3 - hello # todo hash \# character
# (assuming "character" isn't a known custom directive)
ok 4 - hello # todo hash # character

# description: hello \
# todo: true
# todo reason: hash # character
ok 5 - hello \\# todo hash \# character
# (assuming "character" isn't a known custom directive)
ok 6 - hello \\# todo hash # character

# description: hello # description # todo
# todo: false
# (assuming "description" isn't a known custom directive)
ok 7 - hello # description # todo

# multiple escaped \ can appear in a row
# description: hello \\\# todo
# todo: false
ok 8 - hello \\\\\\\# todo

1..8
4 changes: 4 additions & 0 deletions example/14/giving-up.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TAP version 14
1..573
not ok 1 - database handle
Bail out! Couldn't connect to database.
17 changes: 17 additions & 0 deletions example/14/named.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
TAP version 14
1..4
ok 1 - Input file opened
not ok 2 - First line of the input valid
---
message: 'First line invalid'
severity: fail
data:
got: 'Flirble'
expect: 'Fnible'
...
ok 3 - Read the rest of the file
not ok 4 - Summarized correctly # TODO Not written yet
---
message: "Can't make summary yet"
severity: todo
...
10 changes: 10 additions & 0 deletions example/14/pragmas.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TAP version 14
# tell the parser to bail out on any failures from now on
pragma +bail

# tell the parser to execute in strict mode, treating any invalid TAP
# line as a test failure.
pragma +strict

# turn off a feature we don't want to be active right now
pragma -bail
6 changes: 6 additions & 0 deletions example/14/procrastination-considered-ok.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TAP version 14
1..4
ok 1 - Creating test program
ok 2 - Test program runs, no error
not ok 3 - infinite loop # TODO halting problem unsolved
not ok 4 - infinite loop 2 # TODO halting problem unsolved
8 changes: 8 additions & 0 deletions example/14/skipping-a-few.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TAP version 14
1..5
ok 1 - approved operating system
# $^0 is solaris
ok 2 - # SKIP no /sys directory
ok 3 - # SKIP no /sys directory
ok 4 - # SKIP no /sys directory
ok 5 - # SKIP no /sys directory
2 changes: 2 additions & 0 deletions example/14/skipping-everything.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TAP version 14
1..0 # skip because English-to-French translator isn't installed
Loading

0 comments on commit afbd39d

Please sign in to comment.