Skip to content

Commit 918a5fc

Browse files
authored
Merge pull request #209 from tsoding/v3.2.0
Release 3.2.0
2 parents e2c9a46 + ed3f4f8 commit 918a5fc

File tree

73 files changed

+730
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+730
-336
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
nob
22
nob.old
33
nob.exe
4-
build/
4+
nob.exe.old
5+
nob.obj
6+
build/

how_to/nob.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Makes sure the examples are buildable. Used usually on CI.
22
#include "../shared.h"
3-
#define NOB_IMPLEMENTATION
4-
#define NOB_EXPERIMENTAL_DELETE_OLD
5-
#define NOB_WARN_DEPRECATED
6-
#include "../nob.h"
73

84
const char *examples[] = {
95
"001_basic_usage",

nob.c

Lines changed: 80 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
#include "shared.h"
2-
#define NOBDEF static inline
3-
#define NOB_IMPLEMENTATION
4-
#define NOB_EXPERIMENTAL_DELETE_OLD
5-
#define NOB_WARN_DEPRECATED
6-
#include "nob.h"
7-
#undef rename // Testing for backward compatibility after v1.20.6
82

93
const char *test_names[] = {
10-
"minimal_log_level",
114
"nob_sv_end_with",
12-
"set_get_current_dir",
135
"cmd_redirect",
146
"cmd_args_passing",
15-
#ifdef _WIN32
16-
"win32_error",
17-
#endif //_WIN32
187
"read_entire_dir",
198
"da_resize",
209
"da_last",
@@ -27,6 +16,7 @@ const char *test_names[] = {
2716
"temp_running_executable_path",
2817
"no_echo",
2918
"cmd_run_dont_reset",
19+
"chain",
3020
};
3121
#define test_names_count ARRAY_LEN(test_names)
3222

@@ -41,58 +31,74 @@ bool delete_directory_recursively(const char *dir_path)
4131
return walk_dir(dir_path, delete_walk_entry, .post_order = true);
4232
}
4333

44-
bool build_and_run_test(Cmd *cmd, const char *test_name, bool record)
34+
bool build_and_run_test(const char *test_name, bool record)
4535
{
46-
size_t mark = temp_save();
36+
bool result = true;
37+
Cmd cmd = {0};
38+
String_Builder src = {0};
39+
String_Builder dst = {0};
40+
String_View src_sv = {0};
41+
String_View dst_sv = {0};
42+
#ifdef _WIN32
43+
const char *src_stdout_path = temp_sprintf("%s%s.win32.stdout.txt", BUILD_FOLDER TESTS_FOLDER, test_name);
44+
const char *dst_stdout_path = temp_sprintf("%s%s.win32.stdout.txt", TESTS_FOLDER, test_name);
45+
const char *test_stdout_path = temp_sprintf("../%s.win32.stdout.txt", test_name);
46+
#else
47+
const char *src_stdout_path = temp_sprintf("%s%s.stdout.txt", BUILD_FOLDER TESTS_FOLDER, test_name);
48+
const char *dst_stdout_path = temp_sprintf("%s%s.stdout.txt", TESTS_FOLDER, test_name);
49+
const char *test_stdout_path = temp_sprintf("../%s.stdout.txt", test_name);
50+
#endif // _WIN32
51+
const char *bin_path = temp_sprintf("%s%s", BUILD_FOLDER TESTS_FOLDER, test_name);
52+
const char *src_path = temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
53+
const char *test_cwd_path = temp_sprintf("%s%s%s.cwd", BUILD_FOLDER, TESTS_FOLDER, test_name);
4754

48-
const char *bin_path = temp_sprintf("%s%s", BUILD_FOLDER TESTS_FOLDER, test_name);
49-
const char *src_path = temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
50-
nob_cc(cmd);
51-
nob_cc_flags(cmd);
52-
nob_cc_output(cmd, bin_path);
53-
nob_cc_inputs(cmd, src_path);
54-
if (!cmd_run(cmd)) return false;
55+
nob_cc(&cmd);
56+
nob_cc_flags(&cmd);
57+
nob_cc_output(&cmd, bin_path);
58+
nob_cc_inputs(&cmd, src_path);
59+
if (!cmd_run(&cmd)) return_defer(false);
5560

56-
const char *test_cwd_path = temp_sprintf("%s%s%s.cwd", BUILD_FOLDER, TESTS_FOLDER, test_name);
5761
if (file_exists(test_cwd_path)) {
58-
if (!delete_directory_recursively(test_cwd_path)) return false;
62+
if (!delete_directory_recursively(test_cwd_path)) return_defer(false);
5963
}
60-
if (!mkdir_if_not_exists(test_cwd_path)) return false;
61-
if (!set_current_dir(test_cwd_path)) return false;
62-
cmd_append(cmd, temp_sprintf("../%s", test_name));
63-
const char *test_stdout_path = temp_sprintf("../%s.stdout.txt", test_name);
64-
const char *test_stderr_path = temp_sprintf("../%s.stderr.txt", test_name);
65-
if (!cmd_run(cmd, .stdout_path = test_stdout_path, .stderr_path = test_stderr_path)) return false;
66-
if (!set_current_dir("../../../")) return false;
64+
if (!mkdir_if_not_exists(test_cwd_path)) return_defer(false);
65+
if (!set_current_dir(test_cwd_path)) return_defer(false);
66+
#ifdef _WIN32
67+
cmd_append(&cmd, temp_sprintf("../%s.exe", test_name));
68+
#else
69+
cmd_append(&cmd, temp_sprintf("../%s", test_name));
70+
#endif // _WIN32
71+
if (!cmd_run(&cmd, .stdout_path = test_stdout_path)) return_defer(false);
72+
if (!set_current_dir("../../../")) return_defer(false);
6773

6874
// TODO: implement record/replay testing for windows
69-
#ifndef _WIN32
70-
const char *src_stdout_path = temp_sprintf("%s%s.stdout.txt", BUILD_FOLDER TESTS_FOLDER, test_name);
71-
const char *src_stderr_path = temp_sprintf("%s%s.stderr.txt", BUILD_FOLDER TESTS_FOLDER, test_name);
72-
const char *dst_stdout_path = temp_sprintf("%s%s.stdout.txt", TESTS_FOLDER, test_name);
73-
const char *dst_stderr_path = temp_sprintf("%s%s.stderr.txt", TESTS_FOLDER, test_name);
7475
if (record) {
75-
if (!copy_file(src_stdout_path, dst_stdout_path)) return 1;
76-
if (!copy_file(src_stderr_path, dst_stderr_path)) return 1;
76+
if (!copy_file(src_stdout_path, dst_stdout_path)) return_defer(false);
7777
} else {
78-
cmd_append(cmd, "diff");
79-
cmd_append(cmd, "-u");
80-
cmd_append(cmd, dst_stdout_path);
81-
cmd_append(cmd, src_stdout_path);
82-
if (!cmd_run(cmd)) return false;
83-
84-
cmd_append(cmd, "diff");
85-
cmd_append(cmd, "-u");
86-
cmd_append(cmd, dst_stderr_path);
87-
cmd_append(cmd, src_stderr_path);
88-
if (!cmd_run(cmd)) return false;
78+
// TODO: it would be cool to have a portable diff utility in here.
79+
if (!read_entire_file(src_stdout_path, &src)) return_defer(false);
80+
if (!read_entire_file(dst_stdout_path, &dst)) return_defer(false);
81+
82+
src_sv = sb_to_sv(src);
83+
dst_sv = sb_to_sv(dst);
84+
85+
if (!sv_eq(src_sv, dst_sv)) {
86+
nob_log(ERROR, "UNEXPECTED OUTPUT!");
87+
nob_log(ERROR, "EXPECTED:");
88+
fprintf(stderr, SV_Fmt, SV_Arg(dst_sv));
89+
nob_log(ERROR, "ACTUAL:");
90+
fprintf(stderr, SV_Fmt, SV_Arg(src_sv));
91+
return_defer(false);
92+
}
8993
}
90-
#endif // _WIN32
9194

9295
nob_log(INFO, "--- %s finished ---", bin_path);
9396

94-
temp_rewind(mark);
95-
return true;
97+
defer:
98+
free(dst.items);
99+
free(src.items);
100+
free(cmd.items);
101+
return result;
96102
}
97103

98104
typedef struct {
@@ -157,8 +163,6 @@ void print_available_commands(Commands commands)
157163

158164
int main(int argc, char **argv)
159165
{
160-
set_log_handler(cancer_log_handler);
161-
162166
GO_REBUILD_URSELF_PLUS(argc, argv, "nob.h", "shared.h");
163167

164168
Cmd cmd = {0};
@@ -175,17 +179,22 @@ int main(int argc, char **argv)
175179
if (!mkdir_if_not_exists(BUILD_FOLDER)) return 1;
176180
if (!mkdir_if_not_exists(BUILD_FOLDER TESTS_FOLDER)) return 1;
177181

182+
size_t failed_count = 0;
178183
if (argc <= 0) {
179184
for (size_t i = 0; i < test_names_count; ++i) {
180-
if (!build_and_run_test(&cmd, test_names[i], false)) return 1;
185+
size_t mark = temp_save();
186+
if (!build_and_run_test(test_names[i], false)) failed_count += 1;
187+
temp_rewind(mark);
188+
}
189+
} else {
190+
while (argc > 0) {
191+
size_t mark = temp_save();
192+
const char *test_name = shift(argv, argc);
193+
if (!build_and_run_test(test_name, false)) failed_count += 1;
194+
temp_rewind(mark);
181195
}
182-
return 0;
183-
}
184-
185-
while (argc > 0) {
186-
const char *test_name = shift(argv, argc);
187-
if (!build_and_run_test(&cmd, test_name, false)) return 1;
188196
}
197+
if (failed_count > 0) return 1;
189198

190199
return 0;
191200
}
@@ -194,17 +203,23 @@ int main(int argc, char **argv)
194203
if (!mkdir_if_not_exists(BUILD_FOLDER)) return 1;
195204
if (!mkdir_if_not_exists(BUILD_FOLDER TESTS_FOLDER)) return 1;
196205

206+
size_t failed_count = 0;
197207
if (argc <= 0) {
198208
for (size_t i = 0; i < test_names_count; ++i) {
199-
if (!build_and_run_test(&cmd, test_names[i], true)) return 1;
209+
size_t mark = temp_save();
210+
if (!build_and_run_test(test_names[i], true)) failed_count += 1;
211+
temp_rewind(mark);
212+
}
213+
} else {
214+
while (argc > 0) {
215+
size_t mark = temp_save();
216+
const char *test_name = shift(argv, argc);
217+
if (!build_and_run_test(test_name, true)) failed_count += 1;
218+
temp_rewind(mark);
200219
}
201-
return 0;
202220
}
221+
if (failed_count > 0) return 1;
203222

204-
while (argc > 0) {
205-
const char *test_name = shift(argv, argc);
206-
if (!build_and_run_test(&cmd, test_name, true)) return 1;
207-
}
208223
return 0;
209224
}
210225

0 commit comments

Comments
 (0)