Skip to content

Commit 5f22cab

Browse files
committed
update to zig 0.15.1
1 parent 52ff473 commit 5f22cab

File tree

12 files changed

+87
-69
lines changed

12 files changed

+87
-69
lines changed

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
.version = "0.3.0",
88

9-
.minimum_zig_version = "0.15.0-dev.1149+4e6a04929",
9+
.minimum_zig_version = "0.15.1",
1010

1111
.paths = .{
1212
"build.zig",

src/Command.zig

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ pub fn testExecute(
192192
) ExposedError!void {
193193
std.debug.assert(builtin.is_test);
194194

195+
const allocator = std.testing.allocator;
196+
195197
const system: System = .{
196198
._backend = System.TestBackend.create(
197-
std.testing.allocator,
199+
allocator,
198200
settings.system_description,
199201
) catch |err| {
200202
std.debug.panic("unable to create system backend: {t}", .{err});
@@ -214,7 +216,7 @@ pub fn testExecute(
214216
};
215217

216218
return command.execute(
217-
std.testing.allocator,
219+
allocator,
218220
io,
219221
&arg_iter,
220222
system,
@@ -240,69 +242,71 @@ pub fn testError(
240242
var settings_copy = settings;
241243
settings_copy.stderr = &stderr.writer;
242244

243-
try std.testing.expectError(error.AlreadyHandled, command.testExecute(
244-
arguments,
245-
settings_copy,
246-
));
245+
try std.testing.expectError(
246+
error.AlreadyHandled,
247+
command.testExecute(arguments, settings_copy),
248+
);
247249

248-
std.testing.expect(std.mem.indexOf(u8, stderr.getWritten(), expected_error) != null) catch |err| {
249-
std.debug.print("\nEXPECTED: {s}\n\nACTUAL: {s}\n", .{ expected_error, stderr.getWritten() });
250+
std.testing.expect(std.mem.indexOf(u8, stderr.written(), expected_error) != null) catch |err| {
251+
std.debug.print("\nEXPECTED: {s}\n\nACTUAL: {s}\n", .{ expected_error, stderr.written() });
250252
return err;
251253
};
252254
}
253255

254256
pub fn testHelp(command: Command, comptime include_shorthand: bool) !void {
255257
std.debug.assert(builtin.is_test);
256258

259+
const allocator = std.testing.allocator;
260+
257261
const full_expected_help = blk: {
258262
var sb: std.ArrayListUnmanaged(u8) = .empty;
259-
errdefer sb.deinit(std.testing.allocator);
263+
errdefer sb.deinit(allocator);
260264

261265
var iter: NameReplacementIterator = .{ .slice = command.short_help };
262266
while (iter.next()) |result| {
263-
try sb.appendSlice(std.testing.allocator, result.slice);
267+
try sb.appendSlice(allocator, result.slice);
264268
if (result.output_name) {
265-
try sb.appendSlice(std.testing.allocator, command.name);
269+
try sb.appendSlice(allocator, command.name);
266270
}
267271
}
268272

269273
if (!std.mem.eql(u8, command.name, "template")) { // template has an extended help but it is empty
270274
if (command.extended_help) |extended_help| {
271-
try sb.append(std.testing.allocator, '\n');
272-
try sb.appendSlice(std.testing.allocator, extended_help);
275+
try sb.append(allocator, '\n');
276+
try sb.appendSlice(allocator, extended_help);
273277
}
274278
}
275279

276-
break :blk try sb.toOwnedSlice(std.testing.allocator);
280+
break :blk try sb.toOwnedSlice(allocator);
277281
};
278-
defer std.testing.allocator.free(full_expected_help);
282+
defer allocator.free(full_expected_help);
279283

280-
var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator);
284+
var stdout: std.Io.Writer.Allocating = .init(allocator);
281285
defer stdout.deinit();
282286

283287
try command.testExecute(
284288
&.{"--help"},
285289
.{ .stdout = &stdout.writer },
286290
);
287291

288-
try std.testing.expectEqualStrings(full_expected_help, stdout.getWritten());
292+
try std.testing.expectEqualStrings(full_expected_help, stdout.written());
289293

290294
if (include_shorthand) {
291295
const short_expected_help = blk: {
292296
var sb: std.ArrayListUnmanaged(u8) = .empty;
293-
errdefer sb.deinit(std.testing.allocator);
297+
errdefer sb.deinit(allocator);
294298

295299
var iter: NameReplacementIterator = .{ .slice = command.short_help };
296300
while (iter.next()) |result| {
297-
try sb.appendSlice(std.testing.allocator, result.slice);
301+
try sb.appendSlice(allocator, result.slice);
298302
if (result.output_name) {
299-
try sb.appendSlice(std.testing.allocator, command.name);
303+
try sb.appendSlice(allocator, command.name);
300304
}
301305
}
302306

303-
break :blk try sb.toOwnedSlice(std.testing.allocator);
307+
break :blk try sb.toOwnedSlice(allocator);
304308
};
305-
defer std.testing.allocator.free(short_expected_help);
309+
defer allocator.free(short_expected_help);
306310

307311
stdout.clearRetainingCapacity();
308312

@@ -312,14 +316,16 @@ pub fn testHelp(command: Command, comptime include_shorthand: bool) !void {
312316
.{ .stdout = &stdout.writer },
313317
);
314318

315-
try std.testing.expectEqualStrings(short_expected_help, stdout.getWritten());
319+
try std.testing.expectEqualStrings(short_expected_help, stdout.written());
316320
}
317321
}
318322

319323
pub fn testVersion(command: Command) !void {
320324
std.debug.assert(builtin.is_test);
321325

322-
var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator);
326+
const allocator = std.testing.allocator;
327+
328+
var stdout: std.Io.Writer.Allocating = .init(allocator);
323329
defer stdout.deinit();
324330

325331
try command.testExecute(
@@ -331,21 +337,21 @@ pub fn testVersion(command: Command) !void {
331337

332338
const expected = blk: {
333339
var sb: std.ArrayListUnmanaged(u8) = .empty;
334-
errdefer sb.deinit(std.testing.allocator);
340+
errdefer sb.deinit(allocator);
335341

336342
var iter: NameReplacementIterator = .{ .slice = shared.version_string };
337343
while (iter.next()) |result| {
338-
try sb.appendSlice(std.testing.allocator, result.slice);
344+
try sb.appendSlice(allocator, result.slice);
339345
if (result.output_name) {
340-
try sb.appendSlice(std.testing.allocator, command.name);
346+
try sb.appendSlice(allocator, command.name);
341347
}
342348
}
343349

344-
break :blk try sb.toOwnedSlice(std.testing.allocator);
350+
break :blk try sb.toOwnedSlice(allocator);
345351
};
346-
defer std.testing.allocator.free(expected);
352+
defer allocator.free(expected);
347353

348-
try std.testing.expectEqualStrings(expected, stdout.getWritten());
354+
try std.testing.expectEqualStrings(expected, stdout.written());
349355
}
350356

351357
pub const TestFuzzOptions = struct {
@@ -368,24 +374,26 @@ pub fn testFuzz(command: Command, options: TestFuzzOptions) !void {
368374
options: TestFuzzOptions,
369375

370376
fn testOne(context: @This(), input: []const u8) anyerror!void {
377+
const allocator = std.testing.allocator;
378+
371379
const arguments = blk: {
372-
var arguments: std.ArrayList([]const u8) = .init(std.testing.allocator);
373-
errdefer arguments.deinit();
380+
var arguments: std.ArrayList([]const u8) = .empty;
381+
errdefer arguments.deinit(allocator);
374382

375383
var iter = std.mem.splitScalar(u8, input, ' ');
376384

377385
while (iter.next()) |arg| {
378-
try arguments.append(arg);
386+
try arguments.append(allocator, arg);
379387
}
380388

381-
break :blk try arguments.toOwnedSlice();
389+
break :blk try arguments.toOwnedSlice(allocator);
382390
};
383-
defer std.testing.allocator.free(arguments);
391+
defer allocator.free(arguments);
384392

385-
var stdout: std.Io.Writer.Allocating = .init(std.testing.allocator);
393+
var stdout: std.Io.Writer.Allocating = .init(allocator);
386394
defer stdout.deinit();
387395

388-
var stderr: std.Io.Writer.Allocating = .init(std.testing.allocator);
396+
var stderr: std.Io.Writer.Allocating = .init(allocator);
389397
defer stderr.deinit();
390398

391399
context.inner_command.testExecute(
@@ -401,15 +409,15 @@ pub fn testFuzz(command: Command, options: TestFuzzOptions) !void {
401409
// this error is output by main and some output may or not have been written to stderr
402410
},
403411
error.AlreadyHandled => if (context.options.expect_stderr_output_on_failure) {
404-
try std.testing.expect(stderr.getWritten().len != 0);
412+
try std.testing.expect(stderr.written().len != 0);
405413
},
406414
}
407415
return;
408416
};
409417

410-
try std.testing.expect(stderr.getWritten().len == 0);
418+
try std.testing.expect(stderr.written().len == 0);
411419
if (context.options.expect_stdout_output_on_success) {
412-
try std.testing.expect(stdout.getWritten().len != 0);
420+
try std.testing.expect(stdout.written().len != 0);
413421
}
414422
}
415423
};

src/commands/basename.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ const impl = struct {
317317
.{ .stdout = &stdout.writer },
318318
);
319319

320-
try std.testing.expectEqualStrings("world\n", stdout.getWritten());
320+
try std.testing.expectEqualStrings("world\n", stdout.written());
321321
}
322322

323323
test "basename multiple" {
@@ -339,7 +339,7 @@ const impl = struct {
339339
\\test
340340
\\d
341341
\\
342-
, stdout.getWritten());
342+
, stdout.written());
343343
}
344344

345345
test "basename help" {

src/commands/clear.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const impl = struct {
150150
.{ .stdout = &stdout.writer },
151151
);
152152

153-
try std.testing.expectEqualStrings("\x1b[H\x1b[2J\x1b[3J", stdout.getWritten());
153+
try std.testing.expectEqualStrings("\x1b[H\x1b[2J\x1b[3J", stdout.written());
154154
}
155155

156156
test "clear - don't clear scrollback" {
@@ -162,7 +162,7 @@ const impl = struct {
162162
.{ .stdout = &stdout.writer },
163163
);
164164

165-
try std.testing.expectEqualStrings("\x1b[H\x1b[2J", stdout.getWritten());
165+
try std.testing.expectEqualStrings("\x1b[H\x1b[2J", stdout.written());
166166
}
167167

168168
test "clear help" {

src/commands/dirname.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const impl = struct {
191191
.{ .stdout = &stdout.writer },
192192
);
193193

194-
try std.testing.expectEqualStrings("hello\n", stdout.getWritten());
194+
try std.testing.expectEqualStrings("hello\n", stdout.written());
195195
}
196196

197197
test "dirname multiple" {
@@ -212,7 +212,7 @@ const impl = struct {
212212
\\this/is/a
213213
\\a/b/c
214214
\\
215-
, stdout.getWritten());
215+
, stdout.written());
216216
}
217217

218218
test "dirname help" {

src/commands/false.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const impl = struct {
6060
),
6161
);
6262

63-
try std.testing.expectEqualStrings("", stdout.getWritten());
63+
try std.testing.expectEqualStrings("", stdout.written());
6464
}
6565

6666
test "false help" {

src/commands/groups.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ const impl = struct {
291291
},
292292
});
293293

294-
try std.testing.expectEqualStrings("sys user wheel\n", stdout.getWritten());
294+
try std.testing.expectEqualStrings("sys user wheel\n", stdout.written());
295295
}
296296
};
297297

src/commands/nproc.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const impl = struct {
127127
},
128128
});
129129

130-
try std.testing.expectEqualStrings("16\n", stdout.getWritten());
130+
try std.testing.expectEqualStrings("16\n", stdout.written());
131131
}
132132
};
133133

src/commands/true.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const impl = struct {
5656
.{ .stdout = &stdout.writer },
5757
);
5858

59-
try std.testing.expectEqualStrings("", stdout.getWritten());
59+
try std.testing.expectEqualStrings("", stdout.written());
6060
}
6161

6262
test "true help" {

src/commands/uname.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ const impl = struct {
395395
else
396396
"sysname nodename release version machine sysname\n";
397397

398-
try std.testing.expectEqualStrings(expected, stdout.getWritten());
398+
try std.testing.expectEqualStrings(expected, stdout.written());
399399
}
400400
};
401401

0 commit comments

Comments
 (0)