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 {...@@ -1418,6 +1418,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1418 .gpa = gpa,1418 .gpa = gpa,
1419 .comp = comp,1419 .comp = comp,
1420 .main_pkg = main_pkg,1420 .main_pkg = main_pkg,
1421 .main_pkg_is_std = try main_pkg.isInsideOf(std_pkg.*),
1421 .root_pkg = root_pkg,1422 .root_pkg = root_pkg,
1422 .zig_cache_artifact_directory = zig_cache_artifact_directory,1423 .zig_cache_artifact_directory = zig_cache_artifact_directory,
1423 .global_zir_cache = global_zir_cache,1424 .global_zir_cache = global_zir_cache,
src/Module.zig+14-2
...@@ -130,6 +130,10 @@ stage1_flags: packed struct {...@@ -130,6 +130,10 @@ stage1_flags: packed struct {
130} = .{},130} = .{},
131131
132job_queued_update_builtin_zig: bool = true,132job_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
134compile_log_text: ArrayListUnmanaged(u8) = .{},138compile_log_text: ArrayListUnmanaged(u8) = .{},
135139
...@@ -4528,14 +4532,22 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi...@@ -4528,14 +4532,22 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) SemaError!voi
4528 // test decl with no name. Skip the part where we check against4532 // test decl with no name. Skip the part where we check against
4529 // the test name filter.4533 // the test name filter.
4530 if (!mod.comp.bin_file.options.is_test) break :blk false;4534 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 }
4532 try mod.test_functions.put(gpa, new_decl_index, {});4540 try mod.test_functions.put(gpa, new_decl_index, {});
4533 break :blk true;4541 break :blk true;
4534 },4542 },
4535 else => blk: {4543 else => blk: {
4536 if (!is_named_test) break :blk false;4544 if (!is_named_test) break :blk false;
4537 if (!mod.comp.bin_file.options.is_test) break :blk false;4545 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 }
4539 // TODO check the name against --test-filter4551 // TODO check the name against --test-filter
4540 try mod.test_functions.put(gpa, new_decl_index, {});4552 try mod.test_functions.put(gpa, new_decl_index, {});
4541 break :blk true;4553 break :blk true;
src/Package.zig+8
...@@ -124,3 +124,11 @@ pub fn addAndAdopt(parent: *Package, gpa: Allocator, name: []const u8, child: *P...@@ -124,3 +124,11 @@ pub fn addAndAdopt(parent: *Package, gpa: Allocator, name: []const u8, child: *P
124 child.parent = parent;124 child.parent = parent;
125 return parent.add(gpa, name, child);125 return parent.add(gpa, name, child);
126}126}
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}