#!/usr/bin/env node

require('proof')(8, function (assert) {
    var exit = require('../../exit'),
        events = require('events'),
        stream = require('stream'),
        interrupt = require('../../interrupt')

    // rethrow an exception
    try {
        exit(null)(new Error('propagated'))
    } catch (e) {
        assert(e.message, 'propagated', 'propagated')
    }

    // set exit code for when when exit time come
    var process = new events.EventEmitter
    exit(process)(null, 0xaa)
    assert(process.exitCode, 0xaa, 'exit code set')

    process.stderr = new stream.PassThrough
    exit(process)(interrupt.error(new Error, 'abend', { code: 0x77, message: 'abended' }))
    assert(process.stderr.read().toString(), 'abended\n', 'abend error message')
    assert(process.exitCode, 0x77, 'abend exit code')
    process.stdout = new stream.PassThrough
    exit(process)(interrupt.error(new Error, 'help', { message: 'usage' }))
    assert(process.stdout.read().toString(), 'usage\n', 'help message')
    assert(process.exitCode, 0, 'help exit code')
    process.stdout = new stream.PassThrough
    exit(process)(interrupt.error(new Error, 'abend', { code: 0x77 }))
    assert(process.stdout.read(), null, 'no message')
    assert(process.exitCode, 0x77, 'no message exit code')
})

@@ -35,9 +35,9 @@
 f')(
-8
+9
 , fu
@@ -1288,11 +1288,97 @@
  code')%0A
+    exit(process)(null)%0A    assert(process.exitCode, 0x77, 'exit code with no error')%0A
 %7D)%0A

Test undefined exit code.