[tests] Fix assertFalse(exception) anti-pattern
Some debugging tests relied on the following anti-pattern: let exception = false; try { /* ... some code that may throw on test failure ... */ } catch (e) { exception = e; } assertFalse(exception); This may be problematic if a falseish value is thrown. Change-Id: I02eace4cc656fc9581928a90ac53cda4dc72b30c Reviewed-on: https://chromium-review.googlesource.com/972822 Reviewed-by: Georg Neis <neis@chromium.org> Commit-Queue: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#52105}
This commit is contained in:
parent
5197b24ba6
commit
b8ae2249a4
@ -42,8 +42,8 @@ function g() {
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listenerCalled = false;
|
||||
exception = false;
|
||||
let listenerCalled = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -82,7 +82,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerCalled = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -94,5 +94,5 @@ Debug.setBreakPoint(f, 0, 0);
|
||||
g();
|
||||
|
||||
// Make sure that the debug event listener vas invoked.
|
||||
assertFalse(exception, "exception in listener");
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listenerCalled);
|
||||
|
@ -5,7 +5,7 @@
|
||||
// Flags: --harmony-bigint
|
||||
|
||||
Debug = debug.Debug
|
||||
let exception = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
Debug.setListener(function(event, exec_state, event_data, data) {
|
||||
if (event != Debug.DebugEvent.Break) return;
|
||||
@ -16,9 +16,9 @@ Debug.setListener(function(event, exec_state, event_data, data) {
|
||||
assertEquals("bigint", typeof(o.value()));
|
||||
assertEquals(42n, o.value());
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
exceptionThrown = true;
|
||||
};
|
||||
});
|
||||
|
||||
!function() { debugger; }();
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener")
|
||||
|
@ -28,8 +28,8 @@
|
||||
Debug = debug.Debug
|
||||
|
||||
// Simple function which stores the last debug event.
|
||||
listenerComplete = false;
|
||||
exception = false;
|
||||
let listenerComplete = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
var breakpoint = -1;
|
||||
|
||||
@ -42,7 +42,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerComplete = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -57,4 +57,4 @@ g();
|
||||
|
||||
// Make sure that the debug event listener vas invoked.
|
||||
assertTrue(listenerComplete, "listener did not run to completion");
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener")
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
var exception = false; // Exception in debug event listener.
|
||||
var exceptionThrown = false; // Exception in debug event listener.
|
||||
var after_compile_count = 0;
|
||||
var compile_error_count = 0;
|
||||
var current_source = ''; // Current source being compiled.
|
||||
@ -85,7 +85,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -110,7 +110,7 @@ try {
|
||||
}
|
||||
|
||||
// Make sure that the debug event listener was invoked.
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener")
|
||||
|
||||
// Number of before and after + error events should be the same.
|
||||
assertEquals(compile_error_count, 1);
|
||||
|
@ -29,7 +29,7 @@
|
||||
Debug = debug.Debug
|
||||
|
||||
var listenerComplete = false;
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -43,7 +43,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -60,5 +60,5 @@ callDebugger();
|
||||
|
||||
|
||||
// Make sure that the debug event listener vas invoked.
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener")
|
||||
assertTrue(listenerComplete, "listener did not run to completion");
|
||||
|
@ -30,7 +30,7 @@
|
||||
Debug = debug.Debug
|
||||
|
||||
var listenerComplete = false;
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
|
||||
var testingConstructCall = false;
|
||||
|
||||
@ -127,7 +127,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerComplete = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e.toString() + e.stack;
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -191,7 +191,7 @@ new f(input.length - 1, 11.11, 12.12);
|
||||
new f(input.length - 1, 11.11, 12.12, "");
|
||||
|
||||
// Make sure that the debug event listener was invoked.
|
||||
assertFalse(exception, "exception in listener " + exception)
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listenerComplete);
|
||||
|
||||
//Throw away type information for next run.
|
||||
|
@ -30,7 +30,7 @@
|
||||
Debug = debug.Debug
|
||||
|
||||
var listenerComplete = false;
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
|
||||
var testingConstructCall = false;
|
||||
|
||||
@ -118,7 +118,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerComplete = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e.toString() + e.stack;
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -172,7 +172,7 @@ new f(expected.length - 1, 11, 12);
|
||||
new f(expected.length - 1, 11, 12, 0);
|
||||
|
||||
// Make sure that the debug event listener was invoked.
|
||||
assertFalse(exception, "exception in listener " + exception)
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listenerComplete);
|
||||
|
||||
// Throw away type information for next run.
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listenerComplete = false;
|
||||
exception = false;
|
||||
let listenerComplete = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
|
||||
function h() {
|
||||
@ -132,7 +132,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerComplete = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
exceptionThrown = true;
|
||||
print("Caught something. " + e + " " + e.stack);
|
||||
};
|
||||
};
|
||||
@ -145,5 +145,5 @@ var f_result = f();
|
||||
assertEquals("foobar", f_result);
|
||||
|
||||
// Make sure that the debug event listener was invoked.
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listenerComplete);
|
||||
|
@ -30,9 +30,9 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listenerComplete = false;
|
||||
exception = false;
|
||||
breakPointCount = 0;
|
||||
let listenerComplete = false;
|
||||
let exceptionThrown = false;
|
||||
let breakPointCount = 0;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -53,7 +53,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -79,4 +79,4 @@ eval("with({bar:'with'}) { (function g() { var foo = 'local'; debugger; })(); }"
|
||||
|
||||
// Make sure that the debug event listener vas invoked.
|
||||
assertEquals(3, breakPointCount);
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
|
@ -27,8 +27,8 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listenerComplete = false;
|
||||
exception = false;
|
||||
let listenerComplete = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -51,7 +51,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerComplete = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -80,6 +80,6 @@ for (var i = 0; i < 4; i++) {
|
||||
Debug.setBreakPoint(f, 2, 0);
|
||||
g();
|
||||
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
// Make sure that the debug event listener vas invoked.
|
||||
assertTrue(listenerComplete, "listener did not run to completion");
|
||||
|
@ -27,12 +27,12 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listener_complete = false;
|
||||
exception = false;
|
||||
break_count = 0;
|
||||
expected_return_value = 0;
|
||||
expected_source_position = [];
|
||||
debugger_source_position = 0;
|
||||
let listener_complete = false;
|
||||
let exceptionThrown = false;
|
||||
let break_count = 0;
|
||||
let expected_return_value = 0;
|
||||
let expected_source_position = [];
|
||||
let debugger_source_position = 0;
|
||||
|
||||
// Listener which expects to do four steps to reach returning from the function.
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
@ -72,7 +72,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
print(e + e.stack)
|
||||
};
|
||||
};
|
||||
@ -93,7 +93,7 @@ expected_return_value = 2;
|
||||
expected_source_position = [10, 38, 47];
|
||||
listener_complete = false;
|
||||
f();
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listener_complete);
|
||||
assertEquals(4, break_count);
|
||||
|
||||
@ -102,7 +102,7 @@ expected_return_value = 1;
|
||||
expected_source_position = [10, 19, 28];
|
||||
listener_complete = false;
|
||||
f(true);
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listener_complete);
|
||||
assertEquals(4, break_count);
|
||||
|
||||
@ -111,6 +111,6 @@ expected_return_value = 2;
|
||||
expected_source_position = [10, 38, 47];
|
||||
listener_complete = false;
|
||||
f(false);
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
assertTrue(listener_complete);
|
||||
assertEquals(4, break_count);
|
||||
|
@ -4,8 +4,9 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listenerComplete = false;
|
||||
breakPointCount = 0;
|
||||
let listenerComplete = false;
|
||||
let breakPointCount = 0;
|
||||
let exceptionThrown = false;
|
||||
|
||||
async function f() {
|
||||
await (async function() { var a = "a"; await 1; debugger; })();
|
||||
@ -13,7 +14,7 @@ async function f() {
|
||||
var b = "b";
|
||||
|
||||
assertTrue(listenerDone);
|
||||
assertFalse(exception);
|
||||
assertFalse(exceptionThrown);
|
||||
assertEquals(1, breakpointCount);
|
||||
}
|
||||
|
||||
@ -27,7 +28,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
assertEquals("b", exec_state.frame(1).evaluate("b"));
|
||||
assertEquals("c", exec_state.frame(2).evaluate("c"));
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -29,8 +29,8 @@ Debug = debug.Debug
|
||||
|
||||
// Make sure that the backtrace command can be processed when the receiver is
|
||||
// undefined.
|
||||
listenerCalled = false;
|
||||
exception = false;
|
||||
let listenerCalled = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -47,7 +47,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
exception = e
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -67,6 +67,6 @@ try {
|
||||
// Ignore the exception "Cannot call method 'x' of undefined"
|
||||
}
|
||||
|
||||
assertFalse(exception, "exception in listener", exception)
|
||||
assertFalse(exceptionThrown, "exception in listener");
|
||||
// Make sure that the debug event listener vas invoked.
|
||||
assertTrue(listenerCalled, "listener not called");
|
||||
|
@ -31,8 +31,8 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
|
||||
listenerCalled = false;
|
||||
exception = false;
|
||||
let listenerCalled = false;
|
||||
let exceptionThrown = false;
|
||||
|
||||
|
||||
function checkName(name) {
|
||||
@ -64,7 +64,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
listenerCalled = true;
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
exceptionThrown = true;
|
||||
};
|
||||
};
|
||||
|
||||
@ -77,4 +77,4 @@ Debug.setListener(listener);
|
||||
|
||||
// Make sure that the debug event listener vas invoked (again).
|
||||
assertTrue(listenerCalled);
|
||||
assertFalse(exception, "exception in listener")
|
||||
assertFalse(exceptionThrown, "exception in listener")
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
Debug = debug.Debug;
|
||||
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -44,7 +44,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
assertThrows(() => lookup("b"), ReferenceError);
|
||||
}
|
||||
} catch (e) {
|
||||
exception = e.toString() + e.stack;
|
||||
exceptionThrown = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,4 +63,4 @@ function f(a, b) {
|
||||
|
||||
f(1, 2)(3, 4);
|
||||
|
||||
assertFalse(exception);
|
||||
assertFalse(exceptionThrown);
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
Debug = debug.Debug;
|
||||
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
if (event != Debug.DebugEvent.Break) return;
|
||||
@ -44,7 +44,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
// Assert correct value.
|
||||
assertEquals(3, breakpoint.evaluate('x').value());
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
exceptionThrown = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,4 +67,4 @@ function h() {
|
||||
|
||||
h();
|
||||
|
||||
assertFalse(exception);
|
||||
assertFalse(exceptionThrown);
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
Debug = debug.Debug
|
||||
var breaks = 0;
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
try {
|
||||
@ -43,7 +43,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
exception = true;
|
||||
exceptionThrown = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,4 +72,4 @@ Debug.setBreakPoint(b, 0, 0);
|
||||
a(b);
|
||||
a(); // BREAK 3
|
||||
|
||||
assertFalse(exception);
|
||||
assertFalse(exceptionThrown);
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
// Get the Debug object exposed from the debug context global object.
|
||||
Debug = debug.Debug
|
||||
var exception = false;
|
||||
var exceptionThrown = false;
|
||||
var state = 0;
|
||||
|
||||
function listener(event, exec_state, event_data, data) {
|
||||
@ -57,7 +57,7 @@ function listener(event, exec_state, event_data, data) {
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
exception = true;
|
||||
exceptionThrown = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,4 +70,4 @@ function a() {
|
||||
// Set a break point and call to invoke the debug event listener.
|
||||
Debug.setBreakPoint(a, 0, 0);
|
||||
a();
|
||||
assertFalse(exception);
|
||||
assertFalse(exceptionThrown);
|
||||
|
Loading…
Reference in New Issue
Block a user