-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
250 lines (224 loc) · 8.39 KB
/
build.zig
File metadata and controls
250 lines (224 loc) · 8.39 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Create the main library module
const lib_module = b.addModule("zig_test_framework", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.link_libc = true,
});
// Create the test runner executable
const exe = b.addExecutable(.{
.name = "zig-test",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the test framework");
run_step.dependOn(&run_cmd.step);
// Unit tests for the framework itself
const lib_unit_tests = b.addTest(.{
.root_module = lib_module,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
// Test runner tests
const test_runner_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/test_runner_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_test_runner_tests = b.addRunArtifact(test_runner_tests);
// Assertions tests
const assertions_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/assertions_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_assertions_tests = b.addRunArtifact(assertions_tests);
// Suite tests
const suite_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/suite_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_suite_tests = b.addRunArtifact(suite_tests);
// Matchers tests
const matchers_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/matchers_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_matchers_tests = b.addRunArtifact(matchers_tests);
// Hooks tests (executable, not unit test)
const hooks_tests = b.addExecutable(.{
.name = "hooks_test",
.root_module = b.createModule(.{
.root_source_file = b.path("tests/hooks_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zig_test_framework", .module = lib_module },
},
}),
});
b.installArtifact(hooks_tests);
const run_hooks_tests = b.addRunArtifact(hooks_tests);
const hooks_step = b.step("test-hooks", "Run lifecycle hooks tests");
hooks_step.dependOn(&run_hooks_tests.step);
// Reporter tests
const reporter_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/reporter_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_reporter_tests = b.addRunArtifact(reporter_tests);
// CLI tests
const cli_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/cli_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_cli_tests = b.addRunArtifact(cli_tests);
// Filter tests
const filter_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/filter_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_filter_tests = b.addRunArtifact(filter_tests);
// Mock tests
const mock_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("tests/mock_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const run_mock_tests = b.addRunArtifact(mock_tests);
// Comprehensive mock tests (executable)
const comprehensive_mock_tests = b.addExecutable(.{
.name = "comprehensive_mock_test",
.root_module = b.createModule(.{
.root_source_file = b.path("tests/comprehensive_mock_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zig_test_framework", .module = lib_module },
},
}),
});
b.installArtifact(comprehensive_mock_tests);
const run_comprehensive_mock_tests = b.addRunArtifact(comprehensive_mock_tests);
const comprehensive_mock_step = b.step("test-mocks", "Run comprehensive mock tests");
comprehensive_mock_step.dependOn(&run_comprehensive_mock_tests.step);
// Snapshot usage tests (executable)
const snapshot_usage_tests = b.addExecutable(.{
.name = "snapshot_usage_test",
.root_module = b.createModule(.{
.root_source_file = b.path("tests/snapshot_usage_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zig_test_framework", .module = lib_module },
},
}),
});
b.installArtifact(snapshot_usage_tests);
const run_snapshot_usage_tests = b.addRunArtifact(snapshot_usage_tests);
const snapshot_usage_step = b.step("test-snapshots", "Run snapshot usage tests");
snapshot_usage_step.dependOn(&run_snapshot_usage_tests.step);
// Time mocking tests (executable)
const time_tests = b.addExecutable(.{
.name = "time_test",
.root_module = b.createModule(.{
.root_source_file = b.path("tests/time_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zig_test_framework", .module = lib_module },
},
}),
});
b.installArtifact(time_tests);
const run_time_tests = b.addRunArtifact(time_tests);
const time_step = b.step("test-time", "Run time mocking tests");
time_step.dependOn(&run_time_tests.step);
// Create test step that runs all tests
const test_step = b.step("test", "Run all unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_test_runner_tests.step);
test_step.dependOn(&run_assertions_tests.step);
test_step.dependOn(&run_suite_tests.step);
test_step.dependOn(&run_matchers_tests.step);
// Note: hooks_test is an executable, run with 'zig build test-hooks'
test_step.dependOn(&run_reporter_tests.step);
test_step.dependOn(&run_cli_tests.step);
test_step.dependOn(&run_filter_tests.step);
test_step.dependOn(&run_mock_tests.step);
// Examples
const basic_example = b.addExecutable(.{
.name = "basic_example",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/basic_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zig_test_framework", .module = lib_module },
},
}),
});
const advanced_example = b.addExecutable(.{
.name = "advanced_example",
.root_module = b.createModule(.{
.root_source_file = b.path("examples/advanced_test.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{
.{ .name = "zig_test_framework", .module = lib_module },
},
}),
});
const run_basic_example = b.addRunArtifact(basic_example);
const run_advanced_example = b.addRunArtifact(advanced_example);
const examples_step = b.step("examples", "Run all examples");
examples_step.dependOn(&run_basic_example.step);
examples_step.dependOn(&run_advanced_example.step);
}