/usr/lib/nodejs/tap-parser/bin/cmd.js is in node-tap-parser 3.0.3-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #!/usr/bin/env nodejs
var Parser = require('../')
var etoa = require('events-to-array')
var util = require('util')
var args = process.argv.slice(2)
var json = null
args.forEach(function (arg, i) {
if (arg === '-j') {
json = args[i + 1] || 2
} else {
var m = arg.match(/^--json(?:=([0-9]+))$/)
if (m)
json = +m[1] || args[i + 1] || 2
}
if (arg === '-t' || arg === '--tap')
json = 'tap'
if (arg === '-h' || arg === '--help')
usage()
if (arg === '-v' || arg === '--version')
console.log(require('../package.json').version)
process.exit()
})
function usage () {
console.log(function () {/*
Usage:
tap-parser [-j [<indent>] | --json[=indent] | -t | --tap]
Parses TAP data from stdin, and outputs an object representing
the data found in the TAP stream to stdout.
If there are any failures in the TAP stream, then exits with a
non-zero status code.
Data is output by default using node's `util.format()` method, but
JSON can be specified using the `-j` or `--json` flag with a number
of spaces to use as the indent (default=2).
If you pass -t or --tap as an argument, then the output will be a
re-imagined synthesized purified idealized manufactured TAP stream,
rather than JSON or util.format.
*/}.toString().split('\n').slice(1, -1).join('\n'))
if (!process.stdin.isTTY)
process.stdin.resume()
process.exit()
}
var yaml = require('js-yaml')
function tapFormat (msg, indent) {
return indent + msg.map(function (item) {
switch (item[0]) {
case 'child':
return tapFormat(item[1], ' ')
case 'version':
return 'TAP version ' + item[1] + '\n'
case 'plan':
var p = item[1].start + '..' + item[1].end
if (item[1].comment)
p += ' # ' + item[1].comment
return p + '\n'
case 'pragma':
return 'pragma ' + (item[2] ? '+' : '-') + item[1] + '\n'
case 'bailout':
var r = item[1] === true ? '' : (' ' + item[1])
return 'Bail out!' + r + '\n'
case 'assert':
var res = item[1]
return (res.ok ? '' : 'not ') + 'ok ' + res.id +
(res.name ? ' - ' + res.name : '') +
(res.skip ? ' # SKIP' +
(res.skip === true ? '' : ' ' + res.skip) : '') +
(res.todo ? ' # TODO' +
(res.todo === true ? '' : ' ' + res.todo) : '') +
(res.time ? ' # time=' + res.time + 's' : '') +
'\n' +
(res.diag ?
' ---\n ' +
yaml.safeDump(res.diag).split('\n').join('\n ').trim() +
'\n ...\n'
: '')
case 'extra':
case 'comment':
return item[1]
}
}).join('').split('\n').join('\n' + indent).trim() + '\n'
}
function format (msg) {
if (json === 'tap')
return tapFormat(msg, '')
else if (json !== null)
return JSON.stringify(msg, null, +json)
else
return util.inspect(events, null, Infinity)
}
var parser = new Parser()
var events = etoa(parser, [ 'pipe', 'unpipe', 'prefinish', 'finish', 'line' ])
process.stdin.pipe(parser)
process.on('exit', function () {
console.log(format(events))
if (!parser.ok)
process.exit(1)
})
|