neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

run_tests.zig (3000B)


      1 const std = @import("std");
      2 const LazyPath = std.Build.LazyPath;
      3 
      4 pub fn testStep(b: *std.Build, kind: []const u8, nvim_bin: *std.Build.Step.Compile, lua_deps: LazyPath, config_dir: LazyPath, include_path: ?[]const LazyPath) !*std.Build.Step.Run {
      5    const test_step = b.addRunArtifact(nvim_bin);
      6    test_step.addArg("-ll");
      7    test_step.addFileArg(b.path("./test/lua_runner.lua"));
      8    test_step.addDirectoryArg(lua_deps);
      9    if (include_path) |paths| {
     10        for (paths) |path| {
     11            test_step.addPrefixedDirectoryArg("-I", path);
     12        }
     13    }
     14    test_step.addArgs(&.{ "busted", "-v", "-o", "test.busted.outputHandlers.nvim", "--lazy" });
     15    // TODO(bfredl): a bit funky with paths, should work even if we run "zig build" in a nested dir
     16    test_step.addArg(b.fmt("./test/{s}/preload.lua", .{kind}));
     17    test_step.addArg("--lpath=./src/?.lua");
     18    test_step.addArg("--lpath=./runtime/lua/?.lua");
     19    test_step.addArg("--lpath=./?.lua");
     20    test_step.addPrefixedFileArg("--lpath=", config_dir.path(b, "?.lua")); // FULING: not a real file but works anyway?
     21    // TODO(bfredl): look into $BUSTED_ARGS user hook, TEST_TAG,  TEST_FILTER
     22    if (b.args) |args| {
     23        test_step.addArgs(args); // accept TEST_FILE as a positional argument
     24    } else {
     25        test_step.addArg(b.fmt("./test/{s}/", .{kind}));
     26    }
     27 
     28    const env = test_step.getEnvMap();
     29    try env.put("VIMRUNTIME", "runtime");
     30    try env.put("NVIM_RPLUGIN_MANIFEST", "Xtest_xdg/Xtest_rplugin_manifest");
     31    try env.put("XDG_CONFIG_HOME", "Xtest_xdg/config");
     32    try env.put("XDG_DATA_HOME", "Xtest_xdg/share");
     33    try env.put("XDG_STATE_HOME", "Xtest_xdg/state");
     34    try env.put("TMPDIR", b.fmt("{s}/Xtest_tmpdir", .{b.install_path}));
     35    try env.put("NVIM_LOG_FILE", b.fmt("{s}/Xtest_nvimlog", .{b.install_path}));
     36 
     37    env.remove("NVIM");
     38    env.remove("XDG_DATA_DIRS");
     39    return test_step;
     40 }
     41 
     42 pub fn test_steps(b: *std.Build, nvim_bin: *std.Build.Step.Compile, depend_on: *std.Build.Step, lua_deps: LazyPath, config_dir: LazyPath, unit_paths: ?[]const LazyPath) !void {
     43    const empty_dir = b.addWriteFiles();
     44    _ = empty_dir.add(".touch", "");
     45    const tmpdir_create = b.addInstallDirectory(.{ .source_dir = empty_dir.getDirectory(), .install_dir = .prefix, .install_subdir = "Xtest_tmpdir/" });
     46 
     47    const functional_tests = try testStep(b, "functional", nvim_bin, lua_deps, config_dir, null);
     48    functional_tests.step.dependOn(depend_on);
     49    functional_tests.step.dependOn(&tmpdir_create.step);
     50 
     51    const functionaltest_step = b.step("functionaltest", "run functional tests");
     52    functionaltest_step.dependOn(&functional_tests.step);
     53 
     54    if (unit_paths) |paths| {
     55        const unit_tests = try testStep(b, "unit", nvim_bin, lua_deps, config_dir, paths);
     56        unit_tests.step.dependOn(depend_on);
     57        unit_tests.step.dependOn(&tmpdir_create.step);
     58 
     59        const unittest_step = b.step("unittest", "run unit tests");
     60        unittest_step.dependOn(&unit_tests.step);
     61    }
     62 }