aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2023-02-11 14:40:14 +0200
committerGitHub <noreply@github.com>2023-02-11 14:40:14 +0200
commitba680aa98737ae1f572de3bf0b7ef7a7da27ed31 (patch)
tree911c9dad4cd6b3f9e0b8484c45ec5fb96bbdf6fc /src
parentc63be507cf0e9ccbd45cc70e4dc0ac619930733c (diff)
parent948754c5d4b707c991c4db9cdfd968e6f4866ea4 (diff)
downloadzig-ba680aa98737ae1f572de3bf0b7ef7a7da27ed31.tar.gz
zig-ba680aa98737ae1f572de3bf0b7ef7a7da27ed31.zip
Merge pull request #14588 from dweiller/test-runner-imports
fix custom test runner file import path resolution
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index e09b8f18ab..18d0e46892 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1621,16 +1621,21 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const root_pkg = if (options.is_test) root_pkg: {
// TODO: we currently have two packages named 'root' here, which is weird. This
// should be changed as part of the resolution of #12201
- const test_pkg = if (options.test_runner_path) |test_runner|
- try Package.create(gpa, "root", null, test_runner)
- else
- try Package.createWithDir(
- gpa,
- "root",
- options.zig_lib_directory,
- null,
- "test_runner.zig",
- );
+ 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);
+ const pkg = try Package.create(gpa, "root", test_dir, basename);
+
+ // copy package table from main_pkg to root_pkg
+ pkg.table = try main_pkg.table.clone(gpa);
+ 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;