authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-30 19:47:04-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
loge6a37ed94193faf6450a0888c23168a83e914955
treed185e3c818da7e1aed100c38b92285b60f103f6b
parent42007307bed84ba691b86e17b6e414eef352e94c

Change null pointer test to `addFilePost` test


1 files changed, 32 insertions(+), 13 deletions(-)

lib/std/cache_hash.zig+32-13
......@@ -232,7 +232,13 @@ pub const CacheHash = struct {
232232 // reset the hash
233233 self.blake3 = Blake3.init();
234234 self.blake3.update(&bin_digest);
235
236 // Remove files not in the initial hash
237 for (self.files.items[input_file_count..]) |*file| {
238 file.deinit(self.alloc);
239 }
235240 try self.files.resize(input_file_count);
241
236242 for (self.files.items) |file| {
237243 self.blake3.update(&file.bin_digest);
238244 }
......@@ -512,18 +518,19 @@ test "no file inputs" {
512518 testing.expectEqual(digest1, digest2);
513519}
514520
515test "manifest file with extra line does not cause null pointer exeception" {
521test "CacheHashes with files added after initial hash work" {
516522 const cwd = fs.cwd();
517523
518 const temp_file1 = "cache_hash_remove_file_test1.txt";
519 const temp_file2 = "cache_hash_remove_file_test2.txt";
520 const temp_manifest_dir = "cache_hash_remove_file_manifest_dir";
524 const temp_file1 = "cache_hash_post_file_test1.txt";
525 const temp_file2 = "cache_hash_post_file_test2.txt";
526 const temp_manifest_dir = "cache_hash_post_file_manifest_dir";
521527
522528 try cwd.writeFile(temp_file1, "Hello, world!\n");
523529 try cwd.writeFile(temp_file2, "Hello world the second!\n");
524530
525531 var digest1: [BASE64_DIGEST_LEN]u8 = undefined;
526532 var digest2: [BASE64_DIGEST_LEN]u8 = undefined;
533 var digest3: [BASE64_DIGEST_LEN]u8 = undefined;
527534
528535 {
529536 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
......@@ -531,11 +538,12 @@ test "manifest file with extra line does not cause null pointer exeception" {
531538
532539 ch.add("1234");
533540 _ = try ch.addFile(temp_file1);
534 _ = try ch.addFile(temp_file2);
535541
536542 // There should be nothing in the cache
537543 testing.expectEqual(@as(?[64]u8, null), try ch.hit());
538544
545 _ = try ch.addFilePost(temp_file2);
546
539547 digest1 = ch.final();
540548 }
541549 {
......@@ -544,20 +552,31 @@ test "manifest file with extra line does not cause null pointer exeception" {
544552
545553 ch.add("1234");
546554 _ = try ch.addFile(temp_file1);
547 _ = try ch.addFile(temp_file2);
548 {
549 // Remove an input file from the cache hash.
550 // We still have to add the input file, or else the initial cache
551 // hash will be different, and a different manifest file checked
552 const chf = ch.files.orderedRemove(1);
553 testing.allocator.free(chf.path.?);
554 }
555555
556556 // A file that we depend on has been updated, so the cache should not contain an entry for it
557557 digest2 = (try ch.hit()).?;
558558 }
559559
560 // Modify the file added after initial hash
561 try cwd.writeFile(temp_file2, "Hello world the second, updated\n");
562
563 {
564 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
565 defer ch.release() catch unreachable;
566
567 ch.add("1234");
568 _ = try ch.addFile(temp_file1);
569
570 // A file that we depend on has been updated, so the cache should not contain an entry for it
571 testing.expectEqual(@as(?[64]u8, null), try ch.hit());
572
573 _ = try ch.addFilePost(temp_file2);
574
575 digest3 = ch.final();
576 }
577
560578 testing.expect(mem.eql(u8, digest1[0..], digest2[0..]));
579 testing.expect(!mem.eql(u8, digest1[0..], digest3[0..]));
561580
562581 try cwd.deleteTree(temp_manifest_dir);
563582 try cwd.deleteFile(temp_file1);