authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2022-09-23 05:32:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-05 04:21:16-04:00
log6ac0d2d9d6a28dc79f78ed9a4e66f5145d6d7765
tree86537a7b1ae513f80518283d5ff978b0a08840ea
parentff534d22676b8a934acf1931f91d70c554a4bdca

Fix all std lib tests being run for any file within the std package

Before this commit: ``` $ zig test lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib 2170 passed; 37 skipped; 0 failed. ``` After this commit: ``` $ zig test lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib All 45 tests passed. ``` This matches stage1 behavior: ``` $ zig test -fstage1 lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib All 45 tests passed. ``` All tests are still run if `zig test` is run directly on `lib/std/std.zig`: ``` $ zig test lib/std/std.zig --main-pkg-path lib/std --zig-lib-dir lib 2170 passed; 37 skipped; 0 failed. ``` `zig build test-std` is unaffected by this change. Closes #12926

3 files changed, 8 insertions(+), 8 deletions(-)

src/Autodoc.zig+1-1
...@@ -853,7 +853,7 @@ fn walkInstruction(...@@ -853,7 +853,7 @@ fn walkInstruction(
853 var path = str_tok.get(file.zir);853 var path = str_tok.get(file.zir);
854854
855 const maybe_other_package: ?*Package = blk: {855 const maybe_other_package: ?*Package = blk: {
856 if (self.module.main_pkg_in_std and std.mem.eql(u8, path, "std")) {856 if (self.module.main_pkg_is_std and std.mem.eql(u8, path, "std")) {
857 path = "root";857 path = "root";
858 break :blk self.module.main_pkg;858 break :blk self.module.main_pkg;
859 } else {859 } else {
src/Compilation.zig+4-4
...@@ -1588,10 +1588,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1588,10 +1588,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1588 try main_pkg.add(gpa, "root", root_pkg);1588 try main_pkg.add(gpa, "root", root_pkg);
1589 try main_pkg.addAndAdopt(gpa, "std", std_pkg);1589 try main_pkg.addAndAdopt(gpa, "std", std_pkg);
15901590
1591 const main_pkg_in_std = m: {1591 const main_pkg_is_std = m: {
1592 const std_path = try std.fs.path.resolve(arena, &[_][]const u8{1592 const std_path = try std.fs.path.resolve(arena, &[_][]const u8{
1593 std_pkg.root_src_directory.path orelse ".",1593 std_pkg.root_src_directory.path orelse ".",
1594 std.fs.path.dirname(std_pkg.root_src_path) orelse ".",1594 std_pkg.root_src_path,
1595 });1595 });
1596 defer arena.free(std_path);1596 defer arena.free(std_path);
1597 const main_path = try std.fs.path.resolve(arena, &[_][]const u8{1597 const main_path = try std.fs.path.resolve(arena, &[_][]const u8{
...@@ -1599,7 +1599,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1599,7 +1599,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1599 main_pkg.root_src_path,1599 main_pkg.root_src_path,
1600 });1600 });
1601 defer arena.free(main_path);1601 defer arena.free(main_path);
1602 break :m mem.startsWith(u8, main_path, std_path);1602 break :m mem.eql(u8, main_path, std_path);
1603 };1603 };
16041604
1605 // Pre-open the directory handles for cached ZIR code so that it does not need1605 // Pre-open the directory handles for cached ZIR code so that it does not need
...@@ -1638,7 +1638,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1638,7 +1638,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1638 .gpa = gpa,1638 .gpa = gpa,
1639 .comp = comp,1639 .comp = comp,
1640 .main_pkg = main_pkg,1640 .main_pkg = main_pkg,
1641 .main_pkg_in_std = main_pkg_in_std,1641 .main_pkg_is_std = main_pkg_is_std,
1642 .root_pkg = root_pkg,1642 .root_pkg = root_pkg,
1643 .zig_cache_artifact_directory = zig_cache_artifact_directory,1643 .zig_cache_artifact_directory = zig_cache_artifact_directory,
1644 .global_zir_cache = global_zir_cache,1644 .global_zir_cache = global_zir_cache,
src/Module.zig+3-3
...@@ -142,7 +142,7 @@ job_queued_update_builtin_zig: bool = true,...@@ -142,7 +142,7 @@ job_queued_update_builtin_zig: bool = true,
142/// This makes it so that we can run `zig test` on the standard library.142/// This makes it so that we can run `zig test` on the standard library.
143/// Otherwise, the logic for scanning test decls skips all of them because143/// Otherwise, the logic for scanning test decls skips all of them because
144/// `main_pkg != std_pkg`.144/// `main_pkg != std_pkg`.
145main_pkg_in_std: bool,145main_pkg_is_std: bool,
146146
147compile_log_text: ArrayListUnmanaged(u8) = .{},147compile_log_text: ArrayListUnmanaged(u8) = .{},
148148
...@@ -5174,7 +5174,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -5174,7 +5174,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
5174 // the test name filter.5174 // the test name filter.
5175 if (!comp.bin_file.options.is_test) break :blk false;5175 if (!comp.bin_file.options.is_test) break :blk false;
5176 if (decl_pkg != mod.main_pkg) {5176 if (decl_pkg != mod.main_pkg) {
5177 if (!mod.main_pkg_in_std) break :blk false;5177 if (!mod.main_pkg_is_std) break :blk false;
5178 const std_pkg = mod.main_pkg.table.get("std").?;5178 const std_pkg = mod.main_pkg.table.get("std").?;
5179 if (std_pkg != decl_pkg) break :blk false;5179 if (std_pkg != decl_pkg) break :blk false;
5180 }5180 }
...@@ -5185,7 +5185,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err...@@ -5185,7 +5185,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
5185 if (!is_named_test) break :blk false;5185 if (!is_named_test) break :blk false;
5186 if (!comp.bin_file.options.is_test) break :blk false;5186 if (!comp.bin_file.options.is_test) break :blk false;
5187 if (decl_pkg != mod.main_pkg) {5187 if (decl_pkg != mod.main_pkg) {
5188 if (!mod.main_pkg_in_std) break :blk false;5188 if (!mod.main_pkg_is_std) break :blk false;
5189 const std_pkg = mod.main_pkg.table.get("std").?;5189 const std_pkg = mod.main_pkg.table.get("std").?;
5190 if (std_pkg != decl_pkg) break :blk false;5190 if (std_pkg != decl_pkg) break :blk false;
5191 }5191 }