@@ -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 ("\n EXPECTED: {s}\n\n ACTUAL: {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 ("\n EXPECTED: {s}\n\n ACTUAL: {s}\n " , .{ expected_error , stderr .written () });
250252 return err ;
251253 };
252254}
253255
254256pub 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
319323pub 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
351357pub 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 };
0 commit comments