diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-26 13:17:34 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-26 18:32:44 -0400 |
| commit | 2f040a23c8b968db56ab4c4725d6651f5ea3418e (patch) | |
| tree | 58727a1c2ffdf356db2f5c01e84940e4ced0541f /test | |
| parent | 7cb6279ac0cec065234347bda5944be64fe8b3da (diff) | |
| download | zig-2f040a23c8b968db56ab4c4725d6651f5ea3418e.tar.gz zig-2f040a23c8b968db56ab4c4725d6651f5ea3418e.zip | |
clean up references to os
Diffstat (limited to 'test')
| -rw-r--r-- | test/cli.zig | 40 | ||||
| -rw-r--r-- | test/tests.zig | 90 |
2 files changed, 65 insertions, 65 deletions
diff --git a/test/cli.zig b/test/cli.zig index 1e7f1d0a73..cee030e4db 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -1,7 +1,9 @@ const std = @import("std"); const builtin = @import("builtin"); -const os = std.os; const testing = std.testing; +const process = std.process; +const fs = std.fs; +const ChildProcess = std.ChildProcess; var a: *std.mem.Allocator = undefined; @@ -12,7 +14,7 @@ pub fn main() !void { var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); defer arena.deinit(); - var arg_it = os.args(); + var arg_it = process.args(); // skip my own exe name _ = arg_it.skip(); @@ -27,9 +29,9 @@ pub fn main() !void { std.debug.warn("Expected second argument to be cache root directory path\n"); return error.InvalidArgs; }); - const zig_exe = try os.path.resolve(a, [][]const u8{zig_exe_rel}); + const zig_exe = try fs.path.resolve(a, [][]const u8{zig_exe_rel}); - const dir_path = try os.path.join(a, [][]const u8{ cache_root, "clitest" }); + const dir_path = try fs.path.join(a, [][]const u8{ cache_root, "clitest" }); const TestFn = fn ([]const u8, []const u8) anyerror!void; const test_fns = []TestFn{ testZigInitLib, @@ -37,8 +39,8 @@ pub fn main() !void { testGodboltApi, }; for (test_fns) |testFn| { - try os.deleteTree(a, dir_path); - try os.makeDir(dir_path); + try fs.deleteTree(a, dir_path); + try fs.makeDir(dir_path); try testFn(zig_exe, dir_path); } } @@ -58,15 +60,15 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void { std.debug.warn("\n"); } -fn exec(cwd: []const u8, argv: []const []const u8) !os.ChildProcess.ExecResult { +fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult { const max_output_size = 100 * 1024; - const result = os.ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| { + const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| { std.debug.warn("The following command failed:\n"); printCmd(cwd, argv); return err; }; switch (result.term) { - os.ChildProcess.Term.Exited => |code| { + .Exited => |code| { if (code != 0) { std.debug.warn("The following command exited with error code {}:\n", code); printCmd(cwd, argv); @@ -97,10 +99,10 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void { } fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { - if (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64) return; + if (builtin.os != .linux or builtin.arch != .x86_64) return; - const example_zig_path = try os.path.join(a, [][]const u8{ dir_path, "example.zig" }); - const example_s_path = try os.path.join(a, [][]const u8{ dir_path, "example.s" }); + const example_zig_path = try fs.path.join(a, [][]const u8{ dir_path, "example.zig" }); + const example_s_path = try fs.path.join(a, [][]const u8{ dir_path, "example.s" }); try std.io.writeFile(example_zig_path, \\// Type your code here, or load an example. @@ -114,13 +116,13 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { ); const args = [][]const u8{ - zig_exe, "build-obj", - "--cache-dir", dir_path, - "--name", "example", - "--output-dir", dir_path, - "--emit", "asm", - "-mllvm", "--x86-asm-syntax=intel", - "--strip", "--release-fast", + zig_exe, "build-obj", + "--cache-dir", dir_path, + "--name", "example", + "--output-dir", dir_path, + "--emit", "asm", + "-mllvm", "--x86-asm-syntax=intel", + "--strip", "--release-fast", example_zig_path, "--disable-gen-h", }; _ = try exec(dir_path, args); diff --git a/test/tests.zig b/test/tests.zig index a17938fc3c..061d4cb55f 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2,11 +2,9 @@ const std = @import("std"); const debug = std.debug; const warn = debug.warn; const build = std.build; -const os = std.os; -const StdIo = os.ChildProcess.StdIo; -const Term = os.ChildProcess.Term; const Buffer = std.Buffer; const io = std.io; +const fs = std.fs; const mem = std.mem; const fmt = std.fmt; const ArrayList = std.ArrayList; @@ -30,19 +28,19 @@ const TestTarget = struct { const test_targets = []TestTarget{ TestTarget{ - .os = builtin.Os.linux, - .arch = builtin.Arch.x86_64, - .abi = builtin.Abi.gnu, + .os = .linux, + .arch = .x86_64, + .abi = .gnu, }, TestTarget{ - .os = builtin.Os.macosx, - .arch = builtin.Arch.x86_64, - .abi = builtin.Abi.gnu, + .os = .macosx, + .arch = .x86_64, + .abi = .gnu, }, TestTarget{ - .os = builtin.Os.windows, - .arch = builtin.Arch.x86_64, - .abi = builtin.Abi.msvc, + .os = .windows, + .arch = .x86_64, + .abi = .msvc, }, }; @@ -114,7 +112,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M const exe = b.addExecutable("test-cli", "test/cli.zig"); const run_cmd = exe.run(); run_cmd.addArgs([][]const u8{ - os.path.realAlloc(b.allocator, b.zig_exe) catch unreachable, + fs.path.realAlloc(b.allocator, b.zig_exe) catch unreachable, b.pathFromRoot(b.cache_root), }); @@ -301,12 +299,12 @@ pub const CompareOutputContext = struct { warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); - const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; + const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; defer child.deinit(); - child.stdin_behavior = StdIo.Ignore; - child.stdout_behavior = StdIo.Pipe; - child.stderr_behavior = StdIo.Pipe; + child.stdin_behavior = .Ignore; + child.stdout_behavior = .Pipe; + child.stderr_behavior = .Pipe; child.env_map = b.env_map; child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); @@ -324,7 +322,7 @@ pub const CompareOutputContext = struct { debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); }; switch (term) { - Term.Exited => |code| { + .Exited => |code| { if (code != 0) { warn("Process {} exited with error code {}\n", full_exe_path, code); printInvocation(args.toSliceConst()); @@ -383,13 +381,13 @@ pub const CompareOutputContext = struct { warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); - const child = os.ChildProcess.init([][]const u8{full_exe_path}, b.allocator) catch unreachable; + const child = std.ChildProcess.init([][]const u8{full_exe_path}, b.allocator) catch unreachable; defer child.deinit(); child.env_map = b.env_map; - child.stdin_behavior = StdIo.Ignore; - child.stdout_behavior = StdIo.Ignore; - child.stderr_behavior = StdIo.Ignore; + child.stdin_behavior = .Ignore; + child.stdout_behavior = .Ignore; + child.stderr_behavior = .Ignore; const term = child.spawnAndWait() catch |err| { debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); @@ -397,13 +395,13 @@ pub const CompareOutputContext = struct { const expected_exit_code: i32 = 126; switch (term) { - Term.Exited => |code| { + .Exited => |code| { if (code != expected_exit_code) { warn("\nProgram expected to exit with code {} " ++ "but exited with code {}\n", expected_exit_code, code); return error.TestFailed; } }, - Term.Signal => |sig| { + .Signal => |sig| { warn("\nProgram expected to exit with code {} " ++ "but instead signaled {}\n", expected_exit_code, sig); return error.TestFailed; }, @@ -459,7 +457,7 @@ pub const CompareOutputContext = struct { pub fn addCase(self: *CompareOutputContext, case: TestCase) void { const b = self.b; - const root_src = os.path.join( + const root_src = fs.path.join( b.allocator, [][]const u8{ b.cache_root, case.sources.items[0].filename }, ) catch unreachable; @@ -475,7 +473,7 @@ pub const CompareOutputContext = struct { exe.addAssemblyFile(root_src); for (case.sources.toSliceConst()) |src_file| { - const expanded_src_path = os.path.join( + const expanded_src_path = fs.path.join( b.allocator, [][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; @@ -507,7 +505,7 @@ pub const CompareOutputContext = struct { } for (case.sources.toSliceConst()) |src_file| { - const expanded_src_path = os.path.join( + const expanded_src_path = fs.path.join( b.allocator, [][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; @@ -538,7 +536,7 @@ pub const CompareOutputContext = struct { } for (case.sources.toSliceConst()) |src_file| { - const expanded_src_path = os.path.join( + const expanded_src_path = fs.path.join( b.allocator, [][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; @@ -633,7 +631,7 @@ pub const CompileErrorContext = struct { const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); const b = self.context.b; - const root_src = os.path.join( + const root_src = fs.path.join( b.allocator, [][]const u8{ b.cache_root, self.case.sources.items[0].filename }, ) catch unreachable; @@ -669,13 +667,13 @@ pub const CompileErrorContext = struct { printInvocation(zig_args.toSliceConst()); } - const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; + const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; defer child.deinit(); child.env_map = b.env_map; - child.stdin_behavior = StdIo.Ignore; - child.stdout_behavior = StdIo.Pipe; - child.stderr_behavior = StdIo.Pipe; + child.stdin_behavior = .Ignore; + child.stdout_behavior = .Pipe; + child.stderr_behavior = .Pipe; child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); @@ -692,7 +690,7 @@ pub const CompileErrorContext = struct { debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err)); }; switch (term) { - Term.Exited => |code| { + .Exited => |code| { if (code == 0) { printInvocation(zig_args.toSliceConst()); return error.CompilationIncorrectlySucceeded; @@ -823,7 +821,7 @@ pub const CompileErrorContext = struct { self.step.dependOn(&compile_and_cmp_errors.step); for (case.sources.toSliceConst()) |src_file| { - const expanded_src_path = os.path.join( + const expanded_src_path = fs.path.join( b.allocator, [][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; @@ -858,7 +856,7 @@ pub const BuildExamplesContext = struct { } var zig_args = ArrayList([]const u8).init(b.allocator); - const rel_zig_exe = os.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable; + const rel_zig_exe = fs.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable; zig_args.append(rel_zig_exe) catch unreachable; zig_args.append("build") catch unreachable; @@ -958,7 +956,7 @@ pub const TranslateCContext = struct { const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step); const b = self.context.b; - const root_src = os.path.join( + const root_src = fs.path.join( b.allocator, [][]const u8{ b.cache_root, self.case.sources.items[0].filename }, ) catch unreachable; @@ -976,13 +974,13 @@ pub const TranslateCContext = struct { printInvocation(zig_args.toSliceConst()); } - const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; + const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; defer child.deinit(); child.env_map = b.env_map; - child.stdin_behavior = StdIo.Ignore; - child.stdout_behavior = StdIo.Pipe; - child.stderr_behavior = StdIo.Pipe; + child.stdin_behavior = .Ignore; + child.stdout_behavior = .Pipe; + child.stderr_behavior = .Pipe; child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); @@ -999,14 +997,14 @@ pub const TranslateCContext = struct { debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err)); }; switch (term) { - Term.Exited => |code| { + .Exited => |code| { if (code != 0) { warn("Compilation failed with exit code {}\n", code); printInvocation(zig_args.toSliceConst()); return error.TestFailed; } }, - Term.Signal => |code| { + .Signal => |code| { warn("Compilation failed with signal {}\n", code); printInvocation(zig_args.toSliceConst()); return error.TestFailed; @@ -1131,7 +1129,7 @@ pub const TranslateCContext = struct { self.step.dependOn(&translate_c_and_cmp.step); for (case.sources.toSliceConst()) |src_file| { - const expanded_src_path = os.path.join( + const expanded_src_path = fs.path.join( b.allocator, [][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; @@ -1254,7 +1252,7 @@ pub const GenHContext = struct { pub fn addCase(self: *GenHContext, case: *const TestCase) void { const b = self.b; - const root_src = os.path.join( + const root_src = fs.path.join( b.allocator, [][]const u8{ b.cache_root, case.sources.items[0].filename }, ) catch unreachable; @@ -1269,7 +1267,7 @@ pub const GenHContext = struct { obj.setBuildMode(mode); for (case.sources.toSliceConst()) |src_file| { - const expanded_src_path = os.path.join( + const expanded_src_path = fs.path.join( b.allocator, [][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; |
