@@ -45,7 +45,7 @@ pub const AssertionDiagnostic = struct {
4545
4646 pub fn init (allocator : Allocator ) AssertionDiagnostic {
4747 return .{
48- .failures = ArrayList ( AssertionFailure ). init ( allocator ) ,
48+ .failures = .empty ,
4949 .allocator = allocator ,
5050 };
5151 }
@@ -54,7 +54,7 @@ pub const AssertionDiagnostic = struct {
5454 for (self .failures .items ) | * failure | {
5555 failure .deinit (self .allocator );
5656 }
57- self .failures .deinit ();
57+ self .failures .deinit (self . allocator );
5858 }
5959
6060 pub fn addFailure (
@@ -76,7 +76,7 @@ pub const AssertionDiagnostic = struct {
7676 .assertion_index = assertion_index ,
7777 .source_file = if (source_file ) | file | try self .allocator .dupe (u8 , file ) else null ,
7878 };
79- try self .failures .append (failure );
79+ try self .failures .append (self . allocator , failure );
8080 }
8181};
8282
@@ -86,16 +86,16 @@ pub fn hasFailures(diagnostic: *const AssertionDiagnostic) bool {
8686
8787pub fn reportFailures (diagnostic : * const AssertionDiagnostic , writer : anytype ) ! void {
8888 for (diagnostic .failures .items ) | failure | {
89- const source_info = if (failure .source_file ) | file |
89+ const source_info = if (failure .source_file ) | file |
9090 try std .fmt .allocPrint (diagnostic .allocator , " in {s}:{d}" , .{ file , failure .assertion_index + 1 })
91- else
92- try std .fmt .allocPrint (diagnostic .allocator , " (assertion #{d})" , .{ failure .assertion_index + 1 });
91+ else
92+ try std .fmt .allocPrint (diagnostic .allocator , " (assertion #{d})" , .{failure .assertion_index + 1 });
9393 defer diagnostic .allocator .free (source_info );
9494
9595 switch (failure .reason ) {
9696 .status_mismatch = > try writer .print ("[Fail]{s} Expected status {s}, got {s}\n " , .{ source_info , failure .expected , failure .actual }),
97- .header_mismatch = > try writer .print ("[Fail]{s} Expected header \" {s}\" to be \" {s}\" , got \" {s}\" \n " , .{ source_info , failure .assertion_key [8.. failure .assertion_key .len - 2 ], failure .expected , failure .actual }),
98- .header_missing = > try writer .print ("[Fail]{s} Expected header \" {s}\" to be \" {s}\" , but header was missing\n " , .{ source_info , failure .assertion_key [8.. failure .assertion_key .len - 2 ], failure .expected }),
97+ .header_mismatch = > try writer .print ("[Fail]{s} Expected header \" {s}\" to be \" {s}\" , got \" {s}\" \n " , .{ source_info , failure .assertion_key [8 .. failure .assertion_key .len - 2 ], failure .expected , failure .actual }),
98+ .header_missing = > try writer .print ("[Fail]{s} Expected header \" {s}\" to be \" {s}\" , but header was missing\n " , .{ source_info , failure .assertion_key [8 .. failure .assertion_key .len - 2 ], failure .expected }),
9999 .body_mismatch = > try writer .print ("[Fail]{s} Expected body \" {s}\" , got \" {s}\" \n " , .{ source_info , failure .expected , failure .actual }),
100100 .contains_failed = > try writer .print ("[Fail]{s} Expected {s} to contain \" {s}\" , got \" {s}\" \n " , .{ source_info , failure .assertion_key , failure .expected , failure .actual }),
101101 .not_contains_failed = > try writer .print ("[Fail]{s} Expected {s} to NOT contain \" {s}\" , got \" {s}\" \n " , .{ source_info , failure .assertion_key , failure .expected , failure .actual }),
@@ -123,10 +123,9 @@ fn matchesRegex(text: []const u8, pattern: []const u8) bool {
123123 return compiled_regex .match (text ) catch return false ;
124124}
125125
126-
127126pub fn check (
128- request : * HttpParser.HttpRequest ,
129- response : Client.HttpResponse ,
127+ request : * HttpParser.HttpRequest ,
128+ response : Client.HttpResponse ,
130129 diagnostic : * AssertionDiagnostic ,
131130 source_file : ? []const u8 ,
132131) void {
@@ -292,7 +291,6 @@ fn checkAssertion(
292291 }
293292}
294293
295-
296294test "Assertion checker with diagnostics - all pass" {
297295 const allocator = std .testing .allocator ;
298296
@@ -346,9 +344,9 @@ test "Assertion checker with diagnostics - all pass" {
346344
347345 var diagnostic = AssertionDiagnostic .init (allocator );
348346 defer diagnostic .deinit ();
349-
347+
350348 check (& request , response , & diagnostic , "test.httpspec" );
351-
349+
352350 try std .testing .expect (! hasFailures (& diagnostic ));
353351 try std .testing .expectEqual (@as (usize , 0 ), diagnostic .failures .items .len );
354352}
@@ -400,9 +398,9 @@ test "Assertion checker with not_equal - all pass" {
400398
401399 var diagnostic = AssertionDiagnostic .init (allocator );
402400 defer diagnostic .deinit ();
403-
401+
404402 check (& request , response , & diagnostic , "test.httpspec" );
405-
403+
406404 try std .testing .expect (! hasFailures (& diagnostic ));
407405 try std .testing .expectEqual (@as (usize , 0 ), diagnostic .failures .items .len );
408406}
@@ -454,12 +452,12 @@ test "Assertion checker with failures - collects all failures" {
454452
455453 var diagnostic = AssertionDiagnostic .init (allocator );
456454 defer diagnostic .deinit ();
457-
455+
458456 check (& request , response , & diagnostic , "test.httpspec" );
459-
457+
460458 try std .testing .expect (hasFailures (& diagnostic ));
461459 try std .testing .expectEqual (@as (usize , 3 ), diagnostic .failures .items .len );
462-
460+
463461 try std .testing .expectEqual (FailureReason .status_mismatch , diagnostic .failures .items [0 ].reason );
464462 try std .testing .expectEqual (FailureReason .body_mismatch , diagnostic .failures .items [1 ].reason );
465463 try std .testing .expectEqual (FailureReason .header_mismatch , diagnostic .failures .items [2 ].reason );
@@ -512,9 +510,9 @@ test "HttpParser supports starts_with for status, body, and header" {
512510
513511 var diagnostic = AssertionDiagnostic .init (allocator );
514512 defer diagnostic .deinit ();
515-
513+
516514 check (& request , response , & diagnostic , "test.httpspec" );
517-
515+
518516 try std .testing .expect (! hasFailures (& diagnostic ));
519517}
520518
@@ -575,9 +573,9 @@ test "HttpParser supports matches_regex and not_matches_regex for status, body,
575573
576574 var diagnostic = AssertionDiagnostic .init (allocator );
577575 defer diagnostic .deinit ();
578-
576+
579577 check (& request , response , & diagnostic , "test.httpspec" );
580-
578+
581579 try std .testing .expect (! hasFailures (& diagnostic ));
582580}
583581
@@ -624,8 +622,8 @@ test "HttpParser supports contains and not_contains for headers" {
624622
625623 var diagnostic = AssertionDiagnostic .init (allocator );
626624 defer diagnostic .deinit ();
627-
625+
628626 check (& request , response , & diagnostic , "test.httpspec" );
629-
627+
630628 try std .testing .expect (! hasFailures (& diagnostic ));
631629}
0 commit comments