diff options
| author | Jay Petacat <jay@jayschwa.net> | 2021-01-05 20:57:18 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-01-07 23:48:58 -0800 |
| commit | a9b505fa7774e2e8451bedfa7bea27d7227572e7 (patch) | |
| tree | 408a88da61e15d5ace79ecefebfe868c09f80d35 /test | |
| parent | 8e9a1ac364360b160438af0b96132d5aacf39a71 (diff) | |
| download | zig-a9b505fa7774e2e8451bedfa7bea27d7227572e7.tar.gz zig-a9b505fa7774e2e8451bedfa7bea27d7227572e7.zip | |
Reduce use of deprecated IO types
Related: #4917
Diffstat (limited to 'test')
| -rw-r--r-- | test/compare_output.zig | 30 | ||||
| -rw-r--r-- | test/stage1/behavior/bugs/5487.zig | 6 | ||||
| -rw-r--r-- | test/tests.zig | 8 |
3 files changed, 22 insertions, 22 deletions
diff --git a/test/compare_output.zig b/test/compare_output.zig index 9dc80f202d..a6e9835ea1 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -22,7 +22,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() void { \\ privateFunction(); - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK 2\n", .{}) catch unreachable; \\} \\ @@ -37,7 +37,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\// purposefully conflicting function with main.zig \\// but it's private so it should be OK \\fn privateFunction() void { - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK 1\n", .{}) catch unreachable; \\} \\ @@ -63,7 +63,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { tc.addSourceFile("foo.zig", \\usingnamespace @import("std").io; \\pub fn foo_function() void { - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK\n", .{}) catch unreachable; \\} ); @@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn bar_function() void { \\ if (foo_function()) { - \\ const stdout = getStdOut().outStream(); + \\ const stdout = getStdOut().writer(); \\ stdout.print("OK\n", .{}) catch unreachable; \\ } \\} @@ -106,7 +106,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\pub const a_text = "OK\n"; \\ \\pub fn ok() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print(b_text, .{}) catch unreachable; \\} ); @@ -124,7 +124,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const io = @import("std").io; \\ \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable; \\} , "Hello, world!\n 12 12 a\n"); @@ -267,7 +267,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ var x_local : i32 = print_ok(x); \\} \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("OK\n", .{}) catch unreachable; \\ return 0; \\} @@ -349,7 +349,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\pub fn main() void { \\ const bar = Bar {.field2 = 13,}; \\ const foo = Foo {.field1 = bar,}; - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ if (!foo.method()) { \\ stdout.print("BAD\n", .{}) catch unreachable; \\ } @@ -363,7 +363,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { cases.add("defer with only fallthrough", \\const io = @import("std").io; \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ defer stdout.print("defer2\n", .{}) catch unreachable; @@ -376,7 +376,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const io = @import("std").io; \\const os = @import("std").os; \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ defer stdout.print("defer2\n", .{}) catch unreachable; @@ -393,7 +393,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ do_test() catch return; \\} \\fn do_test() !void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable; @@ -412,7 +412,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ do_test() catch return; \\} \\fn do_test() !void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print("before\n", .{}) catch unreachable; \\ defer stdout.print("defer1\n", .{}) catch unreachable; \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable; @@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\const io = @import("std").io; \\ \\pub fn main() void { - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ stdout.print(foo_txt, .{}) catch unreachable; \\} , "1234\nabcd\n"); @@ -448,7 +448,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() !void { \\ var args_it = std.process.args(); - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ var index: usize = 0; \\ _ = args_it.skip(); \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) { @@ -487,7 +487,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ \\pub fn main() !void { \\ var args_it = std.process.args(); - \\ const stdout = io.getStdOut().outStream(); + \\ const stdout = io.getStdOut().writer(); \\ var index: usize = 0; \\ _ = args_it.skip(); \\ while (args_it.next(allocator)) |arg_or_err| : (index += 1) { diff --git a/test/stage1/behavior/bugs/5487.zig b/test/stage1/behavior/bugs/5487.zig index 02fa677a44..bf530a8a02 100644 --- a/test/stage1/behavior/bugs/5487.zig +++ b/test/stage1/behavior/bugs/5487.zig @@ -3,10 +3,10 @@ const io = @import("std").io; pub fn write(_: void, bytes: []const u8) !usize { return 0; } -pub fn outStream() io.OutStream(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) { - return io.OutStream(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} }; +pub fn writer() io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) { + return io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} }; } test "crash" { - _ = io.multiOutStream(.{outStream()}); + _ = io.multiWriter(.{writer()}); } diff --git a/test/tests.zig b/test/tests.zig index 5ee381e5c2..ec6d9e1df8 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -652,9 +652,9 @@ pub const StackTracesContext = struct { } child.spawn() catch |err| debug.panic("Unable to spawn {s}: {s}\n", .{ full_exe_path, @errorName(err) }); - const stdout = child.stdout.?.inStream().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; + const stdout = child.stdout.?.reader().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; defer b.allocator.free(stdout); - const stderrFull = child.stderr.?.inStream().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; + const stderrFull = child.stderr.?.reader().readAllAlloc(b.allocator, max_stdout_size) catch unreachable; defer b.allocator.free(stderrFull); var stderr = stderrFull; @@ -875,8 +875,8 @@ pub const CompileErrorContext = struct { var stdout_buf = ArrayList(u8).init(b.allocator); var stderr_buf = ArrayList(u8).init(b.allocator); - child.stdout.?.inStream().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable; - child.stderr.?.inStream().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable; + child.stdout.?.reader().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable; + child.stderr.?.reader().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable; const term = child.wait() catch |err| { debug.panic("Unable to spawn {s}: {s}\n", .{ zig_args.items[0], @errorName(err) }); |
