| ... | ... | @@ -398,6 +398,8 @@ const TestIterator = struct { |
| 398 | 398 | start: usize = 0, |
| 399 | 399 | end: usize = 0, |
| 400 | 400 | filenames: []const []const u8, |
| 401 | /// reset on each call to `next` |
| 402 | index: usize = 0, |
| 401 | 403 | |
| 402 | 404 | const Error = error{InvalidIncrementalTestIndex}; |
| 403 | 405 | |
| ... | ... | @@ -416,12 +418,12 @@ const TestIterator = struct { |
| 416 | 418 | } |
| 417 | 419 | |
| 418 | 420 | const remaining = it.filenames[it.end..]; |
| 419 | | var i: usize = 0; |
| 420 | | while (i < remaining.len - 1) : (i += 1) { |
| 421 | it.index = 0; |
| 422 | while (it.index < remaining.len - 1) : (it.index += 1) { |
| 421 | 423 | // First, check if this file is part of an incremental update sequence |
| 422 | 424 | // Split filename into "<base_name>.<index>.<file_ext>" |
| 423 | | const prev_parts = getTestFileNameParts(remaining[i]); |
| 424 | | const new_parts = getTestFileNameParts(remaining[i + 1]); |
| 425 | const prev_parts = getTestFileNameParts(remaining[it.index]); |
| 426 | const new_parts = getTestFileNameParts(remaining[it.index + 1]); |
| 425 | 427 | |
| 426 | 428 | // If base_name and file_ext match, these files are in the same test sequence |
| 427 | 429 | // and the new one should be the incremented version of the previous test |
| ... | ... | @@ -441,13 +443,22 @@ const TestIterator = struct { |
| 441 | 443 | if (new_parts.test_index != null and new_parts.test_index.? != 0) |
| 442 | 444 | return error.InvalidIncrementalTestIndex; |
| 443 | 445 | |
| 444 | | it.end += i + 1; |
| 446 | it.end += it.index + 1; |
| 445 | 447 | break; |
| 446 | 448 | } |
| 447 | 449 | } else { |
| 448 | 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 | 464 | /// For a filename in the format "<filename>.X.<ext>" or "<filename>.<ext>", returns |
| ... | ... | @@ -1051,7 +1062,8 @@ pub const TestContext = struct { |
| 1051 | 1062 | sortTestFilenames(filenames.items); |
| 1052 | 1063 | |
| 1053 | 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 | 1067 | const strategy: TestStrategy = if (batch.len > 1) .incremental else .independent; |
| 1056 | 1068 | var cases = std.ArrayList(usize).init(ctx.arena); |
| 1057 | 1069 | |
| ... | ... | @@ -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 | |