Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add kitty fallback for checkhealth #98

Merged
merged 12 commits into from
Dec 11, 2023
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ jobs:
- name: Test kitty-scrollback.nvim
run: |
# TODO: improve the env var exports, github actions are making it hard so I gave up for now
export KITTY_CONFIG_DIRECTORY="$GITHUB_WORKSPACE/tests"
export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH
export DISPLAY=:1
export PS1="\[\e[34m\]$ \[\e[m\]"
echo 'export KITTY_CONFIG_DIRECTORY="$GITHUB_WORKSPACE/tests"' >> "$HOME/.bashrc"
echo 'export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH' >> "$HOME/.bashrc"
echo 'export DISPLAY=:1' >> "$HOME/.bashrc"
echo 'export PS1="\[\e[34m\]$ \[\e[m\]"' >> "$HOME/.bashrc"
Expand Down
21 changes: 14 additions & 7 deletions lua/kitty-scrollback/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ M.generate_kittens = function(all, generate_modes)
target_gen_modes[gen_mode] = true
end

local kitty_scrollback_kitten =
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1]
local example_path =
vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/example.lua', false)[1]
local kitty_scrollback_kitten = vim.fn.fnamemodify(
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1],
':p'
)
local example_path = vim.fn.fnamemodify(
vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/example.lua', false)[1],
':p'
)

local action_alias = 'kitty_scrollback_nvim'
local alias_config = {
Expand Down Expand Up @@ -181,8 +185,10 @@ M.generate_kittens = function(all, generate_modes)
end

M.checkhealth = function()
local kitty_scrollback_kitten =
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1]
local kitty_scrollback_kitten = vim.fn.fnamemodify(
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1],
':p'
)
-- NOTE(#58): nvim v0.9 support
-- setup backports for v0.9 because checkhealth can be called outside of standard setup flow
if vim.fn.has('nvim-0.10') <= 0 then
Expand All @@ -191,7 +197,8 @@ M.checkhealth = function()
if vim.fn.has('nvim-0.9') > 0 then
vim
.system({
p.kitty_data.kitty_path,
-- fallback to 'kitty' because checkhealth can be called outside of standard setup flow
(p and p.kitty_data and p.kitty_data.kitty_path) and p.kitty_data.kitty_path or 'kitty',
'@',
'kitten',
kitty_scrollback_kitten,
Expand Down
43 changes: 43 additions & 0 deletions tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,47 @@ M.assert_screen_equals = function(actual, expected, ...)
assert(actual_rstrip == expected_rstrip, ...)
end

M.assert_screen_starts_with = function(actual, expected, ...)
local expected_rstrip = expected:gsub('%s*\n', '\n'):gsub('\n$', '')
local actual_rstrip = actual:gsub('%s*\n', '\n'):sub(1, #expected_rstrip)
M.debug({
actual = actual,
actual_rstrip = actual_rstrip,
actual_length = #actual,
actual_rstrip_length = #actual_rstrip,
expected = expected,
expected_rstrip = expected_rstrip,
expected_length = #expected,
expected_rstrip_length = #expected_rstrip,
})
if actual_rstrip ~= expected_rstrip then
print_differences(actual_rstrip, expected_rstrip)
end
assert(actual_rstrip == expected_rstrip, ...)
end

M.assert_screen_match = function(actual, pattern, ...)
local actual_rstrip = actual:gsub('%s*\n', '\n')
M.debug({
actual = actual,
actual_rstrip = actual_rstrip,
actual_length = #actual,
actual_rstrip_length = #actual_rstrip,
match = pattern,
})
assert(actual_rstrip:match(pattern), ...)
end

M.assert_screen_not_match = function(actual, pattern, ...)
local actual_rstrip = actual:gsub('%s*\n', '\n')
M.debug({
actual = actual,
actual_rstrip = actual_rstrip,
actual_length = #actual,
actual_rstrip_length = #actual_rstrip,
match = pattern,
})
assert(not actual_rstrip:match(pattern), ...)
end

return M
28 changes: 26 additions & 2 deletions tests/kitty-scrollback/kitty_scrollback_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local ksb_dir = vim.fn.fnamemodify(
)
h.debug({
ksb_dir = ksb_dir,
minimal_kitty_conf = ksb_dir .. 'tests/minimal_kitty.conf',
kitty_conf = ksb_dir .. 'tests/kitty.conf',
})

local tmpsock = h.tempsocket(ksb_dir .. 'tmp/')
Expand All @@ -25,7 +25,7 @@ local kitty_cmd = h.debug({
'kitty',
'--listen-on=unix:' .. tmpsock,
'--config',
ksb_dir .. 'tests/minimal_kitty.conf',
ksb_dir .. 'tests/kitty.conf',
'--override',
'shell=' .. shell,
'--session',
Expand All @@ -34,6 +34,7 @@ local kitty_cmd = h.debug({

describe('kitty-scrollback.nvim', function()
before_each(function()
vim.fn.mkdir(ksb_dir .. 'tests/workdir', 'p')
kitty_instance = vim.system(kitty_cmd, {
stdin = 'cd ' .. ksb_dir .. 'tests/workdir',
})
Expand Down Expand Up @@ -85,4 +86,27 @@ $ brew search a 󰄛
'kitty-scrollback.nvim content did not match the terminal screen'
)
end)

it('should successfully open checkhealth', function()
local stdtout = h.feed_kitty({
[[nvim +'lua vim.opt.rtp:append("../..") vim.opt.rtp:append("../../kitty-scrollback.nvim") require("kitty-scrollback").setup() vim.cmd("KittyScrollbackCheckHealth")']],
[[\n]], -- enter
})
h.assert_screen_not_match(
stdtout,
'ERROR',
'kitty-scrollback.nvim checkhealth had an unexpected health check ERROR'
)
h.assert_screen_starts_with(
stdtout,
[[

──────────────────────────────────────────────────────────────────────────────
kitty-scrollback: require("kitty-scrollback.health").check()

kitty-scrollback: Neovim version
]],
'kitty-scrollback.nvim checkhealth content did not start with expected content'
)
end)
end)
File renamed without changes.