Skip to content

Commit 846fa18

Browse files
committed
tests: catch exceptions
Running tests with beam didn't catch exceptions which resulted in command failing with non-informational error. Now, we catch all exceptions, print them, and exit with error code. Signed-off-by: Jakub Gonet <jakub.gonet@swmansion.com>
1 parent d5f6c4e commit 846fa18

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/test.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,18 +634,23 @@ static int test_atom(struct Test *test)
634634
static int test_beam(struct Test *test)
635635
{
636636
char command[512];
637-
snprintf(command, sizeof(command),
637+
size_t written = snprintf(command, sizeof(command),
638638
"erl -pa . -eval '"
639-
"erlang:process_flag(trap_exit, false), " /* init(3) traps exists */
640-
"R = %s:start(), "
641-
"S = if"
642-
" R =:= %i -> 0;"
643-
" true -> io:format(\"Expected ~B, got ~p\n\", [%i, R]) "
644-
"end, "
639+
"erlang:process_flag(trap_exit, false), \n" /* init(3) traps exits */
640+
"S = try %s:start() of\n"
641+
" R when R =:= %i -> 0;\n"
642+
" R -> io:format(\"Expected ~B, got ~p\\n\", [%i, R]), 1\n"
643+
"catch\n"
644+
" _C:E:ST -> io:format(\"Raised ~p, stacktrace:\\n~p\\n\", [E, ST]), 1\n"
645+
"end,\n"
645646
"erlang:halt(S).' -noshell",
646647
test->test_module,
647648
test->expected_value,
648649
test->expected_value);
650+
if (written >= sizeof(command) - 1) {
651+
fprintf(stderr, "Exceeded buffer size for module %s\n", test->test_module);
652+
return 1;
653+
}
649654
return system(command);
650655
}
651656

0 commit comments

Comments
 (0)