Skip to content

Commit

Permalink
chore: add demo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh committed Dec 19, 2023
1 parent 147aaa9 commit 7d09bf5
Show file tree
Hide file tree
Showing 11 changed files with 1,008 additions and 414 deletions.
39 changes: 35 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
TESTS_INIT=tests/minimal_init.lua
TESTS_DIR=tests/
TESTS_INIT = tests/minimal_init.lua
# 30 mins
TIMEOUT_MINS=30*60*1000
TIMEOUT_MINS := $(shell echo $$((30 * 60 * 1000)))


.PHONY: test
.PHONY: test-demo
.PHONY: test-demo-main
.PHONY: test-demo-config

test:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}', timeout = ${TIMEOUT_MINS} }"
-c "lua require([[plenary.test_harness]]).test_directory([[tests ! -regex .*_demo_spec.*]], { minimal_init = '"${TESTS_INIT}"', timeout = "${TIMEOUT_MINS}", })"

test-all:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "lua require([[plenary.test_harness]]).test_directory([[tests]], { minimal_init = '"${TESTS_INIT}"', timeout = "${TIMEOUT_MINS}", })"

test-demo:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "lua require([[plenary.test_harness]]).test_directory([[tests -regex .*_demo_spec.*]], { minimal_init = '"${TESTS_INIT}"', timeout = "${TIMEOUT_MINS}", })"

test-demo-main:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "lua require([[plenary.test_harness]]).test_directory([[tests -name kitty_scrollback_demo_spec.lua]], { minimal_init = '"${TESTS_INIT}"', timeout = "${TIMEOUT_MINS}", })"

