Skip to content

Commit

Permalink
fix(test): add back main test (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski authored Oct 8, 2024
1 parent e18d8c1 commit 11d7001
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn build(b: *std.Build) void {

// Add tests.
const test_step = b.step("test", "Run tests");
for ([_][]const u8{ "file", "gen", "wav" }) |module| {
for ([_][]const u8{ "main", "file", "gen", "wav" }) |module| {
const test_name = b.fmt("{s}-tests", .{module});
const test_module = b.fmt("src/{s}.zig", .{module});
var exe_tests = b.addTest(.{
Expand Down
20 changes: 20 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,23 @@ pub fn main() !void {
try stderr.print("Error occurred: {}\n", .{err});
};
}

test "run" {
const allocator = std.testing.allocator;
var buffer = std.ArrayList(u8).init(allocator);
const output = buffer.writer();
run(allocator, output) catch |err| {
std.debug.print("Error occurred: {s}\n", .{@errorName(err)});
return;
};
const result = buffer.toOwnedSlice() catch |err| {
std.debug.print("Error occurred: {s}\n", .{@errorName(err)});
return;
};
defer allocator.free(result);
try std.testing.expectEqualStrings(
\\Reading 96 bytes from /dev/urandom
\\Saving to output.wav
\\
, result);
}

0 comments on commit 11d7001

Please sign in to comment.