| author | |
| committer | |
| log | c5e847744c82953d44189a2c7094c8257fdf5b09 |
| tree | 26b3f4864583249c3f97ccda0efb1f48bf83fe90 |
| parent | 091fe78337dc3ca340fdf74ca6c1a58c5e666626 |
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.3 files changed, 1 insertions(+), 86 deletions(-)
lib/std/build.zig-55| ... | @@ -3586,58 +3586,3 @@ test "LibExeObjStep.addPackage" { | ... | @@ -3586,58 +3586,3 @@ test "LibExeObjStep.addPackage" { |
| 3586 | const dupe = exe.packages.items[0]; | 3586 | const dupe = exe.packages.items[0]; |
| 3587 | try std.testing.expectEqualStrings(pkg_top.name, dupe.name); | 3587 | try std.testing.expectEqualStrings(pkg_top.name, dupe.name); |
| 3588 | } | 3588 | } |
| 3589 | |||
| 3590 | test "build_runner issue 10381" { | ||
| 3591 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | ||
| 3592 | |||
| 3593 | const progstr = | ||
| 3594 | \\ pub fn main() u8 { | ||
| 3595 | \\ return 1; | ||
| 3596 | \\ } | ||
| 3597 | ; | ||
| 3598 | |||
| 3599 | const buildstr = | ||
| 3600 | \\ const std = @import("std"); | ||
| 3601 | \\ pub fn build(b: *std.build.Builder) void { | ||
| 3602 | \\ const exe = b.addExecutable("source", "source.zig"); | ||
| 3603 | \\ exe.install(); | ||
| 3604 | \\ const run_cmd = exe.run(); | ||
| 3605 | \\ run_cmd.step.dependOn(b.getInstallStep()); | ||
| 3606 | \\ const run_step = b.step("run", "Run"); | ||
| 3607 | \\ run_step.dependOn(&run_cmd.step); | ||
| 3608 | \\ } | ||
| 3609 | ; | ||
| 3610 | |||
| 3611 | const testing = std.testing; | ||
| 3612 | const allocator = testing.allocator; | ||
| 3613 | |||
| 3614 | var it = try std.process.argsWithAllocator(allocator); | ||
| 3615 | defer it.deinit(); | ||
| 3616 | const testargs = try testing.getTestArgs(&it); | ||
| 3617 | |||
| 3618 | var tmpdir = testing.tmpDir(.{ .no_follow = true }); | ||
| 3619 | defer tmpdir.cleanup(); | ||
| 3620 | const tmpdir_path = try tmpdir.getFullPath(allocator); | ||
| 3621 | defer allocator.free(tmpdir_path); | ||
| 3622 | |||
| 3623 | try tmpdir.dir.writeFile("source.zig", progstr); | ||
| 3624 | try tmpdir.dir.writeFile("build.zig", buildstr); | ||
| 3625 | |||
| 3626 | const cwd_path = try std.process.getCwdAlloc(allocator); | ||
| 3627 | defer allocator.free(cwd_path); | ||
| 3628 | const lib_dir = try std.fs.path.join(allocator, &.{ cwd_path, "lib" }); | ||
| 3629 | defer allocator.free(lib_dir); | ||
| 3630 | |||
| 3631 | const result = try testing.runZigBuild(testargs.zigexec, .{ | ||
| 3632 | .subcmd = "run", | ||
| 3633 | .cwd = tmpdir_path, | ||
| 3634 | .lib_dir = lib_dir, | ||
| 3635 | }); | ||
| 3636 | defer { | ||
| 3637 | allocator.free(result.stdout); | ||
| 3638 | allocator.free(result.stderr); | ||
| 3639 | } | ||
| 3640 | |||
| 3641 | try testing.expectEqual(result.term, .{ .Exited = 1 }); | ||
| 3642 | try testing.expect(std.mem.indexOf(u8, result.stderr, "error: UnexpectedExitCode") == null); | ||
| 3643 | } |
lib/std/special/build_runner.zig+1-1| ... | @@ -209,7 +209,7 @@ pub fn main() !void { | ... | @@ -209,7 +209,7 @@ pub fn main() !void { |
| 209 | error.InvalidStepName => { | 209 | error.InvalidStepName => { |
| 210 | return usageAndErr(builder, true, stderr_stream); | 210 | return usageAndErr(builder, true, stderr_stream); |
| 211 | }, | 211 | }, |
| 212 | error.UnexpectedExitCode, error.UncleanExit => process.exit(1), | 212 | error.UncleanExit => process.exit(1), |
| 213 | else => return err, | 213 | else => return err, |
| 214 | } | 214 | } |
| 215 | }; | 215 | }; |
lib/std/testing.zig-30| ... | @@ -450,36 +450,6 @@ pub fn buildExe(zigexec: []const u8, zigfile: []const u8, binfile: []const u8) ! | ... | @@ -450,36 +450,6 @@ pub fn buildExe(zigexec: []const u8, zigfile: []const u8, binfile: []const u8) ! |
| 450 | try expectEqual(ret_val, .{ .Exited = 0 }); | 450 | try expectEqual(ret_val, .{ .Exited = 0 }); |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 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 | ||
| 458 | pub 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 | |||
| 483 | test "expectEqual nested array" { | 453 | test "expectEqual nested array" { |
| 484 | const a = [2][2]f32{ | 454 | const a = [2][2]f32{ |
| 485 | [_]f32{ 1.0, 0.0 }, | 455 | [_]f32{ 1.0, 0.0 }, |