From d7802123c155c1a0bc7704738ecf369ab013303a Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Thu, 28 May 2015 15:09:31 -0400 Subject: [PATCH] Fix multi-line assertion messages in test runner This commit prevents multi-line error messages from being truncated in the local test runner ('tests/run_from_console.js'). --- tests/run_from_console.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/run_from_console.js b/tests/run_from_console.js index f5c5bb4..371e861 100755 --- a/tests/run_from_console.js +++ b/tests/run_from_console.js @@ -250,6 +250,24 @@ if (!program.outputHtml && !program.generateHtml) { console.log(''); if (test_json.num_fails > 0 || program.printAll) { + var extract_error_lines = function (err) { + // the split is to avoid a weird thing where in PhantomJS where we get a stack trace too + var err_lines = err.split('\n'); + if (err_lines.length == 1) { + return err_lines[0]; + } else { + var ind; + for (ind = 0; ind < err_lines.length; ind++) { + var at_ind = err_lines[ind].trim().indexOf('at '); + if (at_ind === 0) { + break; + } + } + + return err_lines.slice(0, ind).join('\n'); + } + }; + var traverse_tree = function(indentation, node) { if (node.type == 'suite') { if (!node.has_subfailures && !program.printAll) return; @@ -281,7 +299,7 @@ if (!program.outputHtml && !program.generateHtml) { cursor.magenta(); console.log('- failed: '+node.text+test_json.replay); cursor.red(); - console.log(' '+node.error.split("\n")[0]); // the split is to avoid a weird thing where in PhantomJS where we get a stack trace too + console.log(' '+extract_error_lines(node.error)); cursor.reset(); console.log(''); }