test-demo-config:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "lua require([[plenary.test_harness]]).test_directory([[tests -name kitty_scrollback_config_demo_spec.lua]], { minimal_init = '"${TESTS_INIT}"', timeout = "${TIMEOUT_MINS}", })"

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,5 @@ The API is available via the `kitty-scrollback.api` module. e.g., `require('kitt

<!-- panvimdoc-ignore-end -->

-- demo
-- demo
43 changes: 43 additions & 0 deletions tests/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# thanks https://github.com/kalgynirae/dotfiles/blob/1203030bd44448088c4c1a42155a254171a31c4b/bashrc#L59
# Test the terminal's text/color capabilities
colortest() {
local color escapes intensity style
echo "NORMAL bold dim itali under rever strik BRIGHT bold dim itali under rever strik"
for color in $(seq 0 7); do
for intensity in 3 9; do # normal, bright
escapes="${intensity}${color}"
printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$escapes" # normal
for style in 1 2 3 4 7 9; do # bold, dim, italic, underline, reverse, strikethrough
escapes="${intensity}${color};${style}"
printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$style"
done
echo -n " "
done
echo
done
echo -n "TRUECOLOR "
awk 'BEGIN{
columns = 78;
step = columns / 6;
for (hue = 0; hue<columns; hue++) {
x = (hue % step) * 255 / step;
if (hue < step) {
r = 255; g = x; b = 0;
} else if (hue < step*2) {
r = 255-x; g = 255; b = 0;
} else if (hue < step*3) {
r = 0; g = 255; b = x;
} else if (hue < step*4) {
r = 0; g = 255-x; b = 255;
} else if (hue < step*5) {
r = x; g = 0; b = 255;
} else {
r = 255; g = 0; b = 255-x;
}
printf "\033[48;2;%d;%d;%dm", r, g, b;
printf "\033[38;2;%d;%d;%dm", 255-r, 255-g, 255-b;
printf " \033[0m";
}
printf "\n";
}'
}
30 changes: 18 additions & 12 deletions tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ Show clicked command plaintext output in kitty-scrollback.nvim
M.move_forward_one_prompt()
end

local next_as_line = false

M.feed_kitty = function(input)
for _, line in pairs(input) do
if line == 'pause' then
Expand All @@ -246,10 +248,15 @@ M.feed_kitty = function(input)
M.pause()
M.kitty_remote_kitten_kitty_scrollback_nvim()
M.pause()
elseif line:match('^\\') then
elseif line == '__next_as_line' then
next_as_line = true
elseif line:match('^\\') or next_as_line then
M.pause(0.2)
M.kitty_remote_send_text(line)
M.pause(0.2)
if next_as_line then
next_as_line = false
end
else
line:gsub('.', function(c)
M.kitty_remote_send_text(c)
Expand Down Expand Up @@ -338,12 +345,12 @@ M.assert_screen_equals = function(actual, expected, ...)
if actual_rstrip ~= expected_rstrip then
debug_print_differences(actual_rstrip, expected_rstrip)
end
assert.are.equal(actual_rstrip, expected_rstrip, ...)
assert.are.equal(expected_rstrip, actual_rstrip, ...)
if expected.cursor_y then
assert.are.equal(actual.cursor_y, expected.cursor_y, ...)
assert.are.equal(expected.cursor_y, actual.cursor_y, ...)
end
if expected.cursor_x then
assert.are.equal(actual.cursor_x, expected.cursor_x, ...)
assert.are.equal(expected.cursor_x, actual.cursor_x, ...)
end
end

Expand All @@ -363,13 +370,12 @@ M.assert_screen_starts_with = function(actual, expected, ...)
if actual_rstrip ~= expected_rstrip then
debug_print_differences(actual_rstrip, expected_rstrip)
end
assert.are.equal(actual_rstrip, expected_rstrip, ...)
assert.is_not_true(actual_rstrip:match(expected.stdout), ...)
assert.are.equal(expected_rstrip, actual_rstrip, ...)
if expected.cursor_y then
assert.are.equal(actual.cursor_y, expected.cursor_y, ...)
assert.are.equal(expected.cursor_y, actual.cursor_y, ...)
end
if expected.cursor_x then
assert.are.equal(actual.cursor_x, expected.cursor_x, ...)
assert.are.equal(expected.cursor_x, actual.cursor_x, ...)
end
end

Expand All @@ -385,10 +391,10 @@ M.assert_screen_match = function(actual, expected, ...)
assert.is_true(actual_rstrip:match(expected.pattern), ...)
assert.is_not_true(actual_rstrip:match(expected.pattern), ...)
if expected.cursor_y then
assert.are.equal(actual.cursor_y, expected.cursor_y, ...)
assert.are.equal(expected.cursor_y, actual.cursor_y, ...)
end
if expected.cursor_x then
assert.are.equal(actual.cursor_x, expected.cursor_x, ...)
assert.are.equal(expected.cursor_x, actual.cursor_x, ...)
end
end

Expand All @@ -403,10 +409,10 @@ M.assert_screen_not_match = function(actual, expected, ...)
})
assert.is_not_true(actual_rstrip:match(expected.pattern), ...)
if expected.cursor_y then
assert.are.equal(actual.cursor_y, expected.cursor_y, ...)
assert.are.equal(expected.cursor_y, actual.cursor_y, ...)
end
if expected.cursor_x then
assert.are.equal(actual.cursor_x, expected.cursor_x, ...)
assert.are.equal(expected.cursor_x, actual.cursor_x, ...)
end
end

Expand Down
169 changes: 169 additions & 0 deletions tests/kitty-scrollback/kitty_scrollback_config_demo_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
local assert = require('luassert.assert')
local h = require('tests.helpers')
local describe = describe ---@diagnostic disable-line: undefined-global
local it = it ---@diagnostic disable-line: undefined-global
local after_each = after_each ---@diagnostic disable-line: undefined-global
local before_each = before_each ---@diagnostic disable-line: undefined-global

h.setup_backport()

local ksb_dir = vim.fn.fnamemodify(
vim.fn.fnamemodify(vim.api.nvim_get_runtime_file('lua/kitty-scrollback', false)[1], ':h:h'),
':p'
)
h.debug({
ksb_dir = ksb_dir,
kitty_conf = ksb_dir .. 'tests/kitty.conf',
})

local tmpsock = h.tempsocket(ksb_dir .. 'tmp/')
local kitty_instance

local shell = h.debug(h.is_github_action and '/bin/bash' or (vim.o.shell .. ' --noprofile --norc'))

local kitty_cmd = h.debug({
'kitty',
'--listen-on=unix:' .. tmpsock,
'--config',
ksb_dir .. 'tests/kitty.conf',
'--override',
'shell=' .. shell,
'--override',
'enabled_layouts=fat:bias=90',
'--override',
'initial_window_width=161c',
'--override',
'initial_window_height=30c',
'--override',
'font_size=18.0',
'--override',
'background_opacity=1.0',
'--session',
'-', -- read session from stdin
})

local cowthink_stdout = vim
.system({ 'cowthink', '-f', '/opt/homebrew/share/cows/stegosaurus.cow', 'nice @' .. h.now() })
:wait().stdout or ''

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,
})
local ready = false
vim.fn.wait(5000, function()
ready = (h.debug(h.kitty_remote_ls():wait()).code == 0)
return ready
end, 500)

assert.is_true(ready, 'kitty is not ready for remote connections, exiting')
h.pause()

local ksb_work_dir = os.getenv('KITTY_SCROLLBACK_NVIM_DIR') or 'tmp/kitty-scrollback.nvim'
local is_directory = vim.fn.isdirectory(ksb_work_dir) > 0
if is_directory then
vim.system({ 'rm', '-rf', ksb_work_dir }):wait()
end
vim
.system({
'git',
'clone',
'https://github.com/mikesmithgh/kitty-scrollback.nvim',
ksb_work_dir,
})
:wait()

h.feed_kitty({
[[source ]] .. ksb_dir .. [[tests/bashrc]],
[[\n]], -- enter
[[cd ]] .. ksb_work_dir,
[[\n]], -- enter
[[clear]],
[[\n]], -- enter
})
end)

after_each(function()
kitty_instance:kill(2)
kitty_instance = nil
end)

it('should demo', function()
h.assert_screen_equals(
h.feed_kitty({
[[
printf "\\033[0m\\033[38;2;167;192;128m\\n" &&
figlet -f cyberlarge -c -w 165 kitty-scrollback.nvim &&
printf "\\033[0m\\n"
eza --tree --icons ../kitty-scrollback.nvim/lua
lolcat --freq=0.15 --spread=1.5 --truecolor -
]],
[[__next_as_line]],
cowthink_stdout,
[[\x04]], -- control+d
[[
figlet -f cyberlarge -c -w 165 kitty-scrollback.nvim | lolcat]],
[[\n]], -- enter
[[
colortest
]],
[[\n]], -- enter
[[__open_ksb]],
[[a# builtin > kitty_scrollback_nvim]],
[[\e]], -- esc
[[0o]],
[[
default configuration for the keymap `kitty_mod+h`
Browse scrollback buffer in kitty-scrollback.nvim
]],
[[\e]], -- esc
[[gg0]],
}),
{
stdout = h.with_status_win(
[[
_____ ..-~ ~-..-~
| | \~~~\.' `./~~~/
--------- \__/ \__/
.' O \ / / \ "
(_____, `._.' | } \/~~~/
`----. / } | / \__/
`-. | / | / `. ,~~|
~-.__| /_ - ~ ^| /- _ `..-'
| / | / ~-. `-. _ _ _
|_____| |_____| ~ - . _ _ _ _ _>
$ figlet -f cyberlarge -c -w 165 kitty-scrollback.nvim | lolcat
_ _ _____ _______ _______ __ __ _______ _______ ______ _____ ______ _______ _______ _ _ __ _ _ _ _____ _______
|____/ | | | \_/ ___ |______ | |_____/ | | | | |_____] |_____| | |____/ | \ | \ / | | | |
| \_ __|__ | | | ______| |_____ | \_ |_____| |_____ |_____ |_____] | | |_____ | \_ . | \_| \/ __|__ | | |
$🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
N▏# builtin > kitty_scrollback_nvim ▕
\▏# default configuration for the keymap `kitty_mod+h` ▕
\▏# ▕
\▏# Browse scrollback buffer in kitty-scrollback.nvim ▕
\▏# ▕
\▏ ▕
\▏ ▕
\▏ ▕
\▏ ▕
T▏ ▕
$🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿
$▏ ▕
$▏ \y Yank <C-CR> Execute <S-CR> Paste :w Paste g? Toggle Mappings ▕
$🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿
]],
168
),
cursor_y = 17,
cursor_x = 3,
},
'kitty-scrollback.nvim did not position cursor on first line'
)
end)
end)
Loading

0 comments on commit 7d09bf5

Please sign in to comment.