Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

runner: Exit with failure on signal'd failures

Fix #54
  • Loading branch information...
commit 4ffebe852b8695fdce7c244e39c2d64feaea76d0 1 parent decf6f9
@isaacs authored
Showing with 67 additions and 3 deletions.
  1. +7 −3 lib/tap-runner.js
  2. +60 −0 test/segv.js
View
10 lib/tap-runner.js
@@ -219,18 +219,22 @@ Runner.prototype.runFiles = function (files, dir, cb) {
err += c
})
- cp.on("exit", function (code) {
+ cp.on("exit", function (code, signal) {
if (cp._ended) return
cp._ended = true
- var ok = !cp._timedOut && !code
+ var ok = !cp._timedOut && code === 0
clearTimeout(timeout)
//childTests.forEach(function (c) { self.write(c) })
var res = { name: path.dirname(f).replace(process.cwd() + "/", "")
+ "/" + fileName
, ok: ok
- , timedOut: cp._timedOut
, exit: code }
+ if (cp._timedOut)
+ res.timedOut = cp._timedOut
+ if (signal)
+ res.signal = signal
+
if (err) {
res.stderr = err
if (tc.results.ok &&
View
60 test/segv.js
@@ -0,0 +1,60 @@
+var test = require('../').test
+var Runner = require('../lib/tap-runner.js')
+var TC = require('../lib/tap-consumer.js')
+
+var fs = require('fs')
+var spawn = require('child_process').spawn
+var segv =
+ 'int main (void) {\n' +
+ ' char *s = "hello world";\n' +
+ ' *s = \'H\';\n' +
+ '}\n'
+var compiled = false
+
+test('setup', function (t) {
+ fs.writeFile('segv.c', segv, 'utf8', function (er) {
+ if (er)
+ throw er
+ var cp = spawn('gcc', ['segv.c', '-o', 'segv'])
+ cp.on('exit', function (code, sig) {
+ if (code !== 0) {
+ t.bailout('failed to compile segv program')
+ return
+ }
+ t.pass('compiled seg faulter')
+ t.end()
+ })
+ })
+})
+
+test('segv', function (t) {
+ var r = new Runner({argv:{remain:['./segv']}})
+ var tc = new TC()
+ var expect =
+ [ { 'id': 1,
+ 'ok': false,
+ 'name': ' ././segv',
+ 'exit': null,
+ 'timedOut': true,
+ 'signal': 'SIGBUS',
+ 'command': '"./segv"' }
+ , 'tests 1'
+ , 'fail 1' ]
+ r.pipe(tc)
+ tc.on('data', function (d) {
+ t.same(d, expect.shift())
+ })
+ tc.on('end', function () {
+ t.equal(expect.length, 0)
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ fs.unlink('segv.c', function () {
+ fs.unlink('segv', function () {
+ t.pass('cleaned up')
+ t.end()
+ })
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.