Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
  • Loading branch information
francisbouvier committed Nov 20, 2024
1 parent 6324fdb commit beec41a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
1 change: 0 additions & 1 deletion .github/workflows/zig-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ jobs:
fetch-depth: 0

- run: zig build test
- run: zig build run
6 changes: 5 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ pub fn build(b: *std.Build) void {
run_step.dependOn(&run_cmd.step);

const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.root_source_file = b.path("src/tests.zig"),
.test_runner = b.path("src/test_runner.zig"),
.target = target,
.optimize = optimize,
});

const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
if (b.args) |args| {
run_exe_unit_tests.addArgs(args);
}

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
Expand Down
2 changes: 2 additions & 0 deletions src/lib.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const Wrapper = @import("io.zig").Wrapper;
pub const Client = @import("std/http/Client.zig");
18 changes: 18 additions & 0 deletions src/test_runner.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const std = @import("std");
const builtin = @import("builtin");

pub const Blocking = @import("Blocking.zig").Blocking;
pub const IO = @import("io.zig").Wrapper(Blocking);

pub const tests = @import("tests.zig");

pub fn main() !void {
std.testing.refAllDecls(tests);
for (builtin.test_functions) |test_fn| {
test_fn.func() catch |err| {
if (err == error.SkipZigTest) continue;
return err;
};
std.debug.print("{s}\tOK\n", .{test_fn.name});
}
}
23 changes: 5 additions & 18 deletions src/main.zig → src/tests.zig
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const std = @import("std");

const Ctx = Client.Ctx;
const stack = @import("stack.zig");
pub const Client = @import("std/http/Client.zig");
const Ctx = Client.Ctx;
pub const Wrapper = @import("io.zig").Wrapper;
const Blocking = @import("blocking.zig").Blocking;
pub const IO = Wrapper(Blocking);

const root = @import("root");
const IO = @import("root").IO;
const Blocking = @import("root").Blocking;

fn onRequestWait(ctx: *Ctx, res: anyerror!void) !void {
res catch |e| {
Expand Down Expand Up @@ -39,12 +37,7 @@ pub fn onRequestConnect(ctx: *Ctx, res: anyerror!void) anyerror!void {
return ctx.req.async_send(ctx, onRequestSend);
}

pub fn main() !void {
return run();
}

pub fn run() !void {

test "example.com" {
// const url = "http://127.0.0.1:8080";
const url = "https://www.example.com";

Expand Down Expand Up @@ -79,11 +72,5 @@ pub fn run() !void {
onRequestConnect,
);

std.log.debug("Final error: {any}", .{ctx.err});
}

test {
_ = stack.Stack(fn () void);
std.testing.refAllDecls(@This());
try run();
try std.testing.expect(ctx.err == null);
}

0 comments on commit beec41a

Please sign in to comment.