robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqtest: fix $NVIM_LOG_FILE from environment being overwritten (#41420)f9ea56f959

master
2.8 KiB66 linesraw
1const std = @import("std");
2const LazyPath = std.Build.LazyPath;
3
4pub fn testStep(b: *std.Build, kind: []const u8, nvim_bin: *std.Build.Step.Compile, config_dir: LazyPath, include_path: ?[]const LazyPath) !*std.Build.Step.Run {
5    const test_step = b.addRunArtifact(nvim_bin);
6    test_step.addArg("-l");
7    test_step.addFileArg(b.path("./test/runner.lua"));
8    if (include_path) |paths| {
9        for (paths) |path| {
10            test_step.addPrefixedDirectoryArg("-I", path);
11        }
12    }
13    test_step.addArg(b.fmt("-P{s}", .{b.install_path}));
14    // TODO(bfredl): investigate parallel test groups like in cmake
15    test_step.addArg(b.fmt("-X{s}/Xdg_dir", .{b.install_path}));
16    test_step.addArg("-v");
17    test_step.addArg(b.fmt("--helper=./test/{s}/preload.lua", .{kind}));
18    test_step.addPrefixedFileArg("--lpath=", config_dir.path(b, "?.lua")); // FULING: not a real file but works anyway?
19    test_step.addArg(b.fmt("--default-path=./test/{s}", .{kind}));
20    if (b.args) |args| test_step.addArgs(args);
21
22    const env = test_step.getEnvMap();
23    try env.put("NVIM_TEST", "1");
24    if (env.get("NVIM_LOG_FILE") == null) {
25        try env.put("NVIM_LOG_FILE", b.fmt("{s}/nvim.log", .{b.install_path}));
26    }
27
28    _ = env.swapRemove("NVIM");
29    _ = env.swapRemove("XDG_DATA_DIRS");
30    return test_step;
31}
32
33pub fn test_steps(b: *std.Build, nvim_bin: *std.Build.Step.Compile, depend_on: *std.Build.Step, config_dir: LazyPath, unit_paths: ?[]const LazyPath) !void {
34    const empty_dir = b.addWriteFiles();
35    _ = empty_dir.add(".touch", "");
36    const tmpdir_create = b.addInstallDirectory(.{ .source_dir = empty_dir.getDirectory(), .install_dir = .prefix, .install_subdir = "Xtest_tmpdir/" });
37
38    const functional_tests = try testStep(b, "functional", nvim_bin, config_dir, null);
39    functional_tests.step.dependOn(depend_on);
40    functional_tests.step.dependOn(&tmpdir_create.step);
41
42    const functionaltest_step = b.step("functionaltest", "run functional tests");
43    functionaltest_step.dependOn(&functional_tests.step);
44
45    const old_tests = b.addRunArtifact(nvim_bin);
46    old_tests.addArg("-l");
47    old_tests.addFileArg(b.path("./test/old/runner.lua"));
48    if (b.args) |args| {
49        old_tests.addArgs(args); // accept TEST_FILE as a positional argument
50    }
51    const env = old_tests.getEnvMap();
52    try env.put("BUILD_DIR", b.install_path);
53
54    const oldtest_step = b.step("oldtest", "run old tests");
55    oldtest_step.dependOn(&old_tests.step);
56    oldtest_step.dependOn(depend_on);
57
58    if (unit_paths) |paths| {
59        const unit_tests = try testStep(b, "unit", nvim_bin, config_dir, paths);
60        unit_tests.step.dependOn(depend_on);
61        unit_tests.step.dependOn(&tmpdir_create.step);
62
63        const unittest_step = b.step("unittest", "run unit tests");
64        unittest_step.dependOn(&unit_tests.step);
65    }
66}