Skip to content

Commit 3ff86e1

Browse files
authored
Add assert_exception to the core test harnesses (#1991)
1 parent e2de519 commit 3ff86e1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

test/harness/async_index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,26 @@ function assert_trap(action, source) {
281281
.catch(_ => {});
282282
}
283283

284+
function assert_exception(action, source) {
285+
const test = `Test that a WebAssembly code throws an exception (${source})`;
286+
const loc = new Error().stack.toString().replace("Error", "");
287+
chain = Promise.all([chain, action()])
288+
.then(
289+
result => {
290+
uniqueTest(_ => {
291+
assert_true(false, loc);
292+
}, test);
293+
},
294+
error => {
295+
uniqueTest(_ => {
296+
// Pass
297+
}, test);
298+
}
299+
)
300+
// Clear all exceptions, so that subsequent tests get executed.
301+
.catch(_ => {});
302+
}
303+
284304
function assert_return(action, source, ...expected) {
285305
const test = `Test that a WebAssembly code returns a specific result (${source})`;
286306
const loc = new Error().stack.toString().replace("Error", "");
@@ -355,7 +375,7 @@ try {
355375
}
356376

357377
function assert_exhaustion(action) {
358-
const test = "Test that a WebAssembly code exhauts the stack space";
378+
const test = "Test that a WebAssembly code exhausts the stack space";
359379
const loc = new Error().stack.toString().replace("Error", "");
360380
chain = Promise.all([action(), chain])
361381
.then(

test/harness/sync_index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ function assert_trap(action, source) {
339339
}, `A wast module that must trap at runtime. (${source})`);
340340
}
341341

342+
function assert_exception(action, source) {
343+
let result = action();
344+
345+
_assert(result instanceof Result);
346+
347+
uniqueTest(() => {
348+
assert_true(result.isError(), 'expected error result');
349+
}, `A wast module that must throw an exception at runtime. (${source})`);
350+
}
351+
342352
let StackOverflow;
343353
try { (function f() { 1 + f() })() } catch (e) { StackOverflow = e.constructor }
344354

0 commit comments

Comments
 (0)