Files
bun.sh/src/unit_test.zig
Don Isaac dff1f555b4 test: get zig build test working (#18207)
### What does this PR do?
Lets us write and run unit tests directly in Zig.

Running Zig unit tests in CI is blocked by https://github.com/ziglang/zig/issues/23281. We can un-comment relevant code once this is fixed.

#### Workflow
> I'll finish writing this up later, but some initial points are below.
> Tl;Dr: `bun build:test`

Test binaries can be made for any kind of build. They are called `<bun>-test` and live next to their corresponding `bun` bin. For example, debug tests compile to `build/debug/bun-debug-test`.

Test binaries re-use most cmake/zig build steps from normal bun binaries, so building one after a normal bun build is pretty fast.

### How did you verify your code works?
I tested that my tests run tests.
2025-04-08 15:31:53 -07:00

17 lines
420 B
Zig

const std = @import("std");
const bun = @import("root").bun;
const t = std.testing;
test {
_ = @import("shell/braces.zig");
_ = @import("bun.js/node/assert/myers_diff.zig");
}
test "basic string usage" {
var s = bun.String.createUTF8("hi");
defer s.deref();
try t.expect(s.tag != .Dead and s.tag != .Empty);
try t.expectEqual(s.length(), 2);
try t.expectEqualStrings(s.asUTF8().?, "hi");
}