| 1502 | |
| 1503 | function expose_assert(f, name) { |
| 1504 | function assert_wrapper(...args) { |
| 1505 | let status = Test.statuses.TIMEOUT; |
| 1506 | let stack = null; |
| 1507 | let new_assert_index = null; |
| 1508 | try { |
| 1509 | if (settings.debug) { |
| 1510 | console.debug("ASSERT", name, tests.current_test && tests.current_test.name, args); |
| 1511 | } |
| 1512 | if (tests.output) { |
| 1513 | tests.set_assert(name, args); |
| 1514 | // Remember the newly pushed assert's index, because `apply` |
| 1515 | // below might push new asserts. |
| 1516 | new_assert_index = tests.asserts_run.length - 1; |
| 1517 | } |
| 1518 | const rv = f.apply(undefined, args); |
| 1519 | status = Test.statuses.PASS; |
| 1520 | return rv; |
| 1521 | } catch(e) { |
| 1522 | status = Test.statuses.FAIL; |
| 1523 | stack = e.stack ? e.stack : null; |
| 1524 | throw e; |
| 1525 | } finally { |
| 1526 | if (tests.output && !stack) { |
| 1527 | stack = get_stack(); |
| 1528 | } |
| 1529 | if (tests.output) { |
| 1530 | tests.set_assert_status(new_assert_index, status, stack); |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | expose(assert_wrapper, name); |
| 1535 | } |
| 1536 | |