Skip to content

Commit

Permalink
Try to set the stack property on the status for cleanup errors
Browse files Browse the repository at this point in the history
This makes them easier to diagnose.
  • Loading branch information
jgraham authored and pull[bot] committed Jul 4, 2023
1 parent fa2192e commit 1255685
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -2884,10 +2884,10 @@
* be cancelled.
*/
Test.prototype.cleanup = function() {
var error_count = 0;
var errors = [];
var bad_value_count = 0;
function on_error() {
error_count += 1;
function on_error(e) {
errors.push(e);
// Abort tests immediately so that tests declared within subsequent
// cleanup functions are not run.
tests.abort();
Expand All @@ -2904,7 +2904,7 @@
try {
result = cleanup_callback();
} catch (e) {
on_error();
on_error(e);
return;
}

Expand All @@ -2919,7 +2919,7 @@
});

if (!this._is_promise_test) {
cleanup_done(this_obj, error_count, bad_value_count);
cleanup_done(this_obj, errors, bad_value_count);
} else {
all_async(results,
function(result, done) {
Expand All @@ -2932,7 +2932,7 @@
}
},
function() {
cleanup_done(this_obj, error_count, bad_value_count);
cleanup_done(this_obj, errors, bad_value_count);
});
}
};
Expand All @@ -2954,17 +2954,21 @@
return false;
}

function cleanup_done(test, error_count, bad_value_count) {
if (error_count || bad_value_count) {
function cleanup_done(test, errors, bad_value_count) {
if (errors.length || bad_value_count) {
var total = test._user_defined_cleanup_count;

tests.status.status = tests.status.ERROR;
tests.status.stack = null;
tests.status.message = "Test named '" + test.name +
"' specified " + total +
" 'cleanup' function" + (total > 1 ? "s" : "");

if (error_count) {
tests.status.message += ", and " + error_count + " failed";
if (errors.length) {
tests.status.message += ", and " + errors.length + " failed";
tests.status.stack = ((typeof errors[0] === "object" &&
errors[0].hasOwnProperty("stack")) ?
errors[0].stack : null);
}

if (bad_value_count) {
Expand All @@ -2975,8 +2979,6 @@
}

tests.status.message += ".";

tests.status.stack = null;
}

test.phase = test.phases.COMPLETE;
Expand Down

0 comments on commit 1255685

Please sign in to comment.