Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Jan 23, 2025
1 parent c2b0167 commit 92e3fb8
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 30 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/tests.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: CI

on:
push:
Expand Down Expand Up @@ -36,13 +36,19 @@ jobs:
neovim: true
version: ${{ matrix.rev }}

- name: Prepare
- name: Install Dependencies
shell: bash
run: |
${{ matrix.install-deps }}
nvim --version
fzf --version
rg --version
make prepare
if [ "$RUNNER_OS" == "Linux" ]; then
fdfind --version
else
fd --version
fi
make deps
- name: Run tests
run: |
Expand Down
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
NVIM_EXEC ?= nvim

# Run all test files
# assuming `nv` is linked to nightly appimage
# run with `make NVIM_EXEC="nvim nv" test`
# to test on both stable and nightly
#
# Run all tests or specic module tests
#
# Test both stable and nightly (assuming `nv` is linked to nightly):
# `make NVIM_EXEC="nvim nv" test`
#
# Test specific module(s) with `make test glob=file`
# NOTE: glob is resolved using `vim.fn.globpath` so we can also run:
# `make test glob=f
#
.PHONY: test
test:
for nvim_exec in $(NVIM_EXEC); do \
printf "\n======\n\n" ; \
$$nvim_exec --version | head -n 1 && echo '' ; \
$$nvim_exec --headless --noplugin -u ./scripts/minimal_init.lua \
-c "lua MiniTest.run()" ; \
-l ./scripts/make_cli.lua ; \
done

# Run test from file at `$FILE` environment variable
# run with `make FILE=tests/init_spec.lua test-file`
.PHONY: test-file
test-file:
for nvim_exec in $(NVIM_EXEC); do \
printf "\n======\n\n" ; \
$$nvim_exec --version | head -n 1 && echo '' ; \
$$nvim_exec --headless --noplugin -u ./scripts/minimal_init.lua \
-c "lua MiniTest.run_file('$(FILE)')" ; \
done

# Download 'mini.nvim' to use its 'mini.test' testing module
prepare:
#
# Download 'mini.nvim' and `nvim-web-devicons` into "deps" subfolder
# only used with the CI workflow, `minimal_init` will detect the deps
# in our lazy.nvim local config
#
.PHONY: deps
deps:
make clean
@mkdir -p deps
git clone --depth=1 --single-branch https://github.com/echasnovski/mini.nvim deps/mini.nvim
git clone --depth=1 --single-branch https://github.com/nvim-tree/nvim-web-devicons \
deps/nvim-web-devicons

# clean up
.PHONY: clean
clean:
rm -rf deps
23 changes: 23 additions & 0 deletions scripts/make_cli.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- NOTE: this script is called with `:help -l`
local MiniTest = require("mini.test")
local glob = vim.env.glob
local find_files


if glob then
-- Find both "tests/glob**/*_spec.lua" and "test/glob*_spec.lua"
find_files = function()
local ret = vim.fn.globpath("tests", glob .. "*_spec.lua", true, true)
for _, f in ipairs(vim.fn.globpath("tests", glob .. "**/*_spec.lua", true, true)) do
table.insert(ret, f)
end
return ret
end
else
-- All test files
find_files = function()
return vim.fn.globpath("tests", "**/*_spec.lua", true, true)
end
end

MiniTest.run({ collect = { find_files = find_files } })
9 changes: 0 additions & 9 deletions scripts/minimal_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,4 @@ if #vim.api.nvim_list_uis() == 0 then
-- Add fzf-lua (lazy)
vim.opt.runtimepath:append(vim.fs.joinpath("deps", "fzf-lua"))
vim.opt.runtimepath:append(vim.fs.joinpath(vim.fn.stdpath("data"), "lazy", "fzf-lua"))

-- Set up 'mini.test'
require("mini.test").setup({
collect = {
find_files = function()
return vim.fn.globpath("tests", "**/*_spec.lua", true, true)
end,
},
})
end
42 changes: 42 additions & 0 deletions tests/file/ui_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---@diagnostic disable: unused-local, unused-function
local MiniTest = require("mini.test")
local helpers = dofile("tests/helpers.lua")
local child = helpers.new_child_neovim()
local expect, eq = helpers.expect, helpers.expect.equality
local new_set = MiniTest.new_set

-- Helpers with child processes
--stylua: ignore start
---@format disable-next
local reload = function(config) child.unload(); child.setup(config) end
local set_cursor = function(...) return child.set_cursor(...) end
local get_cursor = function(...) return child.get_cursor(...) end
local set_lines = function(...) return child.set_lines(...) end
local get_lines = function(...) return child.get_lines(...) end
local type_keys = function(...) return child.type_keys(...) end
local sleep = function(ms) helpers.sleep(ms, child) end
--stylua: ignore end

local T = new_set({
hooks = {
pre_case = function()
child.init()
child.setup({})

-- Make all showed messages full width
child.o.cmdheight = 10
end,
post_once = child.stop,
},
-- n_retry = helpers.get_n_retry(2),
})

T["setup()"] = new_set()

T["setup()"]["setup global vars"] = function()
-- Global vars
eq(child.lua_get([[type(vim.g.fzf_lua_server)]]), "string")
eq(child.lua_get([[type(vim.g.fzf_lua_directory)]]), "string")
end

return T

0 comments on commit 92e3fb8

Please sign in to comment.