Commit 5b10d9f917

Andrew Kelley <andrew@ziglang.org>
2020-02-08 22:24:26
std: fix bitrotted evented code
1 parent 6ae3680
Changed files (5)
lib/std/event/channel.zig
@@ -267,17 +267,16 @@ pub fn Channel(comptime T: type) type {
 }
 
 test "std.event.Channel" {
+    if (!std.io.is_async) return error.SkipZigTest;
+
     // https://github.com/ziglang/zig/issues/1908
     if (builtin.single_threaded) return error.SkipZigTest;
 
     // https://github.com/ziglang/zig/issues/3251
     if (builtin.os == .freebsd) return error.SkipZigTest;
 
-    // TODO provide a way to run tests in evented I/O mode
-    if (!std.io.is_async) return error.SkipZigTest;
-
     var channel: Channel(i32) = undefined;
-    channel.init([0]i32{});
+    channel.init(&[0]i32{});
     defer channel.deinit();
 
     var handle = async testChannelGetter(&channel);
lib/std/event/group.zig
@@ -22,7 +22,7 @@ pub fn Group(comptime ReturnType: type) type {
         const AllocStack = std.atomic.Stack(Node);
 
         pub const Node = struct {
-            bytes: []const u8 = [0]u8{},
+            bytes: []const u8 = &[0]u8{},
             handle: anyframe->ReturnType,
         };
 
lib/std/event/lock.zig
@@ -117,21 +117,21 @@ pub const Lock = struct {
 };
 
 test "std.event.Lock" {
+    if (!std.io.is_async) return error.SkipZigTest;
+
     // TODO https://github.com/ziglang/zig/issues/1908
     if (builtin.single_threaded) return error.SkipZigTest;
 
     // TODO https://github.com/ziglang/zig/issues/3251
     if (builtin.os == .freebsd) return error.SkipZigTest;
 
-    // TODO provide a way to run tests in evented I/O mode
-    if (!std.io.is_async) return error.SkipZigTest;
-
     var lock = Lock.init();
     defer lock.deinit();
 
     _ = async testLock(&lock);
 
-    testing.expectEqualSlices(i32, [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len, shared_test_data);
+    const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
+    testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
 }
 
 async fn testLock(lock: *Lock) void {
lib/std/fs/watch.zig
@@ -615,12 +615,11 @@ pub fn Watch(comptime V: type) type {
 const test_tmp_dir = "std_event_fs_test";
 
 test "write a file, watch it, write it again" {
-    // TODO provide a way to run tests in evented I/O mode
-    if (!std.io.is_async) return error.SkipZigTest;
+    // TODO re-enable this test
+    if (true) return error.SkipZigTest;
 
     const allocator = std.heap.page_allocator;
 
-    // TODO move this into event loop too
     try os.makePath(allocator, test_tmp_dir);
     defer os.deleteTree(test_tmp_dir) catch {};
 
lib/std/net/test.zig
@@ -81,17 +81,15 @@ test "resolve DNS" {
 }
 
 test "listen on a port, send bytes, receive bytes" {
+    if (!std.io.is_async) return error.SkipZigTest;
+
     if (std.builtin.os != .linux) {
         // TODO build abstractions for other operating systems
         return error.SkipZigTest;
     }
-    if (std.io.mode != .evented) {
-        // TODO add ability to run tests in non-blocking I/O mode
-        return error.SkipZigTest;
-    }
 
     // TODO doing this at comptime crashed the compiler
-    const localhost = net.Address.parseIp("127.0.0.1", 0);
+    const localhost = try net.Address.parseIp("127.0.0.1", 0);
 
     var server = net.StreamServer.init(net.StreamServer.Options{});
     defer server.deinit();