From 27580a98e963e582fb36556b655d0a65f42d625f Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 1 Jun 2024 13:21:50 +0200 Subject: [PATCH] [quickjs] Show number of assertions on exit --- src/ecmascript/quickjs/console.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ecmascript/quickjs/console.c b/src/ecmascript/quickjs/console.c index 1b33dbf59..e8990842a 100644 --- a/src/ecmascript/quickjs/console.c +++ b/src/ecmascript/quickjs/console.c @@ -21,6 +21,9 @@ static JSClassID js_console_class_id; +static int assertions; +static int failed_assertions; + static JSValue js_console_assert(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { @@ -33,11 +36,13 @@ js_console_assert(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst return JS_UNDEFINED; } bool res = JS_ToBool(ctx, argv[0]); + assertions++; if (res) { return JS_UNDEFINED; } FILE *log = fopen(console_error_filename, "a"); + failed_assertions++; if (!log) { return JS_UNDEFINED; @@ -123,7 +128,8 @@ js_console_exit(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *a if (!program.testjs) { return JS_UNDEFINED; } - program.retval = JS_ToBool(ctx, argv[0]) ? 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 JS_UNDEFINED; } @@ -143,7 +149,7 @@ static const JSCFunctionListEntry js_console_funcs[] = { JS_CFUNC_DEF("assert", 2, js_console_assert), JS_CFUNC_DEF("log", 1, js_console_log), JS_CFUNC_DEF("error", 1, js_console_error), - JS_CFUNC_DEF("exit", 1, js_console_exit), + JS_CFUNC_DEF("exit", 0, js_console_exit), JS_CFUNC_DEF("toString", 0, js_console_toString) };