mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[spidermonkey] Show number of assertions.
Return FAIL when number of failed assertions is not 0.
This commit is contained in:
parent
582c0e6e40
commit
524cdeb09e
@ -63,10 +63,13 @@ const spidermonkeyFunctionSpec console_funcs[] = {
|
|||||||
{ "assert", console_assert, 2 },
|
{ "assert", console_assert, 2 },
|
||||||
{ "log", console_log, 1 },
|
{ "log", console_log, 1 },
|
||||||
{ "error", console_error, 1 },
|
{ "error", console_error, 1 },
|
||||||
{ "exit", console_exit, 1 },
|
{ "exit", console_exit, 0 },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int assertions;
|
||||||
|
static int failed_assertions;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
console_assert(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
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)) {
|
if (argc < 1 || !get_opt_bool("ecmascript.enable_console_log", NULL)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
assertions++;
|
||||||
bool res = jsval_to_boolean(ctx, args[0]);
|
bool res = jsval_to_boolean(ctx, args[0]);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
@ -83,6 +87,7 @@ console_assert(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
}
|
}
|
||||||
FILE *log = fopen(console_error_filename, "a");
|
FILE *log = fopen(console_error_filename, "a");
|
||||||
|
|
||||||
|
failed_assertions++;
|
||||||
if (!log) {
|
if (!log) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -161,7 +166,8 @@ console_exit(JSContext *ctx, unsigned int argc, JS::Value *vp)
|
|||||||
if (!program.testjs) {
|
if (!program.testjs) {
|
||||||
return true;
|
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;
|
program.terminate = 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user