zjsunit: Allow multiple overrides again.

I now let folks override the same target multiple
times inside of `with_overrides` (and then indirectly
inside of `run_test`.)

I may re-impose this restriction in the future, since
most violations are due to code smells, but there are
a few legitimate use cases for this, and the code
can handle it, plus I want to remove some other
ugliness first.
This commit is contained in:
Steve Howell 2021-03-07 15:11:56 +00:00 committed by Steve Howell
parent eea78df688
commit 8ab5475b37
1 changed files with 0 additions and 18 deletions

View File

@ -157,8 +157,6 @@ exports.with_overrides = function (test_function) {
const restore_callbacks = [];
const unused_funcs = new Map();
const funcs = new Map();
const override = function (obj, func_name, f) {
// Given an object `obj` (which is usually a module object),
// we re-map `obj[func_name]` to the `f` passed in by the caller.
@ -183,22 +181,6 @@ exports.with_overrides = function (test_function) {
`);
}
if (!funcs.has(obj)) {
funcs.set(obj, new Map());
}
if (funcs.get(obj).has(func_name)) {
// Prevent overriding the same function twice, so that
// it's super easy to reason about our logic to restore
// the original function. Usually if somebody sees this
// error, it's a symptom of not breaking up tests enough.
throw new Error(
"You can only override a function one time. Use with_field for more granular control.",
);
}
funcs.get(obj).set(func_name, true);
if (!unused_funcs.has(obj)) {
unused_funcs.set(obj, new Map());
}