From 15b0fa1af95fd5a7c32c820e7ad727048e959cec Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Fri, 30 Aug 2024 18:43:12 +0100 Subject: [PATCH] Latest Zig master compatibility --- build.zig.zon | 20 ++++++++++---------- cli/build.zig.zon | 4 ++-- src/Routes.zig | 2 +- src/jetzig/testing.zig | 30 +++++++++++++++--------------- src/jetzig/testing/App.zig | 8 +++++--- src/test_runner.zig | 2 +- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 4198870..db660b6 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,28 +3,28 @@ .version = "0.0.0", .dependencies = .{ .zmd = .{ - .url = "https://github.com/jetzig-framework/zmd/archive/a197906b017d2a2d6c1896d77c04a74b13ddfa7f.tar.gz", - .hash = "12203b56c2e17a2fd62ea3d3d9be466f43921a3aef88b381cf58f41251815205fdb5", + .url = "https://github.com/jetzig-framework/zmd/archive/6dda080c7fcbe78c39d9e4f52b8eec9aa7cbbaad.tar.gz", + .hash = "12208a01a7c10d0583f253787cf7271587d9509862f34e2b6d754cade7bc08500ef6", }, .zmpl = .{ - .url = "https://github.com/jetzig-framework/zmpl/archive/7c2e599807fe8d28ce45b8b3be1829e3d704422e.tar.gz", - .hash = "12207c30c6fbcb8c7519719fc47ff9d0acca72a3557ec671984d16260bdf1c832740", + .url = "https://github.com/jetzig-framework/zmpl/archive/8d7376704319682e89fb032c36c17e7dd6c51533.tar.gz", + .hash = "12201a0c32e8fa8d3c8482d7486c59656187aead94f7846ad1a6c48b378570d12d1a", }, .jetkv = .{ - .url = "https://github.com/jetzig-framework/jetkv/archive/cf1c611a9c406ccadb50b1bf7798e2b88c43fd2b.tar.gz", - .hash = "1220434169bfbfbb3a0bbe7073f9bcff5401979a967d25ba3915046f6ea44e40839d", + .url = "https://github.com/jetzig-framework/jetkv/archive/2b1130a48979ea2871c8cf6ca89c38b1e7062839.tar.gz", + .hash = "12201d75d73aad5e1c996de4d5ae87a00e58479c8d469bc2eeb5fdeeac8857bc09af", }, .args = .{ - .url = "https://github.com/ikskuh/zig-args/archive/03af1b6c5bfda9646a562c861055024daed5b238.tar.gz", - .hash = "1220904d2fdcd970dd0d216211d092eb3ef6da01117163cc9393ab845a1d66c029d9", + .url = "https://github.com/ikskuh/zig-args/archive/0abdd6947a70e6d8cc83b66228cea614aa856206.tar.gz", + .hash = "1220411a8c46d95bbf3b6e2059854bcb3c5159d428814099df5294232b9980517e9c", }, .smtp_client = .{ .url = "https://github.com/karlseguin/smtp_client.zig/archive/8fcfad9ca2d9e446612c79f4e54050cfbe81b38d.tar.gz", .hash = "1220cebfcf6c63295819df92ec54abe62aad91b1d16666781194c29a7874bb7bbbda", }, .httpz = .{ - .url = "https://github.com/karlseguin/http.zig/archive/e1df408cd530d058a7e1652bd8dcfa7191ff776e.tar.gz", - .hash = "1220efbc744de6e13e57ab9fa6370ea9690601e55ba6ced74179c081a295c99fd422", + .url = "https://github.com/karlseguin/http.zig/archive/30195d6e668d1cb97630bab282d4ac7f147af607.tar.gz", + .hash = "12204f7c5a6b8a6988ab7cbccaf3c1c6199fbf423741412a607be8bde835fb4b8cc8", }, }, diff --git a/cli/build.zig.zon b/cli/build.zig.zon index cacf203..cbbbfd1 100644 --- a/cli/build.zig.zon +++ b/cli/build.zig.zon @@ -5,8 +5,8 @@ .dependencies = .{ .args = .{ - .url = "https://github.com/ikskuh/zig-args/archive/03af1b6c5bfda9646a562c861055024daed5b238.tar.gz", - .hash = "1220904d2fdcd970dd0d216211d092eb3ef6da01117163cc9393ab845a1d66c029d9", + .url = "https://github.com/ikskuh/zig-args/archive/0abdd6947a70e6d8cc83b66228cea614aa856206.tar.gz", + .hash = "1220411a8c46d95bbf3b6e2059854bcb3c5159d428814099df5294232b9980517e9c", }, }, .paths = .{ diff --git a/src/Routes.zig b/src/Routes.zig index 868bede..7863f20 100644 --- a/src/Routes.zig +++ b/src/Routes.zig @@ -598,7 +598,7 @@ fn asNodeIndex(index: usize) std.zig.Ast.Node.Index { } fn isActionFunctionName(name: []const u8) bool { - inline for (@typeInfo(jetzig.views.Route.Action).Enum.fields) |field| { + inline for (@typeInfo(jetzig.views.Route.Action).@"enum".fields) |field| { if (std.mem.eql(u8, field.name, name)) return true; } diff --git a/src/jetzig/testing.zig b/src/jetzig/testing.zig index d36b893..12968eb 100644 --- a/src/jetzig/testing.zig +++ b/src/jetzig/testing.zig @@ -40,7 +40,7 @@ pub const Logger = struct { pub fn log( self: *Logger, comptime message_level: std.log.Level, - comptime scope: @Type(.EnumLiteral), + comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype, ) void { @@ -154,10 +154,10 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: if (try data.getValue(std.mem.trimLeft(u8, expected_path, &.{'.'}))) |value| { switch (value.*) { .string => |string| switch (@typeInfo(@TypeOf(expected_value))) { - .Pointer, .Array => { + .pointer, .array => { if (std.mem.eql(u8, string.value, expected_value)) return; }, - .Null => { + .null => { logFailure( "Expected null/non-existent value for " ++ jetzig.colors.cyan("{s}") ++ ", found: " ++ jetzig.colors.cyan("{s}"), .{ expected_path, string.value }, @@ -167,10 +167,10 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: else => unreachable, }, .integer => |integer| switch (@typeInfo(@TypeOf(expected_value))) { - .Int, .ComptimeInt => { + .int, .comptime_int => { if (integer.value == expected_value) return; }, - .Null => { + .null => { logFailure( "Expected null/non-existent value for " ++ jetzig.colors.cyan("{s}") ++ ", found: " ++ jetzig.colors.green("{}"), .{ expected_path, integer.value }, @@ -180,10 +180,10 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: else => {}, }, .float => |float| switch (@typeInfo(@TypeOf(expected_value))) { - .Float, .ComptimeFloat => { + .float, .comptime_float => { if (float.value == expected_value) return; }, - .Null => { + .null => { logFailure( "Expected null/non-existent value for " ++ jetzig.colors.cyan("{s}") ++ ", found: " ++ jetzig.colors.green("{}"), .{ expected_path, float.value }, @@ -193,10 +193,10 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: else => {}, }, .boolean => |boolean| switch (@typeInfo(@TypeOf(expected_value))) { - .Bool => { + .bool => { if (boolean.value == expected_value) return; }, - .Null => { + .null => { logFailure( "Expected null/non-existent value for " ++ jetzig.colors.cyan("{s}") ++ ", found: " ++ jetzig.colors.green("{}"), .{ expected_path, boolean.value }, @@ -206,10 +206,10 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: else => {}, }, .Null => switch (@typeInfo(@TypeOf(expected_value))) { - .Optional => { + .optional => { if (expected_value == null) return; }, - .Null => { + .null => { return; }, else => {}, @@ -220,7 +220,7 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: switch (value.*) { .string => |string| { switch (@typeInfo(@TypeOf(expected_value))) { - .Pointer, .Array => { + .pointer, .array => { logFailure( "Expected \"" ++ jetzig.colors.red("{s}") ++ "\" in " ++ jetzig.colors.cyan("{s}") ++ ", found \"" ++ jetzig.colors.green("{s}") ++ "\"\nJSON:" ++ json_banner, .{ expected_value, expected_path, string.value, try jsonPretty(response) }, @@ -232,7 +232,7 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: .integer, => |integer| { switch (@typeInfo(@TypeOf(expected_value))) { - .Int, .ComptimeInt => { + .int, .comptime_int => { logFailure( "Expected " ++ jetzig.colors.red("{}") ++ " in " ++ jetzig.colors.cyan("{s}") ++ ", found " ++ jetzig.colors.green("{}") ++ "\nJSON:" ++ json_banner, @@ -244,7 +244,7 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: }, .float => |float| { switch (@typeInfo(@TypeOf(expected_value))) { - .Float, .ComptimeFloat => { + .float, .comptime_float => { logFailure( "Expected " ++ jetzig.colors.red("{}") ++ " in " ++ jetzig.colors.cyan("{s}") ++ ", found " ++ jetzig.colors.green("{}") ++ "\nJSON:" ++ json_banner, .{ expected_value, expected_path, float.value, try jsonPretty(response) }, @@ -255,7 +255,7 @@ pub fn expectJson(expected_path: []const u8, expected_value: anytype, response: }, .boolean => |boolean| { switch (@typeInfo(@TypeOf(expected_value))) { - .Bool => { + .bool => { logFailure( "Expected " ++ jetzig.colors.red("{}") ++ " in " ++ jetzig.colors.cyan("{s}") ++ ", found " ++ jetzig.colors.green("{}") ++ "\nJSON:" ++ json_banner, .{ expected_value, expected_path, boolean.value, try jsonPretty(response) }, diff --git a/src/jetzig/testing/App.zig b/src/jetzig/testing/App.zig index 10375d7..a369616 100644 --- a/src/jetzig/testing/App.zig +++ b/src/jetzig/testing/App.zig @@ -145,7 +145,7 @@ pub fn request( pub fn params(self: App, args: anytype) []Param { const allocator = self.arena.allocator(); var array = std.ArrayList(Param).init(allocator); - inline for (@typeInfo(@TypeOf(args)).Struct.fields) |field| { + inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| { array.append(.{ .key = field.name, .value = @field(args, field.name) }) catch @panic("OOM"); } return array.toOwnedSlice() catch @panic("OOM"); @@ -166,7 +166,7 @@ pub fn multipart(self: *App, comptime args: anytype) []const u8 { const boundary = jetzig.util.generateRandomString(&boundary_buf); self.multipart_boundary = boundary; - inline for (@typeInfo(@TypeOf(args)).Struct.fields, 0..) |field, index| { + inline for (@typeInfo(@TypeOf(args)).@"struct".fields, 0..) |field, index| { if (index > 0) tryWrite(writer, "\r\n"); tryWrite(writer, "--"); tryWrite(writer, boundary); @@ -238,6 +238,8 @@ fn stubbedRequest( .path = path, .query = query, }, + .route_data = null, + .middlewares = undefined, .address = undefined, .method = std.enums.nameCast(httpz.Method, @tagName(method)), .protocol = .HTTP11, @@ -289,7 +291,7 @@ fn createStore(allocator: std.mem.Allocator) !*jetzig.kv.Store { fn buildOptions(app: *const App, args: anytype) RequestOptions { const fields = switch (@typeInfo(@TypeOf(args))) { - .Struct => |info| info.fields, + .@"struct" => |info| info.fields, else => @compileError("Expected struct, found `" ++ @tagName(@typeInfo(@TypeOf(args))) ++ "`"), }; diff --git a/src/test_runner.zig b/src/test_runner.zig index 32b596d..9de38b1 100644 --- a/src/test_runner.zig +++ b/src/test_runner.zig @@ -9,7 +9,7 @@ pub const std_options = .{ pub fn log( comptime message_level: std.log.Level, - comptime scope: @Type(.EnumLiteral), + comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype, ) void {