Validate exit codes more thoroughly. C'mon, Cory.

This commit is contained in:
Cory McWilliams 2024-04-02 20:32:47 -04:00
parent 9f3171e3f1
commit e50144bd34
3 changed files with 22 additions and 5 deletions

View File

@ -516,7 +516,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
if (args.count == 1) if (args.count == 1)
{ {
_tf_run_task(&args, 0); result = _tf_run_task(&args, 0);
} }
if (args.count > 1) if (args.count > 1)
{ {

View File

@ -113,8 +113,8 @@ typedef struct _tf_task_t
bool _trusted; bool _trusted;
bool _one_proc; bool _one_proc;
bool _killed; bool _killed;
int32_t _exitCode;
char _scriptName[256]; char _scriptName[256];
int _global_exception_count;
JSRuntime* _runtime; JSRuntime* _runtime;
JSContext* _context; JSContext* _context;
@ -421,11 +421,11 @@ int tf_task_execute(tf_task_t* task, const char* fileName)
if (source) if (source)
{ {
JSValue result = JS_Eval(task->_context, source, strlen(source), fileName, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_ASYNC); JSValue result = JS_Eval(task->_context, source, strlen(source), fileName, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_ASYNC);
if (tf_util_report_error(task->_context, result)) if (tf_util_report_error(task->_context, result) || task->_global_exception_count)
{ {
tf_printf("Reported an error.\n"); tf_printf("Reported an error.\n");
} }
if (!JS_IsError(task->_context, result) && !JS_IsException(result)) else
{ {
executed = true; executed = true;
} }
@ -1457,6 +1457,8 @@ static void _tf_task_promise_rejection_tracker(JSContext* context, JSValueConst
if (!is_handled) if (!is_handled)
{ {
tf_util_report_error(context, reason); tf_util_report_error(context, reason);
tf_task_t* task = tf_task_get(context);
task->_global_exception_count++;
} }
} }

View File

@ -58,6 +58,20 @@ static void _test_nop(const tf_test_options_t* options)
assert(WEXITSTATUS(result) == 0); assert(WEXITSTATUS(result) == 0);
} }
static void _test_exception(const tf_test_options_t* options)
{
_write_file("out/test.js", "throw new Error('oops');");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
tf_printf("%s\n", command);
int result = system(command);
tf_printf("result = %d\n", result);
(void)result;
assert(WIFEXITED(result));
assert(WEXITSTATUS(result) != 0);
}
#if !defined(__HAIKU__) #if !defined(__HAIKU__)
static void _test_sandbox(const tf_test_options_t* options) static void _test_sandbox(const tf_test_options_t* options)
{ {
@ -372,7 +386,7 @@ static void _test_import(const tf_test_options_t* options)
result = system(command); result = system(command);
tf_printf("returned %d\n", WEXITSTATUS(result)); tf_printf("returned %d\n", WEXITSTATUS(result));
assert(WIFEXITED(result)); assert(WIFEXITED(result));
assert(WEXITSTATUS(result) == 0); assert(WEXITSTATUS(result) != 0);
unlink("out/test.js"); unlink("out/test.js");
unlink("out/required.js"); unlink("out/required.js");
@ -893,6 +907,7 @@ void tf_tests(const tf_test_options_t* options)
_tf_test_run(options, "ssb_id", tf_ssb_test_id_conversion, false); _tf_test_run(options, "ssb_id", tf_ssb_test_id_conversion, false);
_tf_test_run(options, "ssb_following", tf_ssb_test_following, false); _tf_test_run(options, "ssb_following", tf_ssb_test_following, false);
_tf_test_run(options, "nop", _test_nop, false); _tf_test_run(options, "nop", _test_nop, false);
_tf_test_run(options, "exception", _test_exception, false);
#if !defined(__HAIKU__) #if !defined(__HAIKU__)
_tf_test_run(options, "sandbox", _test_sandbox, false); _tf_test_run(options, "sandbox", _test_sandbox, false);
#endif #endif