also looking at this
chore: wip
#1
3 files
+15
-17
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -27,9 +27,7 @@ pub fn build(b: *std.Build) void { | ||
| 27 | 27 | const run_cmd = b.addRunArtifact(exe); |
| 28 | 28 | run_cmd.step.dependOn(b.getInstallStep()); |
| 29 | 29 | |
| 30 | if (b.args) |args| { | |
| 31 | run_cmd.addArgs(args); | |
| 32 | } | |
| 30 | run_cmd.addPassthruArgs(); | |
| 33 | 31 | |
| 34 | 32 | const run_step = b.step("run", "Run the test framework"); |
| 35 | 33 | run_step.dependOn(&run_cmd.step); |
| @@ -113,7 +113,7 @@ fn closeFd(fd: std.posix.fd_t) void { | ||
| 113 | 113 | /// Read entire file contents using POSIX APIs. |
| 114 | 114 | /// Replaces std.fs.cwd().openFile() + file.readToEndAlloc(). |
| 115 | 115 | pub fn readFileAlloc(allocator: std.mem.Allocator, path: []const u8) ![]const u8 { |
| 116 | const path_z = try allocator.dupeZ(u8, path); | |
| 116 | const path_z = try allocator.dupeSentinel(u8, path, 0); | |
| 117 | 117 | defer allocator.free(path_z); |
| 118 | 118 | |
| 119 | 119 | const fd = std.posix.openatZ(std.posix.AT.FDCWD, path_z, .{}, 0) catch |err| { |
| @@ -139,7 +139,7 @@ pub fn readFileAlloc(allocator: std.mem.Allocator, path: []const u8) ![]const u8 | ||
| 139 | 139 | /// Write content to a file using POSIX APIs. |
| 140 | 140 | /// Replaces std.fs.cwd().createFile() + file.writeAll(). |
| 141 | 141 | pub fn writeFile(allocator: std.mem.Allocator, path: []const u8, content: []const u8) !void { |
| 142 | const path_z = try allocator.dupeZ(u8, path); | |
| 142 | const path_z = try allocator.dupeSentinel(u8, path, 0); | |
| 143 | 143 | defer allocator.free(path_z); |
| 144 | 144 | |
| 145 | 145 | const fd = std.posix.openatZ(std.posix.AT.FDCWD, path_z, .{ |
| @@ -161,7 +161,7 @@ pub fn writeFile(allocator: std.mem.Allocator, path: []const u8, content: []cons | ||
| 161 | 161 | /// Delete a file using POSIX APIs. |
| 162 | 162 | /// Replaces std.fs.cwd().deleteFile(). |
| 163 | 163 | pub fn deleteFile(allocator: std.mem.Allocator, path: []const u8) !void { |
| 164 | const path_z = try allocator.dupeZ(u8, path); | |
| 164 | const path_z = try allocator.dupeSentinel(u8, path, 0); | |
| 165 | 165 | defer allocator.free(path_z); |
| 166 | 166 | const rc = std.c.unlink(path_z); |
| 167 | 167 | if (rc != 0) { |
| @@ -175,7 +175,7 @@ pub fn deleteFile(allocator: std.mem.Allocator, path: []const u8) !void { | ||
| 175 | 175 | /// Create directories recursively using POSIX APIs. |
| 176 | 176 | /// Replaces std.fs.cwd().makePath(). |
| 177 | 177 | pub fn makePath(allocator: std.mem.Allocator, path: []const u8) !void { |
| 178 | const path_z = try allocator.dupeZ(u8, path); | |
| 178 | const path_z = try allocator.dupeSentinel(u8, path, 0); | |
| 179 | 179 | defer allocator.free(path_z); |
| 180 | 180 | |
| 181 | 181 | const rc = std.c.mkdir(path_z, 0o755); |
| @@ -189,7 +189,7 @@ pub fn makePath(allocator: std.mem.Allocator, path: []const u8) !void { | ||
| 189 | 189 | if (sep > 0) { |
| 190 | 190 | try makePath(allocator, path[0..sep]); |
| 191 | 191 | // Retry creating the directory |
| 192 | const retry_z = try allocator.dupeZ(u8, path); | |
| 192 | const retry_z = try allocator.dupeSentinel(u8, path, 0); | |
| 193 | 193 | defer allocator.free(retry_z); |
| 194 | 194 | const rc2 = std.c.mkdir(retry_z, 0o755); |
| 195 | 195 | if (rc2 != 0 and std.c.errno(rc2) != .EXIST) { |
| @@ -298,7 +298,7 @@ pub fn spawnAndWait( | ||
| 298 | 298 | defer allocator.free(c_argv); |
| 299 | 299 | |
| 300 | 300 | for (argv, 0..) |arg, i| { |
| 301 | const z = try allocator.dupeZ(u8, arg); | |
| 301 | const z = try allocator.dupeSentinel(u8, arg, 0); | |
| 302 | 302 | c_argv[i] = z.ptr; |
| 303 | 303 | } |
| 304 | 304 | c_argv[argv.len] = null; |
| @@ -251,16 +251,16 @@ pub const Snapshot = struct { | ||
| 251 | 251 | }, |
| 252 | 252 | .@"struct" => { |
| 253 | 253 | try writer.writeAll("{\n"); |
| 254 | inline for (type_info.@"struct".fields, 0..) |field, i| { | |
| 254 | inline for (type_info.@"struct".field_names, 0..) |field_name, i| { | |
| 255 | 255 | if (self.options.pretty_print) { |
| 256 | 256 | try writer.writeAll(" "); |
| 257 | 257 | } |
| 258 | try writer.print("\"{s}\": ", .{field.name}); | |
| 258 | try writer.print("\"{s}\": ", .{field_name}); | |
| 259 | 259 | |
| 260 | const field_value = @field(value, field.name); | |
| 260 | const field_value = @field(value, field_name); | |
| 261 | 261 | try self.formatJsonValue(writer, field_value); |
| 262 | 262 | |
| 263 | if (i < type_info.@"struct".fields.len - 1) { | |
| 263 | if (i < type_info.@"struct".field_names.len - 1) { | |
| 264 | 264 | try writer.writeAll(","); |
| 265 | 265 | } |
| 266 | 266 | if (self.options.pretty_print) { |
| @@ -307,10 +307,10 @@ pub const Snapshot = struct { | ||
| 307 | 307 | |
| 308 | 308 | try writer.writeAll("{\n"); |
| 309 | 309 | |
| 310 | inline for (type_info.@"struct".fields, 0..) |field, i| { | |
| 311 | try writer.print(" \"{s}\": ", .{field.name}); | |
| 310 | inline for (type_info.@"struct".field_names, 0..) |field_name, i| { | |
| 311 | try writer.print(" \"{s}\": ", .{field_name}); | |
| 312 | 312 | |
| 313 | const field_value = @field(value, field.name); | |
| 313 | const field_value = @field(value, field_name); | |
| 314 | 314 | const FieldType = @TypeOf(field_value); |
| 315 | 315 | const field_info = @typeInfo(FieldType); |
| 316 | 316 | |
| @@ -328,7 +328,7 @@ pub const Snapshot = struct { | ||
| 328 | 328 | else => try writer.print("{any}", .{field_value}), |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | if (i < type_info.@"struct".fields.len - 1) { | |
| 331 | if (i < type_info.@"struct".field_names.len - 1) { | |
| 332 | 332 | try writer.writeAll(",\n"); |
| 333 | 333 | } else { |
| 334 | 334 | try writer.writeAll("\n"); |