| author | |
| committer | |
| log | c3e439f86b0484e4428f38c4d8b07b7b5ae1634b |
| tree | c0829ad00b13224bdc25702ffb92409f2d4fefcb |
| parent | 2d1861381432e1ca631ba1ce4f9460d29e265ccc |
2 files changed, 31 insertions(+), 0 deletions(-)
build.zig+12| ... | @@ -20,4 +20,16 @@ pub fn build(b: *std.Build) void { | ... | @@ -20,4 +20,16 @@ pub fn build(b: *std.Build) void { |
| 20 | 20 | ||
| 21 | const run_step = b.step("run", "Run the app"); | 21 | const run_step = b.step("run", "Run the app"); |
| 22 | run_step.dependOn(&run_cmd.step); | 22 | run_step.dependOn(&run_cmd.step); |
| 23 | |||
| 24 | const tests = b.addTest(.{ | ||
| 25 | .root_source_file = b.path("src/test.zig"), | ||
| 26 | .target = target, | ||
| 27 | .optimize = mode, | ||
| 28 | }); | ||
| 29 | |||
| 30 | const run_test = b.addRunArtifact(tests); | ||
| 31 | run_test.step.dependOn(&tests.step); | ||
| 32 | |||
| 33 | const test_step = b.step("test", "Run the test suite"); | ||
| 34 | test_step.dependOn(&run_test.step); | ||
| 23 | } | 35 | } |
src/test.zig created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const ansi = @import("./lib.zig"); | ||
| 3 | |||
| 4 | fn expectFmt(comptime actual: []const u8, expected: []const u8) !void { | ||
| 5 | return std.testing.expectEqualSlices(u8, expected, actual); | ||
| 6 | } | ||
| 7 | |||
| 8 | test { | ||
| 9 | try expectFmt( | ||
| 10 | ansi.color.Fg(.Blue, "All your codebase"), | ||
| 11 | &(.{ 27, '[', '3', '4', 'm' } ++ "All your codebase".* ++ .{ 27, '[', '3', '9', 'm' }), | ||
| 12 | ); | ||
| 13 | } | ||
| 14 | test { | ||
| 15 | try expectFmt( | ||
| 16 | ansi.color.Bg(.Cyan, "All your codebase"), | ||
| 17 | &(.{ 27, '[', '4', '6', 'm' } ++ "All your codebase".* ++ .{ 27, '[', '4', '9', 'm' }), | ||
| 18 | ); | ||
| 19 | } | ||