zjsunit: Handle exceptions in with_field, with_overrides.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-22 19:54:23 -08:00
committed by Anders Kaseorg
parent 7e3735b9ba
commit 58b18fd499

View File

@@ -68,10 +68,12 @@ exports.restore = function () {
exports.with_field = function (obj, field, val, f) { exports.with_field = function (obj, field, val, f) {
const old_val = obj[field]; const old_val = obj[field];
obj[field] = val; try {
const result = f(); obj[field] = val;
obj[field] = old_val; return f();
return result; } finally {
obj[field] = old_val;
}
}; };
exports.with_overrides = function (test_function) { exports.with_overrides = function (test_function) {
@@ -165,11 +167,13 @@ exports.with_overrides = function (test_function) {
}); });
}; };
test_function(override); try {
test_function(override);
restore_callbacks.reverse(); } finally {
for (const restore_callback of restore_callbacks) { restore_callbacks.reverse();
restore_callback(); for (const restore_callback of restore_callbacks) {
restore_callback();
}
} }
for (const module_unused_funcs of unused_funcs.values()) { for (const module_unused_funcs of unused_funcs.values()) {