-
Notifications
You must be signed in to change notification settings - Fork 24
/
nob.c
69 lines (59 loc) · 2.03 KB
/
nob.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "nob.h"
#include "shared.h"
const char *test_names[] = {
"minimal_log_level",
"nob_sv_end_with",
"set_get_current_dir",
"cmd_redirect",
#ifdef _WIN32
"win32_error",
#endif //_WIN32
};
#define test_names_count ARRAY_LEN(test_names)
bool build_and_run_test(Cmd *cmd, const char *test_name)
{
const char *bin_path = temp_sprintf("%s%s", BUILD_FOLDER TESTS_FOLDER, test_name);
const char *src_path = temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
cmd_append(cmd, "cc", "-Wall", "-Wextra", "-Wswitch-enum", "-I.", "-o", bin_path, src_path);
if (!cmd_run_sync_and_reset(cmd)) return false;
cmd_append(cmd, bin_path);
if (!cmd_run_sync_and_reset(cmd)) return false;
nob_log(INFO, "--- %s finished ---", bin_path);
return true;
}
int main(int argc, char **argv)
{
NOB_GO_REBUILD_URSELF(argc, argv);
Cmd cmd = {0};
const char *program_name = shift(argv, argc);
const char *command_name = "test";
if (argc > 0) command_name = shift(argv, argc);
if (!mkdir_if_not_exists(BUILD_FOLDER)) return 1;
if (!mkdir_if_not_exists(BUILD_FOLDER TESTS_FOLDER)) return 1;
if (!mkdir_if_not_exists(BUILD_FOLDER TOOLS_FOLDER)) return 1;
if (strcmp(command_name, "test") == 0) {
if (argc <= 0) {
for (size_t i = 0; i < test_names_count; ++i) {
if (!build_and_run_test(&cmd, test_names[i])) return 1;
}
return 0;
}
while (argc > 0) {
const char *test_name = shift(argv, argc);
if (!build_and_run_test(&cmd, test_name)) return 1;
}
return 0;
}
if (strcmp(command_name, "list") == 0) {
nob_log(INFO, "Tests:");
for (size_t i = 0; i < test_names_count; ++i) {
nob_log(INFO, " %s", test_names[i]);
}
nob_log(INFO, "Use %s test <names...> to run individual tests", program_name);
return 0;
}
nob_log(ERROR, "Unknown command %s", command_name);
return 1;
}