From c5e847744c82953d44189a2c7094c8257fdf5b09 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 28 Apr 2022 14:11:53 -0700 Subject: [PATCH] Revert "Merge pull request #11214 from iddev5/ay-build-runner" This reverts commit 75c9936737a6ba991d4ef187ddc9d51bc0ad0998, reversing changes made to 7f13f5cd5f5a518638b15d7225eae2d88ec1efb5. I don't think `runZigBuild` belongs in std.testing. We already have `test/standalone/*` for this. Additionally test names should explain what they are testing rather than referencing GitHub issue numbers. --- lib/std/build.zig | 55 -------------------------------- lib/std/special/build_runner.zig | 2 +- lib/std/testing.zig | 30 ----------------- 3 files changed, 1 insertion(+), 86 deletions(-) diff --git a/lib/std/build.zig b/lib/std/build.zig index ea7f495404..453f20c333 100644 --- a/lib/std/build.zig +++ b/lib/std/build.zig @@ -3586,58 +3586,3 @@ test "LibExeObjStep.addPackage" { const dupe = exe.packages.items[0]; try std.testing.expectEqualStrings(pkg_top.name, dupe.name); } - -test "build_runner issue 10381" { - if (builtin.os.tag == .wasi) return error.SkipZigTest; - - const progstr = - \\ pub fn main() u8 { - \\ return 1; - \\ } - ; - - const buildstr = - \\ const std = @import("std"); - \\ pub fn build(b: *std.build.Builder) void { - \\ const exe = b.addExecutable("source", "source.zig"); - \\ exe.install(); - \\ const run_cmd = exe.run(); - \\ run_cmd.step.dependOn(b.getInstallStep()); - \\ const run_step = b.step("run", "Run"); - \\ run_step.dependOn(&run_cmd.step); - \\ } - ; - - const testing = std.testing; - const allocator = testing.allocator; - - var it = try std.process.argsWithAllocator(allocator); - defer it.deinit(); - const testargs = try testing.getTestArgs(&it); - - var tmpdir = testing.tmpDir(.{ .no_follow = true }); - defer tmpdir.cleanup(); - const tmpdir_path = try tmpdir.getFullPath(allocator); - defer allocator.free(tmpdir_path); - - try tmpdir.dir.writeFile("source.zig", progstr); - try tmpdir.dir.writeFile("build.zig", buildstr); - - const cwd_path = try std.process.getCwdAlloc(allocator); - defer allocator.free(cwd_path); - const lib_dir = try std.fs.path.join(allocator, &.{ cwd_path, "lib" }); - defer allocator.free(lib_dir); - - const result = try testing.runZigBuild(testargs.zigexec, .{ - .subcmd = "run", - .cwd = tmpdir_path, - .lib_dir = lib_dir, - }); - defer { - allocator.free(result.stdout); - allocator.free(result.stderr); - } - - try testing.expectEqual(result.term, .{ .Exited = 1 }); - try testing.expect(std.mem.indexOf(u8, result.stderr, "error: UnexpectedExitCode") == null); -} diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig index e844866c79..523723ddf2 100644 --- a/lib/std/special/build_runner.zig +++ b/lib/std/special/build_runner.zig @@ -209,7 +209,7 @@ pub fn main() !void { error.InvalidStepName => { return usageAndErr(builder, true, stderr_stream); }, - error.UnexpectedExitCode, error.UncleanExit => process.exit(1), + error.UncleanExit => process.exit(1), else => return err, } }; diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 016e84acd8..cfdf300c04 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -450,36 +450,6 @@ 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 },