Integrate unit tests in ci script
This commit is contained in:
@@ -50,7 +50,10 @@ void handle_cli_arguments(int argc, char **argv)
|
||||
fprintf(stdout, "tint2 version %s\n", VERSION_STRING);
|
||||
exit(0);
|
||||
} else if (strcmp(argv[i], "--test") == 0) {
|
||||
run_all_tests();
|
||||
run_all_tests(false);
|
||||
exit(0);
|
||||
} else if (strcmp(argv[i], "--test-verbose") == 0) {
|
||||
run_all_tests(true);
|
||||
exit(0);
|
||||
} else if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
|
||||
@@ -123,7 +123,7 @@ static Status run_test(TestListItem *item)
|
||||
return run_test_parent(item, pid);
|
||||
}
|
||||
|
||||
void run_all_tests()
|
||||
void run_all_tests(bool verbose)
|
||||
{
|
||||
fprintf(stdout, BLUE "tint2: Running %d tests..." RESET "\n", g_list_length(all_tests));
|
||||
size_t count = 0, succeeded = 0, failed = 0;
|
||||
@@ -138,6 +138,19 @@ void run_all_tests()
|
||||
} else {
|
||||
fprintf(stdout, RED "failed" RESET "\n");
|
||||
failed++;
|
||||
if (verbose) {
|
||||
char *log_name = test_log_name_from_test_name(item->name);
|
||||
FILE *log = fopen(log_name, "rt");
|
||||
if (log) {
|
||||
char buffer[4096];
|
||||
size_t num_read;
|
||||
while ((num_read = fread(buffer, 1, sizeof(buffer), log)) > 0) {
|
||||
fwrite(buffer, 1, num_read, stdout);
|
||||
}
|
||||
fclose(log);
|
||||
}
|
||||
free(log_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failed == 0)
|
||||
|
||||
@@ -16,7 +16,7 @@ void register_test_(Test *test, const char *name);
|
||||
} \
|
||||
void test_##name(Status *test_result_)
|
||||
|
||||
void run_all_tests();
|
||||
void run_all_tests(bool verbose);
|
||||
|
||||
#define FAIL_TEST_ \
|
||||
*test_result_ = FAILURE; \
|
||||
|
||||
@@ -1665,7 +1665,7 @@ TEST(get_next_timeout_simple_multi) {
|
||||
|
||||
set_mock_time_ms(origin + 0);
|
||||
timeout *t1 = add_timeout(100, 0, trigger_callback, &triggered, NULL);
|
||||
timeout *t2 = add_timeout(200, 50, trigger_callback, &triggered, NULL);
|
||||
add_timeout(200, 50, trigger_callback, &triggered, NULL);
|
||||
handle_expired_timers();
|
||||
ASSERT_EQUAL(triggered, 0);
|
||||
ASSERT_EQUAL(timeval_to_ms(get_next_timeout()), 100);
|
||||
|
||||
Reference in New Issue
Block a user