| ... | ... | @@ -1744,6 +1744,9 @@ test FileHeader { |
| 1744 | 1744 | try std.testing.expect(h.isExecutable()); |
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | // Result of the `unpackResource` operation. Enables collecting errors from |
| 1748 | // tar/git diagnostic, filtering that errors by manifest inclusion rules and |
| 1749 | // emitting remaining errors to an `ErrorBundle`. |
| 1747 | 1750 | const UnpackResult = struct { |
| 1748 | 1751 | allocator: std.mem.Allocator, |
| 1749 | 1752 | errors: std.ArrayListUnmanaged(Error) = .{}, |
| ... | ... | @@ -1833,6 +1836,7 @@ const UnpackResult = struct { |
| 1833 | 1836 | } }); |
| 1834 | 1837 | } |
| 1835 | 1838 | |
| 1839 | // Filter errors by manifest inclusion rules. |
| 1836 | 1840 | fn filterErrors(self: *UnpackResult, filter: Filter) !void { |
| 1837 | 1841 | var i = self.errors.items.len; |
| 1838 | 1842 | const root_dir: []const u8 = if (self.root_dir) |root_dir| root_dir else ""; |
| ... | ... | @@ -1850,11 +1854,15 @@ const UnpackResult = struct { |
| 1850 | 1854 | self.root_error_message = try self.allocator.dupe(u8, msg); |
| 1851 | 1855 | } |
| 1852 | 1856 | |
| 1857 | // Emmit errors to an `ErrorBundle`. |
| 1853 | 1858 | fn bundleErrors( |
| 1854 | 1859 | self: *UnpackResult, |
| 1855 | 1860 | eb: *ErrorBundle.Wip, |
| 1856 | 1861 | src_loc: ErrorBundle.SourceLocationIndex, |
| 1857 | 1862 | ) !void { |
| 1863 | if (self.errors.items.len == 0 and self.root_error_message.len == 0) |
| 1864 | return; |
| 1865 | |
| 1858 | 1866 | const notes_len: u32 = @intCast(self.errors.items.len); |
| 1859 | 1867 | try eb.addRootErrorMessage(.{ |
| 1860 | 1868 | .msg = try eb.addString(self.root_error_message), |
| ... | ... | @@ -1941,16 +1949,21 @@ test "tarball with error paths excluded" { |
| 1941 | 1949 | try fb.expectPackageFiles(expected_files); |
| 1942 | 1950 | } |
| 1943 | 1951 | |
| 1952 | // Builds Fetch with required dependencies, clears dependencies on deinit(). |
| 1944 | 1953 | const TestFetchBuilder = struct { |
| 1945 | 1954 | thread_pool: ThreadPool, |
| 1946 | 1955 | http_client: std.http.Client, |
| 1947 | 1956 | global_cache_directory: Cache.Directory, |
| 1948 | 1957 | progress: std.Progress, |
| 1949 | | root_prog_node: *std.Progress.Node, |
| 1950 | 1958 | job_queue: Fetch.JobQueue, |
| 1951 | 1959 | fetch: Fetch, |
| 1952 | 1960 | |
| 1953 | | fn build(self: *TestFetchBuilder, allocator: std.mem.Allocator, cache_parent_dir: std.fs.Dir, path_or_url: []const u8) !*Fetch { |
| 1961 | fn build( |
| 1962 | self: *TestFetchBuilder, |
| 1963 | allocator: std.mem.Allocator, |
| 1964 | cache_parent_dir: std.fs.Dir, |
| 1965 | path_or_url: []const u8, |
| 1966 | ) !*Fetch { |
| 1954 | 1967 | const cache_dir = try cache_parent_dir.makeOpenPath("zig-global-cache", .{}); |
| 1955 | 1968 | |
| 1956 | 1969 | try self.thread_pool.init(.{ .allocator = allocator }); |
| ... | ... | @@ -1958,7 +1971,6 @@ const TestFetchBuilder = struct { |
| 1958 | 1971 | self.global_cache_directory = .{ .handle = cache_dir, .path = null }; |
| 1959 | 1972 | |
| 1960 | 1973 | self.progress = .{ .dont_print_on_dumb = true }; |
| 1961 | | self.root_prog_node = self.progress.start("Fetch", 0); |
| 1962 | 1974 | |
| 1963 | 1975 | self.job_queue = .{ |
| 1964 | 1976 | .http_client = &self.http_client, |
| ... | ... | @@ -1979,7 +1991,7 @@ const TestFetchBuilder = struct { |
| 1979 | 1991 | .lazy_status = .eager, |
| 1980 | 1992 | .parent_package_root = Cache.Path{ .root_dir = undefined }, |
| 1981 | 1993 | .parent_manifest_ast = null, |
| 1982 | | .prog_node = self.root_prog_node, |
| 1994 | .prog_node = self.progress.start("Fetch", 0), |
| 1983 | 1995 | .job_queue = &self.job_queue, |
| 1984 | 1996 | .omit_missing_hash_error = true, |
| 1985 | 1997 | .allow_missing_paths_field = false, |
| ... | ... | @@ -1991,7 +2003,6 @@ const TestFetchBuilder = struct { |
| 1991 | 2003 | .actual_hash = undefined, |
| 1992 | 2004 | .has_build_zig = false, |
| 1993 | 2005 | .oom_flag = false, |
| 1994 | | |
| 1995 | 2006 | .module = null, |
| 1996 | 2007 | }; |
| 1997 | 2008 | return &self.fetch; |
| ... | ... | @@ -2000,7 +2011,7 @@ const TestFetchBuilder = struct { |
| 2000 | 2011 | fn deinit(self: *TestFetchBuilder) void { |
| 2001 | 2012 | self.fetch.deinit(); |
| 2002 | 2013 | self.job_queue.deinit(); |
| 2003 | | self.root_prog_node.end(); |
| 2014 | self.fetch.prog_node.end(); |
| 2004 | 2015 | self.global_cache_directory.handle.close(); |
| 2005 | 2016 | self.http_client.deinit(); |
| 2006 | 2017 | self.thread_pool.deinit(); |
| ... | ... | @@ -2011,6 +2022,8 @@ const TestFetchBuilder = struct { |
| 2011 | 2022 | return try root.root_dir.handle.openDir(root.sub_path, .{ .iterate = true }); |
| 2012 | 2023 | } |
| 2013 | 2024 | |
| 2025 | // Test helper, asserts thet package dir constains expected_files. |
| 2026 | // expected_files must be sorted. |
| 2014 | 2027 | fn expectPackageFiles(self: *TestFetchBuilder, expected_files: []const []const u8) !void { |
| 2015 | 2028 | var package_dir = try self.packageDir(); |
| 2016 | 2029 | defer package_dir.close(); |
| ... | ... | @@ -2041,6 +2054,7 @@ const TestFetchBuilder = struct { |
| 2041 | 2054 | try std.testing.expectEqualDeep(expected_files, actual_files.items); |
| 2042 | 2055 | } |
| 2043 | 2056 | |
| 2057 | // Test helper, asserts that fetch has failed with `msg` error message. |
| 2044 | 2058 | fn expectFetchErrors(self: *TestFetchBuilder, notes_len: usize, msg: []const u8) !void { |
| 2045 | 2059 | var errors = try self.fetch.error_bundle.toOwnedBundle(""); |
| 2046 | 2060 | defer errors.deinit(std.testing.allocator); |
| ... | ... | @@ -2057,6 +2071,10 @@ const TestFetchBuilder = struct { |
| 2057 | 2071 | } |
| 2058 | 2072 | }; |
| 2059 | 2073 | |
| 2074 | // Creates tarball with duplicate files names. Simulating case collisions on |
| 2075 | // case insensitive file system without use of that kind of the file system. |
| 2076 | // Manifest will exclude those files, so adding manifest should remove duplicate |
| 2077 | // files problem. |
| 2060 | 2078 | fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool) !void { |
| 2061 | 2079 | const file = try dir.createFile(tarball_name, .{}); |
| 2062 | 2080 | defer file.close(); |