Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ pub fn build(b: *std.Build) void {
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());

if (b.args) |args| {
run_cmd.addArgs(args);
}
run_cmd.addPassthruArgs();

const run_step = b.step("run", "Run the test framework");
run_step.dependOn(&run_cmd.step);
Expand Down
12 changes: 6 additions & 6 deletions src/compat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn closeFd(fd: std.posix.fd_t) void {
/// Read entire file contents using POSIX APIs.
/// Replaces std.fs.cwd().openFile() + file.readToEndAlloc().
pub fn readFileAlloc(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const path_z = try allocator.dupeZ(u8, path);
const path_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(path_z);

const fd = std.posix.openatZ(std.posix.AT.FDCWD, path_z, .{}, 0) catch |err| {
Expand All @@ -139,7 +139,7 @@ pub fn readFileAlloc(allocator: std.mem.Allocator, path: []const u8) ![]const u8
/// Write content to a file using POSIX APIs.
/// Replaces std.fs.cwd().createFile() + file.writeAll().
pub fn writeFile(allocator: std.mem.Allocator, path: []const u8, content: []const u8) !void {
const path_z = try allocator.dupeZ(u8, path);
const path_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(path_z);

const fd = std.posix.openatZ(std.posix.AT.FDCWD, path_z, .{
Expand All @@ -161,7 +161,7 @@ pub fn writeFile(allocator: std.mem.Allocator, path: []const u8, content: []cons
/// Delete a file using POSIX APIs.
/// Replaces std.fs.cwd().deleteFile().
pub fn deleteFile(allocator: std.mem.Allocator, path: []const u8) !void {
const path_z = try allocator.dupeZ(u8, path);
const path_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(path_z);
const rc = std.c.unlink(path_z);
if (rc != 0) {
Expand All @@ -175,7 +175,7 @@ pub fn deleteFile(allocator: std.mem.Allocator, path: []const u8) !void {
/// Create directories recursively using POSIX APIs.
/// Replaces std.fs.cwd().makePath().
pub fn makePath(allocator: std.mem.Allocator, path: []const u8) !void {
const path_z = try allocator.dupeZ(u8, path);
const path_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(path_z);

const rc = std.c.mkdir(path_z, 0o755);
Expand All @@ -189,7 +189,7 @@ pub fn makePath(allocator: std.mem.Allocator, path: []const u8) !void {
if (sep > 0) {
try makePath(allocator, path[0..sep]);
// Retry creating the directory
const retry_z = try allocator.dupeZ(u8, path);
const retry_z = try allocator.dupeSentinel(u8, path, 0);
defer allocator.free(retry_z);
const rc2 = std.c.mkdir(retry_z, 0o755);
if (rc2 != 0 and std.c.errno(rc2) != .EXIST) {
Expand Down Expand Up @@ -298,7 +298,7 @@ pub fn spawnAndWait(
defer allocator.free(c_argv);

for (argv, 0..) |arg, i| {
const z = try allocator.dupeZ(u8, arg);
const z = try allocator.dupeSentinel(u8, arg, 0);
c_argv[i] = z.ptr;
}
c_argv[argv.len] = null;
Expand Down
16 changes: 8 additions & 8 deletions src/snapshot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ pub const Snapshot = struct {
},
.@"struct" => {
try writer.writeAll("{\n");
inline for (type_info.@"struct".fields, 0..) |field, i| {
inline for (type_info.@"struct".field_names, 0..) |field_name, i| {
if (self.options.pretty_print) {
try writer.writeAll(" ");
}
try writer.print("\"{s}\": ", .{field.name});
try writer.print("\"{s}\": ", .{field_name});

const field_value = @field(value, field.name);
const field_value = @field(value, field_name);
try self.formatJsonValue(writer, field_value);

if (i < type_info.@"struct".fields.len - 1) {
if (i < type_info.@"struct".field_names.len - 1) {
try writer.writeAll(",");
}
if (self.options.pretty_print) {
Expand Down Expand Up @@ -307,10 +307,10 @@ pub const Snapshot = struct {

try writer.writeAll("{\n");

inline for (type_info.@"struct".fields, 0..) |field, i| {
try writer.print(" \"{s}\": ", .{field.name});
inline for (type_info.@"struct".field_names, 0..) |field_name, i| {
try writer.print(" \"{s}\": ", .{field_name});

const field_value = @field(value, field.name);
const field_value = @field(value, field_name);
const FieldType = @TypeOf(field_value);
const field_info = @typeInfo(FieldType);

Expand All @@ -328,7 +328,7 @@ pub const Snapshot = struct {
else => try writer.print("{any}", .{field_value}),
}

if (i < type_info.@"struct".fields.len - 1) {
if (i < type_info.@"struct".field_names.len - 1) {
try writer.writeAll(",\n");
} else {
try writer.writeAll("\n");
Expand Down
Loading