diff --git a/src/base/base_test.c b/src/base/base_test.c index 149352fc..f55c9d73 100644 --- a/src/base/base_test.c +++ b/src/base/base_test.c @@ -32,16 +32,23 @@ test_exemplar_path(Arena *arena, TestCtx *ctx, String8 name) return path; } +internal String8 +test_layer_from_file_path(String8 file_path) +{ + U64 src_min = str8_find_needle(file_path, 0, s("src/"), StringMatchFlag_SlashInsensitive); + if (src_min == file_path.size) { return str8_zero(); } + U64 src_max = src_min + str8_lit("src/").size; + U64 layer_slash_max = str8_find_needle(file_path, src_max, s("/"), StringMatchFlag_SlashInsensitive); + if (layer_slash_max == file_path.size) { return str8_zero(); } + return str8_substr(file_path, r1u64(src_max, layer_slash_max)); +} + internal void base_register_test(char *func_name_cstr, TestFunctionType *fn, char *file_path_cstr, int line, int skip) { - String8 file_path = str8_cstring(file_path_cstr); - U64 src_min = str8_find_needle(file_path, 0, s("src/"), StringMatchFlag_SlashInsensitive); - U64 src_max = src_min + str8_lit("src/").size; - U64 layer_slash_max = str8_find_needle(file_path, src_max, s("/"), StringMatchFlag_SlashInsensitive); - + String8 file_path = str8_cstring(file_path_cstr); TestInfo *t = &test_infos[test_infos_count++]; - t->layer = str8_substr(file_path, r1u64(src_max, layer_slash_max)); + t->layer = test_layer_from_file_path(file_path); t->label = str8_cstring(func_name_cstr); t->decl_line = line; t->skip = skip; diff --git a/src/base/base_test.h b/src/base/base_test.h index c7a225ee..0bfc9d60 100644 --- a/src/base/base_test.h +++ b/src/base/base_test.h @@ -30,6 +30,7 @@ struct TestCtx String8 exemplars_path; String8 artifacts_path; String8 input_data_path; + String8 user_data; TestResult *result_out; String8List *test_out; }; @@ -46,6 +47,7 @@ struct TestInfo S64 decl_line; B32 skip; TestFunctionType *test_fn; + String8 user_data; }; #if BUILD_TESTS @@ -58,6 +60,7 @@ internal String8 test_build_exe_path(Arena *arena, String8 name); internal String8 test_input_path(Arena *arena, TestCtx *ctx, String8 name); internal String8 test_input_exe_path(Arena *arena, TestCtx *ctx, String8 name); internal String8 test_exemplar_path(Arena *arena, TestCtx *ctx, String8 name); +internal String8 test_layer_from_file_path(String8 file_path); internal void base_register_test(char *func_name, TestFunctionType *fn, char *file_path, int line, int skip); #define AddTest(name, file_path, line, skip_, ...) \