zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 8d3e7aa5e0a7b3956a5ba8cf2c85d756ab581465 (tree)
parent df544cace97b57b318dba439d4e67a3953388477
Author: iddev5 <ayushbardhan5@gmail.com>
Date:   Mon,  4 Apr 2022 18:33:47 +0530

std.testing: add function zigBuild for running zig build runner commands

Diffstat:
Mlib/std/testing.zig | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/lib/std/testing.zig b/lib/std/testing.zig @@ -450,6 +450,36 @@ pub fn buildExe(zigexec: []const u8, zigfile: []const u8, binfile: []const u8) ! try expectEqual(ret_val, .{ .Exited = 0 }); } +/// Spawns a zig build runner process 'zigexec build subcmd' and +/// expects success +/// If specified, runs zig build in the cwd path +/// If specified, uses the specified lib_dir for zig standard library +/// instead of compiler's default library directory +pub fn runZigBuild(zigexec: []const u8, options: struct { + subcmd: ?[]const u8 = null, + cwd: ?[]const u8 = null, + lib_dir: ?[]const u8 = null, +}) !std.ChildProcess.ExecResult { + var args = std.ArrayList([]const u8).init(allocator); + defer args.deinit(); + + try args.appendSlice(&.{ zigexec, "build" }); + if (options.subcmd) |subcmd| try args.append(subcmd); + if (options.lib_dir) |lib_dir| try args.append(lib_dir); + + var result = try std.ChildProcess.exec(.{ + .allocator = allocator, + .argv = args.items, + .cwd = if (options.cwd) |c| c else null, + }); + errdefer { + allocator.free(result.stdout); + allocator.free(result.stderr); + } + + return result; +} + test "expectEqual nested array" { const a = [2][2]f32{ [_]f32{ 1.0, 0.0 },