Skip to content

Commit 2c4661a

Browse files
committed
Add a new unittest build step
Preserves all existing behavior (i.e. make test and zig build test are not changed in any way). The new 'unittest' only runs unit tests and is fast to build. It takes ~1.7 to build unittest, vs ~11.09 to build test. This is really the main goal, and hopefully any unit test which are (a) fast and (b) don't impact build times will be run here. The test runner is based on: https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b It allow filtering, i.e. `make unittest F="parse query dup"`. 'unittest' does memory leak detection when tests use std.testing.allocator. Fixed a memory leak in url/query which was detected/reported with by the new 'unittest'. In order to avoid having 3 src/test_xyx.zig files, I merged the existing test_runner.zig and run_tests.zig into a single main_tests.zig. (this change is superfluous, but I thought it was cleaner this way. Happy to revert this).
1 parent 0c1a486 commit 2c4661a

File tree

6 files changed

+367
-32
lines changed

6 files changed

+367
-32
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
ZIG := zig
55
BC := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
6+
# option test filter make unittest F="server"
7+
F=
68

79
# OS and ARCH
810
kernel = $(shell uname -ms)
@@ -42,7 +44,7 @@ help:
4244

4345
# $(ZIG) commands
4446
# ------------
45-
.PHONY: build build-dev run run-release shell test bench download-zig wpt
47+
.PHONY: build build-dev run run-release shell test bench download-zig wpt unittest
4648

4749
zig_version = $(shell grep 'recommended_zig_version = "' "vendor/zig-js-runtime/build.zig" | cut -d'"' -f2)
4850

@@ -91,6 +93,9 @@ test:
9193
@$(ZIG) build test -Dengine=v8 || (printf "\e[33mTest ERROR\e[0m\n"; exit 1;)
9294
@printf "\e[33mTest OK\e[0m\n"
9395

96+
unittest:
97+
@TEST_FILTER='${F}' $(ZIG) build unittest -freference-trace --summary all
98+
9499
# Install and build required dependencies commands
95100
# ------------
96101
.PHONY: install-submodule

build.zig

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ pub fn build(b: *std.Build) !void {
9898

9999
// compile
100100
const tests = b.addTest(.{
101-
.root_source_file = b.path("src/run_tests.zig"),
102-
.test_runner = b.path("src/test_runner.zig"),
101+
.root_source_file = b.path("src/main_tests.zig"),
102+
.test_runner = b.path("src/main_tests.zig"),
103103
.target = target,
104104
.optimize = mode,
105105
});
@@ -119,6 +119,27 @@ pub fn build(b: *std.Build) !void {
119119
const test_step = b.step("test", "Run unit tests");
120120
test_step.dependOn(&run_tests.step);
121121

122+
// unittest
123+
// ----
124+
125+
// compile
126+
const unit_tests = b.addTest(.{
127+
.root_source_file = b.path("src/unit_tests.zig"),
128+
.test_runner = b.path("src/unit_tests.zig"),
129+
.target = target,
130+
.optimize = mode,
131+
});
132+
try common(b, unit_tests, options);
133+
134+
const run_unit_tests = b.addRunArtifact(unit_tests);
135+
if (b.args) |args| {
136+
run_unit_tests.addArgs(args);
137+
}
138+
139+
// step
140+
const unit_test_step = b.step("unittest", "Run unit tests");
141+
unit_test_step.dependOn(&run_unit_tests.step);
142+
122143
// wpt
123144
// -----
124145

File renamed without changes.

src/test_runner.zig

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)