Skip to content

Commit

Permalink
Test coverage of new exit handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
flatheadmill committed Jul 28, 2015
1 parent 9df4252 commit 1b14f47
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
10 changes: 5 additions & 5 deletions exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ module.exports = function (process) {
code = interrupt.rescue(function (error) {
switch (error.type) {
case 'abend':
io.stderr.write(error.context.message)
io.stderr.write('\n')
process.stderr.write(error.context.message)
process.stderr.write('\n')
break
case 'help':
io.stdout.write(error.context.message)
io.stdout.write('\n')
process.stdout.write(error.context.message)
process.stdout.write('\n')
break
}
return error.context.code || 0
})(error)
}
process.on('exit', function () {
process.once('exit', function () {
process.exit(code)
})
}
Expand Down
21 changes: 19 additions & 2 deletions t/arguable/exit.t.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env node

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

// rethrow an exception
try {
Expand All @@ -18,4 +20,19 @@ require('proof')(2, function (assert) {
}
exit(process)(null, 0xaa)
process.emit('exit')

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

0 comments on commit 1b14f47

Please sign in to comment.