diff options
| author | dweiller <4678790+dweiller@users.noreplay.github.com> | 2023-02-08 15:04:29 +1100 |
|---|---|---|
| committer | dweiller <4678790+dweiller@users.noreplay.github.com> | 2023-02-08 16:35:32 +1100 |
| commit | edc0e84270c04acf432096c4772bfe199afdaf15 (patch) | |
| tree | 7f8d8187cc4f6965d484d502b82024dc7fec3975 /src/Compilation.zig | |
| parent | 1f7390f3999e80f775dbc0e62f1dcb071c3bed77 (diff) | |
| download | zig-edc0e84270c04acf432096c4772bfe199afdaf15.tar.gz zig-edc0e84270c04acf432096c4772bfe199afdaf15.zip | |
allow custom test runners to import modules
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 8f265f9eb6..f19e83680d 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1624,16 +1624,21 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const test_pkg = if (options.test_runner_path) |test_runner| test_pkg: { const test_dir = std.fs.path.dirname(test_runner); const basename = std.fs.path.basename(test_runner); - break :test_pkg try Package.create(gpa, "root", test_dir, basename); - } - else - try Package.createWithDir( - gpa, - "root", - options.zig_lib_directory, - null, - "test_runner.zig", - ); + const pkg = try Package.create(gpa, "root", test_dir, basename); + + // copy package table from main_pkg to root_pkg + var iter = main_pkg.table.valueIterator(); + while (iter.next()) |v| { + try pkg.add(gpa, v.*); + } + break :test_pkg pkg; + } else try Package.createWithDir( + gpa, + "root", + options.zig_lib_directory, + null, + "test_runner.zig", + ); errdefer test_pkg.destroy(gpa); break :root_pkg test_pkg; |
