moved functions code to separate files
This commit is contained in:
47
tests/main.c
47
tests/main.c
@@ -31,25 +31,25 @@ void print_value(const TomlValue* value)
|
||||
default:
|
||||
assert(false && "invalid type");
|
||||
break;
|
||||
case TOML_TABLE:
|
||||
case TLIBTOML_TABLE:
|
||||
print_table(value->value.table);
|
||||
break;
|
||||
case TOML_ARRAY:
|
||||
case TLIBTOML_ARRAY:
|
||||
print_array(value->value.array);
|
||||
break;
|
||||
case TOML_STRING:
|
||||
case TLIBTOML_STRING:
|
||||
printf("\"%s\"", value->value.s.data);
|
||||
break;
|
||||
case TOML_INTEGER:
|
||||
case TLIBTOML_INTEGER:
|
||||
printf("%" PRId64, value->value.i);
|
||||
break;
|
||||
case TOML_FLOAT:
|
||||
case TLIBTOML_FLOAT:
|
||||
printf("%f", value->value.f);
|
||||
break;
|
||||
case TOML_DATETIME:
|
||||
case TLIBTOML_DATETIME:
|
||||
printf("(datetime)");
|
||||
break;
|
||||
case TOML_BOOLEAN:
|
||||
case TLIBTOML_BOOLEAN:
|
||||
printf("%s", value->value.b ? "true" : "false");
|
||||
break;
|
||||
}
|
||||
@@ -78,31 +78,24 @@ void print_table(const TomlTable* table)
|
||||
printf("}");
|
||||
}
|
||||
|
||||
i32 test_run(cstr filename)
|
||||
Result(void) test_run(cstr filename)
|
||||
{
|
||||
TomlTable* table = NULL;
|
||||
i32 rc = 0;
|
||||
|
||||
table = toml_load_filename(filename);
|
||||
if (table == NULL)
|
||||
goto cleanup;
|
||||
|
||||
Deferral(4);
|
||||
try(TomlTable* table, p, toml_load_filename(filename));
|
||||
Defer(TomlTable_free(table));
|
||||
print_table(table);
|
||||
printf("\n");
|
||||
|
||||
cleanup:
|
||||
toml_table_free(table);
|
||||
|
||||
if (toml_err()->code != TOML_OK) {
|
||||
fprintf(stderr, "%s\n", toml_err()->message);
|
||||
rc = (i32)toml_err()->code;
|
||||
}
|
||||
toml_err_clear();
|
||||
return rc;
|
||||
;
|
||||
}
|
||||
|
||||
i32 main(void)
|
||||
{
|
||||
Deferral(32);
|
||||
try_fatal_void(tlibc_init());
|
||||
Defer(tlibc_deinit());
|
||||
|
||||
static cstr const filenames[] = {
|
||||
/* should parse */
|
||||
PROJECT_SOURCE_DIR "/tests/key-values.toml",
|
||||
@@ -123,12 +116,14 @@ i32 main(void)
|
||||
i32 num_failed = 0;
|
||||
|
||||
for (i32 i = 0; i < total_tests; i++) {
|
||||
i32 rc = test_run(filenames[i]);
|
||||
if (rc == 0) {
|
||||
ResultVar(void) r = test_run(filenames[i]);
|
||||
if (!r.error) {
|
||||
printf("test %d success\n", i);
|
||||
num_passed++;
|
||||
} else {
|
||||
printf("test %d returned %d\n", i, rc);
|
||||
str err_str = Error_toStr(r.error);
|
||||
printf("%s\ntest %d failed\n", err_str.data, i);
|
||||
str_destroy(err_str);
|
||||
num_failed++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user