authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-08 16:24:26-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-08 16:24:26-05:00
log5b10d9f917ac773ca7c842d74ef44c861484670f
treec7d02b0f0c67f8f933ff66e88f62f476af5841ca
parent6ae36807b70e741ac1a7f8ee1b8d90466abfdda8
signaturelock-open Commit is signed but in an unrecognized format.

std: fix bitrotted evented code


5 files changed, 13 insertions(+), 17 deletions(-)

lib/std/event/channel.zig+3-4
...@@ -267,17 +267,16 @@ pub fn Channel(comptime T: type) type {...@@ -267,17 +267,16 @@ pub fn Channel(comptime T: type) type {
267}267}
268268
269test "std.event.Channel" {269test "std.event.Channel" {
270 if (!std.io.is_async) return error.SkipZigTest;
271
270 // https://github.com/ziglang/zig/issues/1908272 // https://github.com/ziglang/zig/issues/1908
271 if (builtin.single_threaded) return error.SkipZigTest;273 if (builtin.single_threaded) return error.SkipZigTest;
272274
273 // https://github.com/ziglang/zig/issues/3251275 // https://github.com/ziglang/zig/issues/3251
274 if (builtin.os == .freebsd) return error.SkipZigTest;276 if (builtin.os == .freebsd) return error.SkipZigTest;
275277
276 // TODO provide a way to run tests in evented I/O mode
277 if (!std.io.is_async) return error.SkipZigTest;
278
279 var channel: Channel(i32) = undefined;278 var channel: Channel(i32) = undefined;
280 channel.init([0]i32{});279 channel.init(&[0]i32{});
281 defer channel.deinit();280 defer channel.deinit();
282281
283 var handle = async testChannelGetter(&channel);282 var handle = async testChannelGetter(&channel);
lib/std/event/group.zig+1-1
...@@ -22,7 +22,7 @@ pub fn Group(comptime ReturnType: type) type {...@@ -22,7 +22,7 @@ pub fn Group(comptime ReturnType: type) type {
22 const AllocStack = std.atomic.Stack(Node);22 const AllocStack = std.atomic.Stack(Node);
2323
24 pub const Node = struct {24 pub const Node = struct {
25 bytes: []const u8 = [0]u8{},25 bytes: []const u8 = &[0]u8{},
26 handle: anyframe->ReturnType,26 handle: anyframe->ReturnType,
27 };27 };
2828
lib/std/event/lock.zig+4-4
...@@ -117,21 +117,21 @@ pub const Lock = struct {...@@ -117,21 +117,21 @@ pub const Lock = struct {
117};117};
118118
119test "std.event.Lock" {119test "std.event.Lock" {
120 if (!std.io.is_async) return error.SkipZigTest;
121
120 // TODO https://github.com/ziglang/zig/issues/1908122 // TODO https://github.com/ziglang/zig/issues/1908
121 if (builtin.single_threaded) return error.SkipZigTest;123 if (builtin.single_threaded) return error.SkipZigTest;
122124
123 // TODO https://github.com/ziglang/zig/issues/3251125 // TODO https://github.com/ziglang/zig/issues/3251
124 if (builtin.os == .freebsd) return error.SkipZigTest;126 if (builtin.os == .freebsd) return error.SkipZigTest;
125127
126 // TODO provide a way to run tests in evented I/O mode
127 if (!std.io.is_async) return error.SkipZigTest;
128
129 var lock = Lock.init();128 var lock = Lock.init();
130 defer lock.deinit();129 defer lock.deinit();
131130
132 _ = async testLock(&lock);131 _ = async testLock(&lock);
133132
134 testing.expectEqualSlices(i32, [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len, shared_test_data);133 const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
134 testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
135}135}
136136
137async fn testLock(lock: *Lock) void {137async fn testLock(lock: *Lock) void {
lib/std/fs/watch.zig+2-3
...@@ -615,12 +615,11 @@ pub fn Watch(comptime V: type) type {...@@ -615,12 +615,11 @@ pub fn Watch(comptime V: type) type {
615const test_tmp_dir = "std_event_fs_test";615const test_tmp_dir = "std_event_fs_test";
616616
617test "write a file, watch it, write it again" {617test "write a file, watch it, write it again" {
618 // TODO provide a way to run tests in evented I/O mode618 // TODO re-enable this test
619 if (!std.io.is_async) return error.SkipZigTest;619 if (true) return error.SkipZigTest;
620620
621 const allocator = std.heap.page_allocator;621 const allocator = std.heap.page_allocator;
622622
623 // TODO move this into event loop too
624 try os.makePath(allocator, test_tmp_dir);623 try os.makePath(allocator, test_tmp_dir);
625 defer os.deleteTree(test_tmp_dir) catch {};624 defer os.deleteTree(test_tmp_dir) catch {};
626625
lib/std/net/test.zig+3-5
...@@ -81,17 +81,15 @@ test "resolve DNS" {...@@ -81,17 +81,15 @@ test "resolve DNS" {
81}81}
8282
83test "listen on a port, send bytes, receive bytes" {83test "listen on a port, send bytes, receive bytes" {
84 if (!std.io.is_async) return error.SkipZigTest;
85
84 if (std.builtin.os != .linux) {86 if (std.builtin.os != .linux) {
85 // TODO build abstractions for other operating systems87 // TODO build abstractions for other operating systems
86 return error.SkipZigTest;88 return error.SkipZigTest;
87 }89 }
88 if (std.io.mode != .evented) {
89 // TODO add ability to run tests in non-blocking I/O mode
90 return error.SkipZigTest;
91 }
9290
93 // TODO doing this at comptime crashed the compiler91 // TODO doing this at comptime crashed the compiler
94 const localhost = net.Address.parseIp("127.0.0.1", 0);92 const localhost = try net.Address.parseIp("127.0.0.1", 0);
9593
96 var server = net.StreamServer.init(net.StreamServer.Options{});94 var server = net.StreamServer.init(net.StreamServer.Options{});
97 defer server.deinit();95 defer server.deinit();