authorgravatar for ayushbardhan5@gmail.comiddev5 <ayushbardhan5@gmail.com> 2022-04-04 18:33:47+05:30
committergravatar for ayushbardhan5@gmail.comiddev5 <ayushbardhan5@gmail.com> 2022-04-04 18:33:47+05:30
log8d3e7aa5e0a7b3956a5ba8cf2c85d756ab581465
tree99fd869de8a712781502142d2769163608d36620
parentdf544cace97b57b318dba439d4e67a3953388477

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


1 files changed, 30 insertions(+), 0 deletions(-)

lib/std/testing.zig+30
......@@ -450,6 +450,36 @@ pub fn buildExe(zigexec: []const u8, zigfile: []const u8, binfile: []const u8) !
450450 try expectEqual(ret_val, .{ .Exited = 0 });
451451}
452452
453/// Spawns a zig build runner process 'zigexec build subcmd' and
454/// expects success
455/// If specified, runs zig build in the cwd path
456/// If specified, uses the specified lib_dir for zig standard library
457/// instead of compiler's default library directory
458pub fn runZigBuild(zigexec: []const u8, options: struct {
459 subcmd: ?[]const u8 = null,
460 cwd: ?[]const u8 = null,
461 lib_dir: ?[]const u8 = null,
462}) !std.ChildProcess.ExecResult {
463 var args = std.ArrayList([]const u8).init(allocator);
464 defer args.deinit();
465
466 try args.appendSlice(&.{ zigexec, "build" });
467 if (options.subcmd) |subcmd| try args.append(subcmd);
468 if (options.lib_dir) |lib_dir| try args.append(lib_dir);
469
470 var result = try std.ChildProcess.exec(.{
471 .allocator = allocator,
472 .argv = args.items,
473 .cwd = if (options.cwd) |c| c else null,
474 });
475 errdefer {
476 allocator.free(result.stdout);
477 allocator.free(result.stderr);
478 }
479
480 return result;
481}
482
453483test "expectEqual nested array" {
454484 const a = [2][2]f32{
455485 [_]f32{ 1.0, 0.0 },