From 524cdeb09e1fbfcbb0df802906f90236adfbf823 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 1 Jun 2024 13:15:28 +0200 Subject: [PATCH] [spidermonkey] Show number of assertions. Return FAIL when number of failed assertions is not 0. --- src/ecmascript/spidermonkey/console.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ecmascript/spidermonkey/console.cpp b/src/ecmascript/spidermonkey/console.cpp index 4dce820e6..1e050fe64 100644 --- a/src/ecmascript/spidermonkey/console.cpp +++ b/src/ecmascript/spidermonkey/console.cpp @@ -63,10 +63,13 @@ const spidermonkeyFunctionSpec console_funcs[] = { { "assert", console_assert, 2 }, { "log", console_log, 1 }, { "error", console_error, 1 }, - { "exit", console_exit, 1 }, + { "exit", console_exit, 0 }, { NULL } }; +static int assertions; +static int failed_assertions; + static bool console_assert(JSContext *ctx, unsigned int argc, JS::Value *vp) { @@ -76,6 +79,7 @@ console_assert(JSContext *ctx, unsigned int argc, JS::Value *vp) if (argc < 1 || !get_opt_bool("ecmascript.enable_console_log", NULL)) { return true; } + assertions++; bool res = jsval_to_boolean(ctx, args[0]); if (res) { @@ -83,6 +87,7 @@ console_assert(JSContext *ctx, unsigned int argc, JS::Value *vp) } FILE *log = fopen(console_error_filename, "a"); + failed_assertions++; if (!log) { return true; } @@ -161,7 +166,8 @@ console_exit(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!program.testjs) { return true; } - program.retval = args[0].toBoolean() ? RET_ERROR : RET_OK; + fprintf(stderr, "Assertions: %d, failed assertions: %d\n", assertions, failed_assertions); + program.retval = failed_assertions ? RET_ERROR : RET_OK; program.terminate = 1; return true; }