| author | |
| committer | |
| log | edc0e84270c04acf432096c4772bfe199afdaf15 |
| tree | 7f8d8187cc4f6965d484d502b82024dc7fec3975 |
| parent | 1f7390f3999e80f775dbc0e62f1dcb071c3bed77 |
6 files changed, 51 insertions(+), 10 deletions(-)
src/Compilation.zig+15-10| ... | ... | @@ -1624,16 +1624,21 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1624 | 1624 | const test_pkg = if (options.test_runner_path) |test_runner| test_pkg: { |
| 1625 | 1625 | const test_dir = std.fs.path.dirname(test_runner); |
| 1626 | 1626 | const basename = std.fs.path.basename(test_runner); |
| 1627 | break :test_pkg try Package.create(gpa, "root", test_dir, basename); | |
| 1628 | } | |
| 1629 | else | |
| 1630 | try Package.createWithDir( | |
| 1631 | gpa, | |
| 1632 | "root", | |
| 1633 | options.zig_lib_directory, | |
| 1634 | null, | |
| 1635 | "test_runner.zig", | |
| 1636 | ); | |
| 1627 | const pkg = try Package.create(gpa, "root", test_dir, basename); | |
| 1628 | ||
| 1629 | // copy package table from main_pkg to root_pkg | |
| 1630 | var iter = main_pkg.table.valueIterator(); | |
| 1631 | while (iter.next()) |v| { | |
| 1632 | try pkg.add(gpa, v.*); | |
| 1633 | } | |
| 1634 | break :test_pkg pkg; | |
| 1635 | } else try Package.createWithDir( | |
| 1636 | gpa, | |
| 1637 | "root", | |
| 1638 | options.zig_lib_directory, | |
| 1639 | null, | |
| 1640 | "test_runner.zig", | |
| 1641 | ); | |
| 1637 | 1642 | errdefer test_pkg.destroy(gpa); |
| 1638 | 1643 | |
| 1639 | 1644 | break :root_pkg test_pkg; |
test/standalone/test_runner_module_imports/build.zig created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub fn build(b: *std.Build) void { | |
| 4 | const t = b.addTest(.{ | |
| 5 | .root_source_file = .{ .path = "src/main.zig" }, | |
| 6 | }); | |
| 7 | t.setTestRunner("test_runner/main.zig"); | |
| 8 | ||
| 9 | const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } }); | |
| 10 | const module2 = b.createModule(.{ | |
| 11 | .source_file = .{ .path = "module2/main.zig" }, | |
| 12 | .dependencies = &.{.{ .name = "module1", .module = module1 }}, | |
| 13 | }); | |
| 14 | ||
| 15 | t.addModule("module2", module2); | |
| 16 | ||
| 17 | const test_step = b.step("test", "Run unit tests"); | |
| 18 | test_step.dependOn(&t.step); | |
| 19 | } |
test/standalone/test_runner_module_imports/module1/main.zig created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | pub const decl: usize = 1234567890; |
test/standalone/test_runner_module_imports/module2/main.zig created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | pub const mod1 = @import("module1"); |
test/standalone/test_runner_module_imports/src/main.zig created+6| ... | ... | @@ -0,0 +1,6 @@ |
| 1 | const mod2 = @import("module2"); | |
| 2 | const std = @import("std"); | |
| 3 | ||
| 4 | test { | |
| 5 | try std.testing.expectEqual(@as(usize, 1234567890), mod2.mod1.decl); | |
| 6 | } |
test/standalone/test_runner_module_imports/test_runner/main.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | const std = @import("std"); | |
| 2 | const mod2 = @import("module2"); | |
| 3 | ||
| 4 | pub fn main() !void { | |
| 5 | try std.testing.expectEqual(@as(usize, 1234567890), mod2.mod1.decl); | |
| 6 | for (@import("builtin").test_functions) |test_fn| { | |
| 7 | try test_fn.func(); | |
| 8 | } | |
| 9 | } |