aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-26 16:22:47 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-26 16:22:47 -0700
commit67d5bfefba48d28c02e2841f1a47a213d28d4693 (patch)
tree6b1fa9ebcdc207782cbe85997fc7070fb6ca22b0 /lib/std/testing.zig
parentba426f0a54d1c80ae9a4c73e06c5dc1265f0568b (diff)
downloadzig-67d5bfefba48d28c02e2841f1a47a213d28d4693.tar.gz
zig-67d5bfefba48d28c02e2841f1a47a213d28d4693.zip
std.testing: remove tight coupling with executing zig as child process
This tight coupling causes problems for various targets, requires hacky "get args" functionality, and bungles relative file system paths, making invalid assumptions about the zig-cache directory. In short, these are not unit tests; these should be standalone tests instead. Reverts e5d4a694ea7dd251e10d6434c9321b5e0a548d4b Reverts d976456ef665bf0aba3a83a8e7fccb4a92b2d3b2 Reverts dbbda0f41a7c5e214801925f8447a15193c3c731 Closes #11542
Diffstat (limited to 'lib/std/testing.zig')
-rw-r--r--lib/std/testing.zig51
1 files changed, 0 insertions, 51 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 174e898bca..4e43413d28 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -355,19 +355,6 @@ pub const TmpDir = struct {
const random_bytes_count = 12;
const sub_path_len = std.fs.base64_encoder.calcSize(random_bytes_count);
- /// caller owns memory
- pub fn getFullPath(self: *TmpDir, alloc: std.mem.Allocator) ![]u8 {
- const cwd_str = try std.process.getCwdAlloc(alloc);
- defer alloc.free(cwd_str);
- const path = try std.fs.path.join(alloc, &[_][]const u8{
- cwd_str,
- "zig-cache",
- "tmp",
- &self.sub_path,
- });
- return path;
- }
-
pub fn cleanup(self: *TmpDir) void {
self.dir.close();
self.parent_dir.deleteTree(&self.sub_path) catch {};
@@ -413,44 +400,6 @@ pub fn tmpDir(opts: std.fs.Dir.OpenDirOptions) TmpDir {
};
}
-const TestArgs = struct {
- testexec: [:0]const u8 = undefined,
- zigexec: [:0]const u8 = undefined,
-};
-
-/// Get test arguments inside test block by regular test runner ('zig test file.zig')
-/// Caller must provide backing ArgIterator
-pub fn getTestArgs(it: *std.process.ArgIterator) !TestArgs {
- var testargs = TestArgs{};
- testargs.testexec = it.next() orelse unreachable;
- testargs.zigexec = it.next() orelse unreachable;
- try expect(!it.skip());
- return testargs;
-}
-
-test "getTestArgs" {
- var it = try std.process.argsWithAllocator(allocator);
- const testargs = try getTestArgs(&it);
- defer it.deinit(); // no-op unless WASI or Windows
- try expect(testargs.testexec.len > 0); // zig compiler executable path
- try expect(testargs.zigexec.len > 0); // test runner executable path
-}
-
-/// Spawns child process with 'zigexec build-exe zigfile -femit-bin=binfile'
-/// and expects success
-pub fn buildExe(zigexec: []const u8, zigfile: []const u8, binfile: []const u8) !void {
- const flag_emit = "-femit-bin=";
- const cmd_emit = try std.mem.concat(allocator, u8, &[_][]const u8{ flag_emit, binfile });
- defer allocator.free(cmd_emit);
-
- const args = [_][]const u8{ zigexec, "build-exe", zigfile, cmd_emit };
- var procCompileChild = std.ChildProcess.init(&args, allocator);
- try procCompileChild.spawn();
-
- const ret_val = try procCompileChild.wait();
- try expectEqual(ret_val, .{ .Exited = 0 });
-}
-
test "expectEqual nested array" {
const a = [2][2]f32{
[_]f32{ 1.0, 0.0 },