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(
853853 var path = str_tok.get(file.zir);
854854
855855 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")) {
857857 path = "root";
858858 break :blk self.module.main_pkg;
859859 } else {
src/Compilation.zig+4-4
......@@ -1588,10 +1588,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15881588 try main_pkg.add(gpa, "root", root_pkg);
15891589 try main_pkg.addAndAdopt(gpa, "std", std_pkg);
15901590
1591 const main_pkg_in_std = m: {
1591 const main_pkg_is_std = m: {
15921592 const std_path = try std.fs.path.resolve(arena, &[_][]const u8{
15931593 std_pkg.root_src_directory.path orelse ".",
1594 std.fs.path.dirname(std_pkg.root_src_path) orelse ".",
1594 std_pkg.root_src_path,
15951595 });
15961596 defer arena.free(std_path);
15971597 const main_path = try std.fs.path.resolve(arena, &[_][]const u8{
......@@ -1599,7 +1599,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15991599 main_pkg.root_src_path,
16001600 });
16011601 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);
16031603 };
16041604
16051605 // 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 {
16381638 .gpa = gpa,
16391639 .comp = comp,
16401640 .main_pkg = main_pkg,
1641 .main_pkg_in_std = main_pkg_in_std,
1641 .main_pkg_is_std = main_pkg_is_std,
16421642 .root_pkg = root_pkg,
16431643 .zig_cache_artifact_directory = zig_cache_artifact_directory,
16441644 .global_zir_cache = global_zir_cache,
src/Module.zig+3-3
......@@ -142,7 +142,7 @@ job_queued_update_builtin_zig: bool = true,
142142/// This makes it so that we can run `zig test` on the standard library.
143143/// Otherwise, the logic for scanning test decls skips all of them because
144144/// `main_pkg != std_pkg`.
145main_pkg_in_std: bool,
145main_pkg_is_std: bool,
146146
147147compile_log_text: ArrayListUnmanaged(u8) = .{},
148148
......@@ -5174,7 +5174,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
51745174 // the test name filter.
51755175 if (!comp.bin_file.options.is_test) break :blk false;
51765176 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;
51785178 const std_pkg = mod.main_pkg.table.get("std").?;
51795179 if (std_pkg != decl_pkg) break :blk false;
51805180 }
......@@ -5185,7 +5185,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
51855185 if (!is_named_test) break :blk false;
51865186 if (!comp.bin_file.options.is_test) break :blk false;
51875187 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;
51895189 const std_pkg = mod.main_pkg.table.get("std").?;
51905190 if (std_pkg != decl_pkg) break :blk false;
51915191 }