| ... | @@ -509,3 +509,55 @@ test "no file inputs" { | ... | @@ -509,3 +509,55 @@ test "no file inputs" { |
| 509 | | 509 | |
| 510 | testing.expectEqual(digest1, digest2); | 510 | testing.expectEqual(digest1, digest2); |
| 511 | } | 511 | } |
| | 512 | |
| | 513 | test "manifest file with extra line does not cause null pointer exeception" { |
| | 514 | const cwd = fs.cwd(); |
| | 515 | |
| | 516 | const temp_file1 = "cache_hash_remove_file_test1.txt"; |
| | 517 | const temp_file2 = "cache_hash_remove_file_test2.txt"; |
| | 518 | const temp_manifest_dir = "cache_hash_remove_file_manifest_dir"; |
| | 519 | |
| | 520 | try cwd.writeFile(temp_file1, "Hello, world!\n"); |
| | 521 | try cwd.writeFile(temp_file2, "Hello world the second!\n"); |
| | 522 | |
| | 523 | var digest1: [BASE64_DIGEST_LEN]u8 = undefined; |
| | 524 | var digest2: [BASE64_DIGEST_LEN]u8 = undefined; |
| | 525 | |
| | 526 | { |
| | 527 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| | 528 | defer ch.release() catch unreachable; |
| | 529 | |
| | 530 | ch.add("1234"); |
| | 531 | _ = try ch.addFile(temp_file1); |
| | 532 | _ = try ch.addFile(temp_file2); |
| | 533 | |
| | 534 | // There should be nothing in the cache |
| | 535 | testing.expectEqual(@as(?[64]u8, null), try ch.hit()); |
| | 536 | |
| | 537 | digest1 = ch.final(); |
| | 538 | } |
| | 539 | { |
| | 540 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| | 541 | defer ch.release() catch unreachable; |
| | 542 | |
| | 543 | ch.add("1234"); |
| | 544 | _ = try ch.addFile(temp_file1); |
| | 545 | _ = try ch.addFile(temp_file2); |
| | 546 | { |
| | 547 | // Remove an input file from the cache hash. |
| | 548 | // We still have to add the input file, or else the initial cache |
| | 549 | // hash will be different, and a different manifest file checked |
| | 550 | const chf = ch.files.orderedRemove(1); |
| | 551 | testing.allocator.free(chf.path.?); |
| | 552 | } |
| | 553 | |
| | 554 | // A file that we depend on has been updated, so the cache should not contain an entry for it |
| | 555 | digest2 = (try ch.hit()).?; |
| | 556 | } |
| | 557 | |
| | 558 | testing.expect(mem.eql(u8, digest1[0..], digest2[0..])); |
| | 559 | |
| | 560 | try cwd.deleteTree(temp_manifest_dir); |
| | 561 | try cwd.deleteFile(temp_file1); |
| | 562 | try cwd.deleteFile(temp_file2); |
| | 563 | } |