var Test = require('./test.js')

var to = process.env.TAP_TIMEOUT
if (to)
  to *= 1000

var tap = new Test({
  timeout: to || Infinity
})
module.exports = tap

tap._name = 'TAP'

process.on('exit', function (code) {
  delete tap.end
  tap.endAll()

  if (!tap._ok && code === 0)
    process.exit(1)
})

tap.end = function () {}
tap.pipe(process.stdout)
tap.plan = tap.plan.bind(tap)
tap.test = tap.test.bind(tap)

tap.mochaGlobals = require('./mocha.js').global

@@ -271,17 +271,108 @@
 e === 0)
+ %7B
 %0A
+    if (process.version.match(/%5Ev(0%5C.12%5C.%7C%5B%5E0%5D)/))%0A      process.exitCode = 1%0A    else%0A  
     proc
@@ -383,16 +383,20 @@
 exit(1)%0A
+  %7D%0A
 %7D)%0A%0Atap.

use process.exitCode instead of process.exit()