| ... | ... | @@ -976,16 +976,16 @@ fn hashFile(file: fs.File, bin_digest: *[Hasher.mac_length]u8) !void { |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | // Create/Write a file, close it, then grab its stat.mtime timestamp. |
| 979 | | fn testGetCurrentFileTimestamp() !i128 { |
| 979 | fn testGetCurrentFileTimestamp(dir: fs.Dir) !i128 { |
| 980 | 980 | const test_out_file = "test-filetimestamp.tmp"; |
| 981 | 981 | |
| 982 | | var file = try fs.cwd().createFile(test_out_file, .{ |
| 982 | var file = try dir.createFile(test_out_file, .{ |
| 983 | 983 | .read = true, |
| 984 | 984 | .truncate = true, |
| 985 | 985 | }); |
| 986 | 986 | defer { |
| 987 | 987 | file.close(); |
| 988 | | fs.cwd().deleteFile(test_out_file) catch {}; |
| 988 | dir.deleteFile(test_out_file) catch {}; |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | return (try file.stat()).mtime; |
| ... | ... | @@ -997,16 +997,17 @@ test "cache file and then recall it" { |
| 997 | 997 | return error.SkipZigTest; |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | | const cwd = fs.cwd(); |
| 1000 | var tmp = testing.tmpDir(.{}); |
| 1001 | defer tmp.cleanup(); |
| 1001 | 1002 | |
| 1002 | 1003 | const temp_file = "test.txt"; |
| 1003 | 1004 | const temp_manifest_dir = "temp_manifest_dir"; |
| 1004 | 1005 | |
| 1005 | | try cwd.writeFile(temp_file, "Hello, world!\n"); |
| 1006 | try tmp.dir.writeFile(temp_file, "Hello, world!\n"); |
| 1006 | 1007 | |
| 1007 | 1008 | // Wait for file timestamps to tick |
| 1008 | | const initial_time = try testGetCurrentFileTimestamp(); |
| 1009 | | while ((try testGetCurrentFileTimestamp()) == initial_time) { |
| 1009 | const initial_time = try testGetCurrentFileTimestamp(tmp.dir); |
| 1010 | while ((try testGetCurrentFileTimestamp(tmp.dir)) == initial_time) { |
| 1010 | 1011 | std.time.sleep(1); |
| 1011 | 1012 | } |
| 1012 | 1013 | |
| ... | ... | @@ -1016,9 +1017,9 @@ test "cache file and then recall it" { |
| 1016 | 1017 | { |
| 1017 | 1018 | var cache = Cache{ |
| 1018 | 1019 | .gpa = testing.allocator, |
| 1019 | | .manifest_dir = try cwd.makeOpenPath(temp_manifest_dir, .{}), |
| 1020 | .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}), |
| 1020 | 1021 | }; |
| 1021 | | cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); |
| 1022 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1022 | 1023 | defer cache.manifest_dir.close(); |
| 1023 | 1024 | |
| 1024 | 1025 | { |
| ... | ... | @@ -1054,9 +1055,6 @@ test "cache file and then recall it" { |
| 1054 | 1055 | |
| 1055 | 1056 | try testing.expectEqual(digest1, digest2); |
| 1056 | 1057 | } |
| 1057 | | |
| 1058 | | try cwd.deleteTree(temp_manifest_dir); |
| 1059 | | try cwd.deleteFile(temp_file); |
| 1060 | 1058 | } |
| 1061 | 1059 | |
| 1062 | 1060 | test "check that changing a file makes cache fail" { |
| ... | ... | @@ -1064,21 +1062,19 @@ test "check that changing a file makes cache fail" { |
| 1064 | 1062 | // https://github.com/ziglang/zig/issues/5437 |
| 1065 | 1063 | return error.SkipZigTest; |
| 1066 | 1064 | } |
| 1067 | | const cwd = fs.cwd(); |
| 1065 | var tmp = testing.tmpDir(.{}); |
| 1066 | defer tmp.cleanup(); |
| 1068 | 1067 | |
| 1069 | 1068 | const temp_file = "cache_hash_change_file_test.txt"; |
| 1070 | 1069 | const temp_manifest_dir = "cache_hash_change_file_manifest_dir"; |
| 1071 | 1070 | const original_temp_file_contents = "Hello, world!\n"; |
| 1072 | 1071 | const updated_temp_file_contents = "Hello, world; but updated!\n"; |
| 1073 | 1072 | |
| 1074 | | try cwd.deleteTree(temp_manifest_dir); |
| 1075 | | try cwd.deleteTree(temp_file); |
| 1076 | | |
| 1077 | | try cwd.writeFile(temp_file, original_temp_file_contents); |
| 1073 | try tmp.dir.writeFile(temp_file, original_temp_file_contents); |
| 1078 | 1074 | |
| 1079 | 1075 | // Wait for file timestamps to tick |
| 1080 | | const initial_time = try testGetCurrentFileTimestamp(); |
| 1081 | | while ((try testGetCurrentFileTimestamp()) == initial_time) { |
| 1076 | const initial_time = try testGetCurrentFileTimestamp(tmp.dir); |
| 1077 | while ((try testGetCurrentFileTimestamp(tmp.dir)) == initial_time) { |
| 1082 | 1078 | std.time.sleep(1); |
| 1083 | 1079 | } |
| 1084 | 1080 | |
| ... | ... | @@ -1088,9 +1084,9 @@ test "check that changing a file makes cache fail" { |
| 1088 | 1084 | { |
| 1089 | 1085 | var cache = Cache{ |
| 1090 | 1086 | .gpa = testing.allocator, |
| 1091 | | .manifest_dir = try cwd.makeOpenPath(temp_manifest_dir, .{}), |
| 1087 | .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}), |
| 1092 | 1088 | }; |
| 1093 | | cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); |
| 1089 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1094 | 1090 | defer cache.manifest_dir.close(); |
| 1095 | 1091 | |
| 1096 | 1092 | { |
| ... | ... | @@ -1110,7 +1106,7 @@ test "check that changing a file makes cache fail" { |
| 1110 | 1106 | try ch.writeManifest(); |
| 1111 | 1107 | } |
| 1112 | 1108 | |
| 1113 | | try cwd.writeFile(temp_file, updated_temp_file_contents); |
| 1109 | try tmp.dir.writeFile(temp_file, updated_temp_file_contents); |
| 1114 | 1110 | |
| 1115 | 1111 | { |
| 1116 | 1112 | var ch = cache.obtain(); |
| ... | ... | @@ -1132,9 +1128,6 @@ test "check that changing a file makes cache fail" { |
| 1132 | 1128 | |
| 1133 | 1129 | try testing.expect(!mem.eql(u8, digest1[0..], digest2[0..])); |
| 1134 | 1130 | } |
| 1135 | | |
| 1136 | | try cwd.deleteTree(temp_manifest_dir); |
| 1137 | | try cwd.deleteTree(temp_file); |
| 1138 | 1131 | } |
| 1139 | 1132 | |
| 1140 | 1133 | test "no file inputs" { |
| ... | ... | @@ -1142,18 +1135,20 @@ test "no file inputs" { |
| 1142 | 1135 | // https://github.com/ziglang/zig/issues/5437 |
| 1143 | 1136 | return error.SkipZigTest; |
| 1144 | 1137 | } |
| 1145 | | const cwd = fs.cwd(); |
| 1138 | |
| 1139 | var tmp = testing.tmpDir(.{}); |
| 1140 | defer tmp.cleanup(); |
| 1141 | |
| 1146 | 1142 | const temp_manifest_dir = "no_file_inputs_manifest_dir"; |
| 1147 | | defer cwd.deleteTree(temp_manifest_dir) catch {}; |
| 1148 | 1143 | |
| 1149 | 1144 | var digest1: [hex_digest_len]u8 = undefined; |
| 1150 | 1145 | var digest2: [hex_digest_len]u8 = undefined; |
| 1151 | 1146 | |
| 1152 | 1147 | var cache = Cache{ |
| 1153 | 1148 | .gpa = testing.allocator, |
| 1154 | | .manifest_dir = try cwd.makeOpenPath(temp_manifest_dir, .{}), |
| 1149 | .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}), |
| 1155 | 1150 | }; |
| 1156 | | cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); |
| 1151 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1157 | 1152 | defer cache.manifest_dir.close(); |
| 1158 | 1153 | |
| 1159 | 1154 | { |
| ... | ... | @@ -1188,18 +1183,19 @@ test "Manifest with files added after initial hash work" { |
| 1188 | 1183 | // https://github.com/ziglang/zig/issues/5437 |
| 1189 | 1184 | return error.SkipZigTest; |
| 1190 | 1185 | } |
| 1191 | | const cwd = fs.cwd(); |
| 1186 | var tmp = testing.tmpDir(.{}); |
| 1187 | defer tmp.cleanup(); |
| 1192 | 1188 | |
| 1193 | 1189 | const temp_file1 = "cache_hash_post_file_test1.txt"; |
| 1194 | 1190 | const temp_file2 = "cache_hash_post_file_test2.txt"; |
| 1195 | 1191 | const temp_manifest_dir = "cache_hash_post_file_manifest_dir"; |
| 1196 | 1192 | |
| 1197 | | try cwd.writeFile(temp_file1, "Hello, world!\n"); |
| 1198 | | try cwd.writeFile(temp_file2, "Hello world the second!\n"); |
| 1193 | try tmp.dir.writeFile(temp_file1, "Hello, world!\n"); |
| 1194 | try tmp.dir.writeFile(temp_file2, "Hello world the second!\n"); |
| 1199 | 1195 | |
| 1200 | 1196 | // Wait for file timestamps to tick |
| 1201 | | const initial_time = try testGetCurrentFileTimestamp(); |
| 1202 | | while ((try testGetCurrentFileTimestamp()) == initial_time) { |
| 1197 | const initial_time = try testGetCurrentFileTimestamp(tmp.dir); |
| 1198 | while ((try testGetCurrentFileTimestamp(tmp.dir)) == initial_time) { |
| 1203 | 1199 | std.time.sleep(1); |
| 1204 | 1200 | } |
| 1205 | 1201 | |
| ... | ... | @@ -1210,9 +1206,9 @@ test "Manifest with files added after initial hash work" { |
| 1210 | 1206 | { |
| 1211 | 1207 | var cache = Cache{ |
| 1212 | 1208 | .gpa = testing.allocator, |
| 1213 | | .manifest_dir = try cwd.makeOpenPath(temp_manifest_dir, .{}), |
| 1209 | .manifest_dir = try tmp.dir.makeOpenPath(temp_manifest_dir, .{}), |
| 1214 | 1210 | }; |
| 1215 | | cache.addPrefix(.{ .path = null, .handle = fs.cwd() }); |
| 1211 | cache.addPrefix(.{ .path = null, .handle = tmp.dir }); |
| 1216 | 1212 | defer cache.manifest_dir.close(); |
| 1217 | 1213 | |
| 1218 | 1214 | { |
| ... | ... | @@ -1245,11 +1241,11 @@ test "Manifest with files added after initial hash work" { |
| 1245 | 1241 | try testing.expect(mem.eql(u8, &digest1, &digest2)); |
| 1246 | 1242 | |
| 1247 | 1243 | // Modify the file added after initial hash |
| 1248 | | try cwd.writeFile(temp_file2, "Hello world the second, updated\n"); |
| 1244 | try tmp.dir.writeFile(temp_file2, "Hello world the second, updated\n"); |
| 1249 | 1245 | |
| 1250 | 1246 | // Wait for file timestamps to tick |
| 1251 | | const initial_time2 = try testGetCurrentFileTimestamp(); |
| 1252 | | while ((try testGetCurrentFileTimestamp()) == initial_time2) { |
| 1247 | const initial_time2 = try testGetCurrentFileTimestamp(tmp.dir); |
| 1248 | while ((try testGetCurrentFileTimestamp(tmp.dir)) == initial_time2) { |
| 1253 | 1249 | std.time.sleep(1); |
| 1254 | 1250 | } |
| 1255 | 1251 | |
| ... | ... | @@ -1272,8 +1268,4 @@ test "Manifest with files added after initial hash work" { |
| 1272 | 1268 | |
| 1273 | 1269 | try testing.expect(!mem.eql(u8, &digest1, &digest3)); |
| 1274 | 1270 | } |
| 1275 | | |
| 1276 | | try cwd.deleteTree(temp_manifest_dir); |
| 1277 | | try cwd.deleteFile(temp_file1); |
| 1278 | | try cwd.deleteFile(temp_file2); |
| 1279 | 1271 | } |