authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-30 17:06:03-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
log1ffff1bb181da785b63bb3ed6accf23874cb07f3
tree3ccd29889f71a6bb766a4c614ee9ffd163bc9f7f
parent0fa89dc51d6bb92f36ceb1399e07aa6f7c1dbd2b

Add test case for fix in previous commit


1 files changed, 52 insertions(+), 0 deletions(-)

lib/std/cache_hash.zig+52
......@@ -509,3 +509,55 @@ test "no file inputs" {
509509
510510 testing.expectEqual(digest1, digest2);
511511}
512
513test "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}