Skip to content

Commit

Permalink
Merge a35a4c6 into 25a1a19
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 3, 2016
2 parents 25a1a19 + a35a4c6 commit de41450
Show file tree
Hide file tree
Showing 23 changed files with 290 additions and 50 deletions.
11 changes: 6 additions & 5 deletions lib/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function clean (stack) {

return st.trim()
.replace(/^\s*at /, '')
.replace(/\\/g, '/')
.replace(cwd + '/', '')
.replace(cwd + '\\', '')
}).filter(function (st) {
return st
}).join('\n').trim()
Expand Down Expand Up @@ -128,13 +128,14 @@ function at (fn) {
}

var res = {
file: site.getFileName(),
file: site.getFileName().replace(/\\/g, '/'),
line: site.getLineNumber(),
column: site.getColumnNumber()
}

if (res.file.indexOf(cwd + '/') === 0 ||
res.file.indexOf(cwd + '\\') === 0) {
res.file = res.file.replace(/\\/g, '/')
res.file = res.file.substr(cwd.length + 1)
}

Expand Down Expand Up @@ -214,15 +215,15 @@ function parseLine (line) {
var native = match[11] === 'native'

var res = {
file: file,
file: file.replace(/\\/g, '/'),
line: +lnum,
column: +col
}

if (res.file &&
(res.file.indexOf(cwd + '/') === 0 ||
res.file.indexOf(cwd + '\\') === 0)) {
res.file = res.file.substr(cwd.length + 1)
res.file = res.file.substr(cwd.length + 1).replace(/\\/g, '/')
}

if (ctor) {
Expand All @@ -233,7 +234,7 @@ function parseLine (line) {
res.evalOrigin = evalOrigin
res.evalLine = evalLine
res.evalColumn = evalCol
res.evalFile = evalFile
res.evalFile = evalFile.replace(/\\/g, '/')
}

if (native) {
Expand Down
31 changes: 28 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ Test.prototype.threw = function threw (er, extra, proxy) {
}

this.fail(extra.message || er.message, extra)

// thrown errors cut to the front of the queue.
if (this._currentChild && this._queue.length) {
this._queue.unshift(this._queue.pop())
}
if (!proxy) {
this.end(IMPLICIT)
}
Expand Down Expand Up @@ -605,7 +610,7 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra) {
if (cmd === process.execPath) {
name = args.map(function (a) {
if (a.indexOf(process.cwd()) === 0) {
return './' + a.substr(process.cwd().length + 1)
return './' + a.substr(process.cwd().length + 1).replace(/\\/g, '/')
} else {
return a
}
Expand Down Expand Up @@ -661,7 +666,27 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra) {
}

var start = process.hrtime()
var child = spawn(cmd, args, options)
try {
var child = spawn(cmd, args, options)
} catch (er) {
this.threw(er)
return
}

child.on('error', function (er) {
this.threw(er)

// unhook entirely
child.stdout.removeAllListeners('data')
child.stdout.removeAllListeners('end')
child.removeAllListeners('close')
this._currentChild = null
this._processQueue()

// just to be safe, kill the process
child.kill('SIGKILL')
}.bind(this))

var parser = new Parser()
var self = this
this._currentChild = child
Expand Down Expand Up @@ -781,7 +806,7 @@ Test.prototype.done = Test.prototype.end = function end (implicit) {
}

if (this._currentChild) {
this._queue.push(['end'])
this._queue.push(['end', implicit])
return
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"codecov.io": "^0.1.6",
"coveralls": "^2.11.2",
"deeper": "^2.1.0",
"foreground-child": "^1.2.0",
"foreground-child": "^1.3.3",
"glob": "^6.0.1",
"js-yaml": "^3.3.1",
"mkdirp": "^0.5.0",
"nyc": "^5.1.0",
"nyc": "^5.2.0",
"only-shallow": "^1.0.2",
"opener": "^1.4.1",
"readable-stream": "^2.0.2",
Expand All @@ -34,7 +34,7 @@
"tap"
],
"license": "ISC",
"repository": "https://github.com/isaacs/node-tap.git",
"repository": "https://github.com/tapjs/node-tap.git",
"scripts": {
"regen-fixtures": "node scripts/generate-test-test.js test/test/*.js",
"test": "node bin/run.js test/*.* --coverage",
Expand Down
4 changes: 2 additions & 2 deletions scripts/generate-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ function generate (file, bail) {
output = output.split(node).join('\0N2\0')
output = output.split(path.basename(node)).join('\0N2\0')

output = output.split('\0N1\0').join('___/.*(node|iojs)')
output = output.split('\0N2\0').join('___/.*(node|iojs)/~~~')
output = output.split('\0N1\0').join('___/.*(node|iojs)(\.exe)?')
output = output.split('\0N2\0').join('___/.*(node|iojs)(\.exe)?/~~~')

output = yamlishToJson(output)

Expand Down
61 changes: 61 additions & 0 deletions test/executable-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var t = require('../')

if (process.platform === 'win32') {
t.plan(0, 'shebangs and exe bits are unix only')
process.exit(0)
}

var spawn = require('child_process').spawn
var path = require('path')
var fs = require('fs')
var fixdir = path.resolve(__dirname, 'executable-scripts')
var executed = path.resolve(fixdir, 'executed.sh')
var notExecuted = path.resolve(fixdir, 'not-executed.sh')
var run = require.resolve('../bin/run.js')
var node = process.execPath

function cleanup () {
try { fs.unlinkSync(executed) } catch (e) {}
try { fs.unlinkSync(notExecuted) } catch (e) {}
try { fs.rmdirSync(fixdir) } catch (e) {}
}

t.test('setup', function (t) {
cleanup()
fs.mkdirSync(fixdir, '0755')
fs.writeFileSync(
executed,
'#!/bin/sh\n' +
'echo 1..1\n' +
'echo ok 1 File with executable bit should be executed\n'
)
fs.chmodSync(executed, '0755')
fs.writeFileSync(
notExecuted,
'#!/bin/sh\n' +
'echo 1..1\n' +
'echo not ok 1 File without executable bit should not be run\n' +
'exit 1\n'
)
fs.chmodSync(notExecuted, '0644')
t.end()
})

t.test('run tap bin on shell scripts', function (t) {
var args = [run, fixdir, '--bail', '--no-color', '-Rtap']
var child = spawn(node, args)
var output = ''
child.stdout.on('data', function (c) {
output += c
})

child.on('close', function (code, signal) {
t.equal(code, 0, 'exit 0')
t.equal(signal, null, 'no signal exit')
t.notMatch(output, /not-executed\.sh/, 'not-executed.sh not seen')
t.match(output, /executed\.sh/, 'executed.sh was seen')
t.end()
})
})

t.tearDown(cleanup)
4 changes: 0 additions & 4 deletions test/executed.sh

This file was deleted.

12 changes: 9 additions & 3 deletions test/expose-gc-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
var tap = require('../')
var cp = require('child_process')
var node = process.execPath
var run = require.resolve('../bin/run.js')
var path = require('path')
var dir = path.resolve(__dirname, '..')
var gcScript = require.resolve('./fixtures/gc-script.js')
var opt = { cwd: dir }

tap.test("gc test when the gc isn't there", function (t) {
t.plan(1)
cp.exec('bin/run.js test/fixtures/gc-script.js', opt, function (err, stdo, stde) {
var args = [run, gcScript]
cp.execFile(node, args, opt, function (err, stdo, stde) {
if (err) throw err
t.equal(stde, 'false\n')
})
Expand All @@ -17,7 +21,8 @@ tap.test('gc test when the gc should be there', function (t) {
t.test('test for gc using --gc', function (t) {
t.plan(1)

cp.exec('bin/run.js --gc test/fixtures/gc-script.js', opt, function (err, stdo, stde) {
var args = [run, '--gc', gcScript]
cp.execFile(node, args, opt, function (err, stdo, stde) {
if (err) throw err
t.equal(stde, 'true\n')
})
Expand All @@ -26,7 +31,8 @@ tap.test('gc test when the gc should be there', function (t) {
t.test('test for gc using --expose-gc', function (t) {
t.plan(1)

cp.exec('bin/run.js --expose-gc test/fixtures/gc-script.js', opt, function (err, stdo, stde) {
var args = [run, '--expose-gc', gcScript]
cp.execFile(node, args, opt, function (err, stdo, stde) {
if (err) throw err
t.equal(stde, 'true\n')
})
Expand Down
5 changes: 0 additions & 5 deletions test/not-executed.sh

This file was deleted.

4 changes: 2 additions & 2 deletions test/only-non-tap-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (process.argv[2] === 'child') {
t.has(tt._skips, [
{
ok: true,
message: './test/only-non-tap-output.js child',
message: /\.[\\\/]test[\\\/]only-non-tap-output.js child/,
extra: {
at: {},
results: {},
Expand All @@ -31,7 +31,7 @@ if (process.argv[2] === 'child') {
},
{
ok: true,
message: './test/only-non-tap-output.js silent',
message: /\.[\\\/]test[\\\/]only-non-tap-output.js silent/,
extra: {
at: {},
results: {},
Expand Down
2 changes: 1 addition & 1 deletion test/require-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('compile-to-js require hook', function (t) {

function verifyOutput (err, stdout, stderr) {
t.ok(!!err, 'Should have failed to run')
t.match(stdout, 'file: test/fixtures/using-require-hook.faux',
t.match(stdout, /file: .*[\\\/]using-require-hook\.faux/,
'error happened in the *.faux file')
t.notMatch(stdout, 'source:',
'omits the source because the line cannot be resolved')
Expand Down
13 changes: 10 additions & 3 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t.test('usage', function (t) {
})
child.on('close', function (code) {
t.equal(code, c, 'code should be ' + c)
t.match(out, /^Usage:\n/, 'should print usage')
t.match(out, /^Usage:\r?\n/, 'should print usage')
t.end()
})
}
Expand Down Expand Up @@ -260,6 +260,8 @@ t.test('version', function (t) {
var skip = false
if (!headBin) {
skip = 'head program not available'
} else if (process.platform === 'win32') {
skip = 'signals on windows are weird'
}

t.test('handle EPIPE gracefully', { skip: skip }, function (t) {
Expand Down Expand Up @@ -324,7 +326,7 @@ t.test('unknown arg throws', function (t) {
}
})

t.test('read from stdin', function (t) {
t.test('read from stdin', { skip: process.platform === 'win32' && 'skip stdin test on windows' }, function (t) {
function stripTime (s) {
return s.split(ok).join('test/test/ok.js')
.replace(/[0-9\.]+m?s/g, '{{TIME}}')
Expand Down Expand Up @@ -482,9 +484,14 @@ t.test('-t or --timeout to set timeout', function (t) {
out += c
})
child.on('close', function (code, signal) {
var skip = process.platform === 'win32' && 'SIGTERM on windows is weird'
t.equal(code, 1)
t.equal(signal, null)
t.match(out, /received SIGTERM with pending event queue activity/)
t.match(
out,
/received SIGTERM with pending event queue activity/,
{ skip: skip }
)
t.end()
})
})
Expand Down
4 changes: 4 additions & 0 deletions test/segv.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
var tap = require('../')
if (process.platform === 'win32') {
tap.plan(0, 'skip on windows')
process.exit()
}
var test = tap.test
var Test = tap.Test
var fs = require('fs')
Expand Down
62 changes: 62 additions & 0 deletions test/spawn-failures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var cp = require('child_process')
var spawn = cp.spawn
cp.spawn = hijackedSpawn

var throwNow = false
var throwLater = false
function hijackedSpawn (cmd, args, options) {
if (throwNow) {
throw throwNow
}
var child = spawn.call(cp, cmd, args, options)
if (throwLater) {
setTimeout(function () {
child.emit('error', throwLater)
})
}
return child
}

var t = require('../')
var Test = t.Test
var ok = require.resolve('./test/ok.js')

t.test('handle throws from spawn()', function (t) {
throwNow = new Error('now is fine')

var output = ''
var tt = new Test()
tt.on('data', function (c) {
output += c
})
t.doesNotThrow(function spawn_throw_now () {
tt.spawn(process.execPath, [ok])
})
tt.end()
throwNow = false

t.comment(output)
t.notOk(tt.passing(), 'a failed spawn should fail the test')
t.end()
})

t.test('handle child process error event', function (t) {
throwLater = new Error('later is fine')

var output = ''
var tt = new Test()
tt.on('data', function (c) {
output += c
})
t.doesNotThrow(function spawn_throw_later () {
tt.spawn(process.execPath, [ok])
})
tt.end()

setTimeout(function () {
throwLater = false
t.comment(output)
t.notOk(tt.passing(), 'a failed spawn should fail the test')
t.end()
}, 100)
})

0 comments on commit de41450

Please sign in to comment.