Skip to content

Commit

Permalink
test: split integration suite
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Jun 21, 2024
1 parent e224f26 commit 41bf268
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 49 deletions.
53 changes: 4 additions & 49 deletions tests/cli.zig
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
const std = @import("std");
const build_options = @import("build_options");

test "default" {
const exe_path = build_options.exe_path;
const argv = [_][]const u8{ exe_path, "--time=short" };
const proc = try std.process.Child.run(.{
.allocator = std.testing.allocator,
.argv = &argv,
});

defer std.testing.allocator.free(proc.stdout);
defer std.testing.allocator.free(proc.stderr);

const term = proc.term;

try std.testing.expectEqual(term, std.process.Child.Term{ .Exited = 0 });
}

test "columns" {
const exe_path = build_options.exe_path;
const argv = [_][]const u8{ exe_path, "--time=short", "-s=columns" };
const proc = try std.process.Child.run(.{
.allocator = std.testing.allocator,
.argv = &argv,
});

defer std.testing.allocator.free(proc.stdout);
defer std.testing.allocator.free(proc.stderr);

const term = proc.term;

try std.testing.expectEqual(term, std.process.Child.Term{ .Exited = 0 });
}

test "crypto" {
const exe_path = build_options.exe_path;
const argv = [_][]const u8{ exe_path, "--time=short", "-s=crypto" };
const proc = try std.process.Child.run(.{
.allocator = std.testing.allocator,
.argv = &argv,
});

defer std.testing.allocator.free(proc.stdout);
defer std.testing.allocator.free(proc.stderr);

const term = proc.term;

try std.testing.expectEqual(term, std.process.Child.Term{ .Exited = 0 });
comptime {
_ = @import("default.zig");
_ = @import("columns.zig");
_ = @import("crypto.zig");
}
35 changes: 35 additions & 0 deletions tests/columns.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const std = @import("std");

const Process = std.process.Child;
const ArrayList = std.ArrayList;

const build_options = @import("build_options");

test "columns" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();

const argv = [_][]const u8{
build_options.exe_path,
"--time=short",
"-s=columns",
};

var process = Process.init(&argv, allocator);
process.stdout_behavior = .Pipe;
process.stderr_behavior = .Pipe;
var stdout = ArrayList(u8).init(allocator);
var stderr = ArrayList(u8).init(allocator);

defer {
stdout.deinit();
stderr.deinit();
}

try process.spawn();
try process.collectOutput(&stdout, &stderr, 1024);
const term = try process.wait();

try std.testing.expectEqual(term.Exited, 0);
}
35 changes: 35 additions & 0 deletions tests/crypto.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const std = @import("std");

const Process = std.process.Child;
const ArrayList = std.ArrayList;

const build_options = @import("build_options");

test "crypto" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();

const argv = [_][]const u8{
build_options.exe_path,
"--time=short",
"-s=crypto",
};

var process = Process.init(&argv, allocator);
process.stdout_behavior = .Pipe;
process.stderr_behavior = .Pipe;
var stdout = ArrayList(u8).init(allocator);
var stderr = ArrayList(u8).init(allocator);

defer {
stdout.deinit();
stderr.deinit();
}

try process.spawn();
try process.collectOutput(&stdout, &stderr, 1024);
const term = try process.wait();

try std.testing.expectEqual(term.Exited, 0);
}
34 changes: 34 additions & 0 deletions tests/default.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const std = @import("std");

const Process = std.process.Child;
const ArrayList = std.ArrayList;

const build_options = @import("build_options");

test "default" {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();

const argv = [_][]const u8{
build_options.exe_path,
"--time=short",
};

var process = Process.init(&argv, allocator);
process.stdout_behavior = .Pipe;
process.stderr_behavior = .Pipe;
var stdout = ArrayList(u8).init(allocator);
var stderr = ArrayList(u8).init(allocator);

defer {
stdout.deinit();
stderr.deinit();
}

try process.spawn();
try process.collectOutput(&stdout, &stderr, 1024);
const term = try process.wait();

try std.testing.expectEqual(term.Exited, 0);
}

0 comments on commit 41bf268

Please sign in to comment.