|
| 1 | +local MiniTest = require("mini.test") |
| 2 | +local eq = MiniTest.expect.equality |
| 3 | +local child = MiniTest.new_child_neovim() |
| 4 | + |
| 5 | +local function setup_test_environment() |
| 6 | + Utils = require("eca.utils") |
| 7 | + _G.cmd = function(custom_path) |
| 8 | + return { |
| 9 | + "nvim", |
| 10 | + "--headless", |
| 11 | + "--noplugin", |
| 12 | + "--clean", |
| 13 | + "--cmd", |
| 14 | + [[lua package.preload["eca.path_finder"] = function() |
| 15 | + local M = {} |
| 16 | + function M.new() |
| 17 | + return setmetatable({}, { __index = M }) |
| 18 | + end |
| 19 | + function M:find(custom_path) |
| 20 | + if custom_path == "error" then |
| 21 | + error("custom-server-path-error") |
| 22 | + end |
| 23 | + return (custom_path ~= "" and custom_path) or "no-custom-server-path" |
| 24 | + end |
| 25 | + return M |
| 26 | + end]], |
| 27 | + "-u", |
| 28 | + "scripts/server_path.lua", |
| 29 | + "-c", |
| 30 | + string.format("lua ServerPath.run(%s)", Utils.lua_quote(custom_path or "")), |
| 31 | + } |
| 32 | + end |
| 33 | +end |
| 34 | + |
| 35 | +local T = MiniTest.new_set({ |
| 36 | + hooks = { |
| 37 | + pre_case = function() |
| 38 | + child.restart({ "-u", "scripts/minimal_init.lua" }) |
| 39 | + child.lua_func(setup_test_environment) |
| 40 | + end, |
| 41 | + post_case = function() |
| 42 | + end, |
| 43 | + post_once = child.stop, |
| 44 | + }, |
| 45 | +}) |
| 46 | + |
| 47 | +T["server_path"] = MiniTest.new_set() |
| 48 | + |
| 49 | +T["server_path"]["run without custom path should print to stdout"] = function() |
| 50 | + child.lua("_G.result = vim.system(_G.cmd(), { text = true }):wait()") |
| 51 | + eq(child.lua_get("_G.result.code"), 0) |
| 52 | + eq(child.lua_get("_G.result.stdout"), "no-custom-server-path") |
| 53 | + eq(child.lua_get("_G.result.stderr"), "") |
| 54 | +end |
| 55 | + |
| 56 | +T["server_path"]["run with custom path should print to stdout"] = function() |
| 57 | + child.lua("_G.result = vim.system(_G.cmd('custom-server-path'), { text = true }):wait()") |
| 58 | + eq(child.lua_get("_G.result.code"), 0) |
| 59 | + eq(child.lua_get("_G.result.stdout"), "custom-server-path") |
| 60 | + eq(child.lua_get("_G.result.stderr"), "") |
| 61 | +end |
| 62 | + |
| 63 | +T["server_path"]["run with error should print to stderr"] = function() |
| 64 | + child.lua("_G.result = vim.system(_G.cmd('error'), { text = true }):wait()") |
| 65 | + eq(child.lua_get("_G.result.code"), 1) |
| 66 | + eq(child.lua_get("_G.result.stdout"), "") |
| 67 | + eq(string.find(child.lua_get("_G.result.stderr"), "custom-server-path-error", 1 , true) ~= nil, true) |
| 68 | +end |
| 69 | + |
| 70 | +return T |
0 commit comments