Skip to content

Commit

Permalink
add math test
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 17, 2024
1 parent b4dcfd5 commit 4ca3bd2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ jobs:
- name: Build
run: zig build -DzigCC --summary all

- name: Test
run: zig build test
20 changes: 18 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ pub fn build(b: *Build) !void {
b.getInstallStep().dependOn(&ldc.step);
}
buildShaders(b);

// build tests
const math_test = try ldcBuildStep(b, .{
.name = "test-math",
.kind = .@"test",
.target = b.host,
.artifact = sokol,
.sources = &.{b.fmt("{s}/src/handmade/math.d", .{rootPath()})},
.dflags = &.{},
});
b.default_step.dependOn(&math_test.step);
}

// Use LDC2 (https://github.com/ldc-developers/ldc) to compile the D examples
Expand Down Expand Up @@ -454,8 +465,13 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep {
const example_run = b.addSystemCommand(&.{b.pathJoin(&.{ b.install_path, "bin", options.name })});
example_run.step.dependOn(&ldc_exec.step);

const run = b.step(b.fmt("run-{s}", .{options.name}), b.fmt("Run {s} example", .{options.name}));
run.dependOn(&example_run.step);
if (options.kind != .@"test") {
const run = b.step(b.fmt("run-{s}", .{options.name}), b.fmt("Run {s} example", .{options.name}));
run.dependOn(&example_run.step);
} else {
const tests = b.step("test", "Run all tests");
tests.dependOn(&example_run.step);
}

return ldc_exec;
}
Expand Down
6 changes: 3 additions & 3 deletions src/handmade/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ float radians(float deg)
return deg * (PI / 180.0);
}

@safe pure unittest
@safe unittest
{
import std.math : isClose;
// Vec3.zero test
Expand All @@ -224,7 +224,7 @@ float radians(float deg)

}

@safe pure unittest
@safe unittest
{
import std.math : isClose;
// Vec3.new test
Expand All @@ -237,7 +237,7 @@ float radians(float deg)

}

@safe pure unittest
@safe unittest
{
import std.math : isClose;
// Mat4.identity test
Expand Down

0 comments on commit 4ca3bd2

Please sign in to comment.