|
| 1 | +describe("peekstack.health", function() |
| 2 | + local health = require("peekstack.health") |
| 3 | + local config = require("peekstack.config") |
| 4 | + |
| 5 | + local original_health_start |
| 6 | + local original_health_ok |
| 7 | + local original_health_warn |
| 8 | + local original_health_error |
| 9 | + local original_health_info |
| 10 | + local original_executable |
| 11 | + local original_has |
| 12 | + |
| 13 | + ---@type string[] |
| 14 | + local messages |
| 15 | + |
| 16 | + before_each(function() |
| 17 | + messages = {} |
| 18 | + original_health_start = vim.health.start |
| 19 | + original_health_ok = vim.health.ok |
| 20 | + original_health_warn = vim.health.warn |
| 21 | + original_health_error = vim.health.error |
| 22 | + original_health_info = vim.health.info |
| 23 | + original_executable = vim.fn.executable |
| 24 | + original_has = vim.fn.has |
| 25 | + |
| 26 | + vim.health.start = function() end |
| 27 | + vim.health.ok = function(msg) |
| 28 | + table.insert(messages, "ok:" .. msg) |
| 29 | + end |
| 30 | + vim.health.warn = function(msg) |
| 31 | + table.insert(messages, "warn:" .. msg) |
| 32 | + end |
| 33 | + vim.health.error = function(msg) |
| 34 | + table.insert(messages, "error:" .. msg) |
| 35 | + end |
| 36 | + vim.health.info = function(msg) |
| 37 | + table.insert(messages, "info:" .. msg) |
| 38 | + end |
| 39 | + end) |
| 40 | + |
| 41 | + after_each(function() |
| 42 | + vim.health.start = original_health_start |
| 43 | + vim.health.ok = original_health_ok |
| 44 | + vim.health.warn = original_health_warn |
| 45 | + vim.health.error = original_health_error |
| 46 | + vim.health.info = original_health_info |
| 47 | + vim.fn.executable = original_executable |
| 48 | + vim.fn.has = original_has |
| 49 | + config.setup({}) |
| 50 | + end) |
| 51 | + |
| 52 | + it("reports ok for nvim version and rg when available", function() |
| 53 | + vim.fn.has = function() |
| 54 | + return 1 |
| 55 | + end |
| 56 | + vim.fn.executable = function() |
| 57 | + return 1 |
| 58 | + end |
| 59 | + config.setup({}) |
| 60 | + |
| 61 | + health.check() |
| 62 | + |
| 63 | + assert.is_true(vim.list_contains(messages, "ok:nvim >= 0.10")) |
| 64 | + assert.is_true(vim.list_contains(messages, "ok:rg available")) |
| 65 | + end) |
| 66 | + |
| 67 | + it("warns when rg is not available", function() |
| 68 | + vim.fn.has = function() |
| 69 | + return 1 |
| 70 | + end |
| 71 | + vim.fn.executable = function() |
| 72 | + return 0 |
| 73 | + end |
| 74 | + config.setup({}) |
| 75 | + |
| 76 | + health.check() |
| 77 | + |
| 78 | + local found = false |
| 79 | + for _, msg in ipairs(messages) do |
| 80 | + if msg:find("warn:rg not found") then |
| 81 | + found = true |
| 82 | + end |
| 83 | + end |
| 84 | + assert.is_true(found) |
| 85 | + end) |
| 86 | + |
| 87 | + it("warns when configured picker backend is not installed", function() |
| 88 | + vim.fn.has = function() |
| 89 | + return 1 |
| 90 | + end |
| 91 | + vim.fn.executable = function() |
| 92 | + return 1 |
| 93 | + end |
| 94 | + config.setup({ picker = { backend = "telescope" } }) |
| 95 | + |
| 96 | + health.check() |
| 97 | + |
| 98 | + local found = false |
| 99 | + for _, msg in ipairs(messages) do |
| 100 | + if msg:find("warn:") and msg:find("telescope") and msg:find("not installed") then |
| 101 | + found = true |
| 102 | + end |
| 103 | + end |
| 104 | + assert.is_true(found) |
| 105 | + end) |
| 106 | + |
| 107 | + it("reports persist status when enabled inside a git repo", function() |
| 108 | + vim.fn.has = function() |
| 109 | + return 1 |
| 110 | + end |
| 111 | + vim.fn.executable = function() |
| 112 | + return 1 |
| 113 | + end |
| 114 | + config.setup({ persist = { enabled = true } }) |
| 115 | + |
| 116 | + health.check() |
| 117 | + |
| 118 | + local found_persist = false |
| 119 | + for _, msg in ipairs(messages) do |
| 120 | + if msg:find("persist") then |
| 121 | + found_persist = true |
| 122 | + end |
| 123 | + end |
| 124 | + assert.is_true(found_persist) |
| 125 | + end) |
| 126 | +end) |
0 commit comments