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').
This commit is contained in:
Solly Ross 2015-05-28 15:09:31 -04:00
parent 1bcd031ba2
commit d7802123c1
1 changed files with 19 additions and 1 deletions

View File

@ -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('');
}