Skip to content

Commit

Permalink
Allow Node.js to format exceptions.
Browse files Browse the repository at this point in the history
Do this instead of trying to comment out stack traces. The program will
exit non-zero, so the test runner will always mark it as a failed test.
The `Bail out!` is TAP compliant, so the failure will be apparent in a
log of a test run.
  • Loading branch information
flatheadmill committed Dec 9, 2016
1 parent 2b68346 commit 715155d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 12 additions & 1 deletion redux/scaffold.js
Expand Up @@ -72,7 +72,7 @@ module.exports = function (count, test) {
} else {
stream.write('Bail out!\n')
if (error.stack) {
assert.say(error.stack)
throw error
} else {
assert.inspect(error)
}
Expand Down Expand Up @@ -114,6 +114,17 @@ module.exports = function (count, test) {
stream.write('1..' + expected + '\n')
}

// Found where line numbers are added, syntax context is added. Will
// have to read carefully to see if we can recreate, but then it would
// be Node.js/V8 specific, specific to Node.js. Although I have no
// intention of running in other JavaScript environments, it is probably
// best to treat the Proof scaffold as a minimal process wrapper, let
// Node.js do its thing.
//
// https://github.com/nodejs/node/blob/4db97b832b2522551d1bfacc1b95e3cbbf2df097/src/node.cc#L1440
// Hoplessness. Add answer.
// http://stackoverflow.com/questions/13746831/how-can-i-get-the-line-number-of-a-syntaxerror-thrown-by-requireid-in-node-js
// So, I'm removing a try/catch block here.
try {
test.call(null, assert, callback)
if (test.length == 1) callback()
Expand Down
15 changes: 8 additions & 7 deletions t/proof/scaffold.t.js
Expand Up @@ -92,13 +92,14 @@ function prove (assert) {

assert(out.read().toString(), 'Bail out!\n# 1\n', 'throw integer')

var expected = { exitCode: 1, message: 'exit 1 throw error' }

scaffold(0, function (_assert) {
throw new Error('hello')
})(globals, out, exit, noop)

assert(/^# .*hello$/m.test(out.read().toString()), 'throw error')
try {
scaffold(0, function (_assert) {
throw new Error('hello')
})(globals, out, exit, noop)
} catch (error) {
assert(error.message, 'hello', 'throw error')
assert(out.read().toString(), 'Bail out!\n', 'throw error bail out')
}

var expected = { exitCode: 1, message: 'exit 1 missing tests' }

Expand Down

0 comments on commit 715155d

Please sign in to comment.