| ... | @@ -398,6 +398,8 @@ const TestIterator = struct { | ... | @@ -398,6 +398,8 @@ const TestIterator = struct { |
| 398 | start: usize = 0, | 398 | start: usize = 0, |
| 399 | end: usize = 0, | 399 | end: usize = 0, |
| 400 | filenames: []const []const u8, | 400 | filenames: []const []const u8, |
| | 401 | /// reset on each call to `next` |
| | 402 | index: usize = 0, |
| 401 | | 403 | |
| 402 | const Error = error{InvalidIncrementalTestIndex}; | 404 | const Error = error{InvalidIncrementalTestIndex}; |
| 403 | | 405 | |
| ... | @@ -416,12 +418,12 @@ const TestIterator = struct { | ... | @@ -416,12 +418,12 @@ const TestIterator = struct { |
| 416 | } | 418 | } |
| 417 | | 419 | |
| 418 | const remaining = it.filenames[it.end..]; | 420 | const remaining = it.filenames[it.end..]; |
| 419 | var i: usize = 0; | 421 | it.index = 0; |
| 420 | while (i < remaining.len - 1) : (i += 1) { | 422 | while (it.index < remaining.len - 1) : (it.index += 1) { |
| 421 | // First, check if this file is part of an incremental update sequence | 423 | // First, check if this file is part of an incremental update sequence |
| 422 | // Split filename into "<base_name>.<index>.<file_ext>" | 424 | // Split filename into "<base_name>.<index>.<file_ext>" |
| 423 | const prev_parts = getTestFileNameParts(remaining[i]); | 425 | const prev_parts = getTestFileNameParts(remaining[it.index]); |
| 424 | const new_parts = getTestFileNameParts(remaining[i + 1]); | 426 | const new_parts = getTestFileNameParts(remaining[it.index + 1]); |
| 425 | | 427 | |
| 426 | // If base_name and file_ext match, these files are in the same test sequence | 428 | // If base_name and file_ext match, these files are in the same test sequence |
| 427 | // and the new one should be the incremented version of the previous test | 429 | // and the new one should be the incremented version of the previous test |
| ... | @@ -441,13 +443,22 @@ const TestIterator = struct { | ... | @@ -441,13 +443,22 @@ const TestIterator = struct { |
| 441 | if (new_parts.test_index != null and new_parts.test_index.? != 0) | 443 | if (new_parts.test_index != null and new_parts.test_index.? != 0) |
| 442 | return error.InvalidIncrementalTestIndex; | 444 | return error.InvalidIncrementalTestIndex; |
| 443 | | 445 | |
| 444 | it.end += i + 1; | 446 | it.end += it.index + 1; |
| 445 | break; | 447 | break; |
| 446 | } | 448 | } |
| 447 | } else { | 449 | } else { |
| 448 | it.end += remaining.len; | 450 | it.end += remaining.len; |
| 449 | } | 451 | } |
| 450 | } | 452 | } |
| | 453 | |
| | 454 | /// In the event of an `error.InvalidIncrementalTestIndex`, this function can |
| | 455 | /// be used to find the current filename that was being processed. |
| | 456 | /// Asserts the iterator hasn't reached the end. |
| | 457 | fn currentFilename(it: TestIterator) []const u8 { |
| | 458 | assert(it.end != it.filenames.len); |
| | 459 | const remaining = it.filenames[it.end..]; |
| | 460 | return remaining[it.index + 1]; |
| | 461 | } |
| 451 | }; | 462 | }; |
| 452 | | 463 | |
| 453 | /// For a filename in the format "<filename>.X.<ext>" or "<filename>.<ext>", returns | 464 | /// For a filename in the format "<filename>.X.<ext>" or "<filename>.<ext>", returns |
| ... | @@ -1051,7 +1062,8 @@ pub const TestContext = struct { | ... | @@ -1051,7 +1062,8 @@ pub const TestContext = struct { |
| 1051 | sortTestFilenames(filenames.items); | 1062 | sortTestFilenames(filenames.items); |
| 1052 | | 1063 | |
| 1053 | var test_it = TestIterator{ .filenames = filenames.items }; | 1064 | var test_it = TestIterator{ .filenames = filenames.items }; |
| 1054 | while (try test_it.next()) |batch| { | 1065 | while (test_it.next()) |maybe_batch| { |
| | 1066 | const batch = maybe_batch orelse break; |
| 1055 | const strategy: TestStrategy = if (batch.len > 1) .incremental else .independent; | 1067 | const strategy: TestStrategy = if (batch.len > 1) .incremental else .independent; |
| 1056 | var cases = std.ArrayList(usize).init(ctx.arena); | 1068 | var cases = std.ArrayList(usize).init(ctx.arena); |
| 1057 | | 1069 | |
| ... | @@ -1133,6 +1145,10 @@ pub const TestContext = struct { | ... | @@ -1133,6 +1145,10 @@ pub const TestContext = struct { |
| 1133 | } | 1145 | } |
| 1134 | } | 1146 | } |
| 1135 | } | 1147 | } |
| | 1148 | } else |err| { |
| | 1149 | // make sure the current file is set to the file that produced an error |
| | 1150 | current_file.* = test_it.currentFilename(); |
| | 1151 | return err; |
| 1136 | } | 1152 | } |
| 1137 | } | 1153 | } |
| 1138 | | 1154 | |