authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-05 22:17:21-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-06 22:41:00-07:00
log3b60ab4872355f0b9a9c7d0794ca8b548ab99412
treea5fd44fa180714d5f16eaba89ed34dc9b3829041
parentf034cef262ed050551bc5c36d710263950e5eb27

stage2: fix std lib tests always filtering out all tests


3 files changed, 23 insertions(+), 2 deletions(-)

src/Compilation.zig+1
......@@ -1418,6 +1418,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
14181418 .gpa = gpa,
14191419 .comp = comp,
14201420 .main_pkg = main_pkg,
1421 .main_pkg_is_std = try main_pkg.isInsideOf(std_pkg.*),
14211422 .root_pkg = root_pkg,
14221423 .zig_cache_artifact_directory = zig_cache_artifact_directory,
14231424 .global_zir_cache = global_zir_cache,
src/Module.zig+14-2
......@@ -130,6 +130,10 @@ stage1_flags: packed struct {
130130} = .{},
131131
132132job_queued_update_builtin_zig: bool = true,
133/// This makes it so that we can run `zig test` on the standard library.
134/// Otherwise, the logic for scanning test decls skips all of them because
135/// `main_pkg != std_pkg`.
136main_pkg_is_std: bool,
133137
134138compile_log_text: ArrayListUnmanaged(u8) = .{},
135139
......@@ -4528,14 +4532,22 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi
45284532 // test decl with no name. Skip the part where we check against
45294533 // the test name filter.
45304534 if (!mod.comp.bin_file.options.is_test) break :blk false;
4531 if (decl_pkg != mod.main_pkg) break :blk false;
4535 if (decl_pkg != mod.main_pkg) {
4536 if (!mod.main_pkg_is_std) break :blk false;
4537 const std_pkg = mod.main_pkg.table.get("std").?;
4538 if (std_pkg != decl_pkg) break :blk false;
4539 }
45324540 try mod.test_functions.put(gpa, new_decl_index, {});
45334541 break :blk true;
45344542 },
45354543 else => blk: {
45364544 if (!is_named_test) break :blk false;
45374545 if (!mod.comp.bin_file.options.is_test) break :blk false;
4538 if (decl_pkg != mod.main_pkg) break :blk false;
4546 if (decl_pkg != mod.main_pkg) {
4547 if (!mod.main_pkg_is_std) break :blk false;
4548 const std_pkg = mod.main_pkg.table.get("std").?;
4549 if (std_pkg != decl_pkg) break :blk false;
4550 }
45394551 // TODO check the name against --test-filter
45404552 try mod.test_functions.put(gpa, new_decl_index, {});
45414553 break :blk true;
src/Package.zig+8
......@@ -124,3 +124,11 @@ pub fn addAndAdopt(parent: *Package, gpa: Allocator, name: []const u8, child: *P
124124 child.parent = parent;
125125 return parent.add(gpa, name, child);
126126}
127
128pub fn isInsideOf(pkg: Package, another: Package) !bool {
129 var pkg_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
130 var another_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
131 const pkg_path = try pkg.root_src_directory.handle.realpath(pkg.root_src_path, &pkg_buffer);
132 const another_path = try another.root_src_directory.handle.realpath(".", &another_buffer);
133 return mem.startsWith(u8, pkg_path, another_path);
134}