adjust test build to deal with library-based systems
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 1m33s

This commit is contained in:
Emil Lerch 2023-10-28 08:31:12 -07:00
parent 90f1461207
commit 0736660669
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 35 additions and 9 deletions

View File

@ -32,25 +32,40 @@ pub fn build(b: *std.Build) !void {
// running `zig build`). // running `zig build`).
b.installArtifact(lib); b.installArtifact(lib);
// Creates a step for unit testing. This only builds the test executable // Creates steps for unit testing. This only builds the test executable
// but does not run it. // but does not run it.
const main_tests = b.addTest(.{ const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" }, .root_source_file = .{ .path = "src/test.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
_ = try universal_lambda.addModules(b, main_tests); _ = try universal_lambda.addModules(b, exe_tests);
// _ = try ulb.createOptionsModule(b, main_tests);
// main_tests.addModule("flexilib-interface", flexilib_module); var run_exe_tests = b.addRunArtifact(exe_tests);
var run_main_tests = b.addRunArtifact(main_tests); run_exe_tests.skip_foreign_checks = true;
run_main_tests.skip_foreign_checks = true;
// Universal lambda can end up as an exe or a lib. When it is a library,
// we end up changing the root source file away from downstream so we can
// control exports and such. This is just flexilib for now, but we could
// end up in a situation where we need to create an array of libraries
// with various roots that all meet the rest of the build DAG at test_step
// in the future. Scaleway, for instance, is another system that works
// via shared library
const lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/flexilib.zig" },
.target = target,
.optimize = optimize,
});
_ = try universal_lambda.addModules(b, lib_tests);
var run_lib_tests = b.addRunArtifact(lib_tests);
run_lib_tests.skip_foreign_checks = true;
// This creates a build step. It will be visible in the `zig build --help` menu, // This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test` // and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install". // This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests"); const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step); test_step.dependOn(&run_exe_tests.step);
test_step.dependOn(&run_lib_tests.step);
} }
pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile) !void { pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile) !void {

View File

@ -162,7 +162,18 @@ test {
std.testing.refAllDecls(@import("CloudflareDeployStep.zig")); std.testing.refAllDecls(@import("CloudflareDeployStep.zig"));
} }
std.testing.refAllDecls(@import("console.zig")); std.testing.refAllDecls(@import("console.zig"));
std.testing.refAllDecls(@import("flexilib.zig")); // By importing flexilib.zig, this breaks downstream any time someone
// tries to build flexilib, because flexilib.zig becomes the root module,
// then gets imported here again. It shouldn't be done unless doing
// zig build test, but it is. So we need to figure that out at some point...
// const root = @import("root");
// if (@hasDecl(root, "run") and @hasDecl(root, "register"))
// std.testing.refAllDecls(root)
// else
// std.testing.refAllDecls(@import("flexilib.zig"));
//
// What we need to do here is update our own build.zig to add a specific
// test with flexilib as root. That will match the behavior of downstream
// The following do not currently have tests // The following do not currently have tests