Skip to content

Commit

Permalink
test: move tests to nvim-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcampos committed Nov 12, 2024
1 parent 179fc6e commit 2321815
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 36 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@ jobs:
linux:
strategy:
matrix:
version: [stable, v0.7.0, master]
version: [stable, v0.7.0, nightly]

runs-on: ubuntu-latest

env:
NVIM_TEST_VERSION: ${{ matrix.version }}

steps:

- name: Set current date
id: vars
run: |
echo "current_date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "nvim_test_path=$HOME/.data/nvim-test/" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3

- uses: actions/cache@v3
id: cache
with:
path: neovim
key: ${{ runner.os }}-nvim-${{ matrix.version }}-${{ steps.vars.outputs.current_date }}
path: ${{ steps.vars.outputs.nvim_test_path }}
key: ${{ runner.os }}-nvim-test-${{ matrix.version }}

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y autoconf automake build-essential cmake gcc-11 gettext gperf libtool-bin locales ninja-build pkg-config unzip
# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y autoconf automake build-essential cmake gcc-11 gettext gperf libtool-bin locales ninja-build pkg-config unzip

- name: Setup lua
uses: leafo/gh-actions-lua@v9
Expand All @@ -49,15 +52,14 @@ jobs:
- name: Run functional tests
env:
NEOVIM_BRANCH: ${{ matrix.version }}
NVIM_TEST_VERSION: ${{ matrix.version }}
NVIM_RUNNER_VERSION: v0.10.2
run: |
make functionaltest
- name: Run unit tests
env:
VIMRUNTIME: ${{ github.workspace }}/neovim/runtime/
VUSTED_NVIM: ${{ github.workspace }}/neovim/build/bin/nvim
run: |
export VUSTED_NVIM=$HOME/.data/nvim-test/nvim-test-${{ matrix.version }}/bin/nvim
make unittest
- name: Check formatting
Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FILTER ?= .*

NEOVIM_BRANCH ?= master
NEOVIM_TEST_VERSION := v0.10.2
NEOVIM_RUNNER_VERSION ?= v0.10.2

neovim:
git clone --depth 1 https://github.com/neovim/neovim --branch $(NEOVIM_BRANCH)
make -C $@
nvim-test:
git clone --depth 1 https://github.com/lewis6991/nvim-test
nvim-test/bin/nvim-test --init

vim-snippets:
git clone --depth 1 https://github.com/honza/vim-snippets
Expand All @@ -15,13 +16,16 @@ export BUSTED_ARGS = -v --lazy --shuffle \
--filter=$(FILTER) \
--lpath=$(PWD)/test/functional/?.lua

functionaltest: neovim vim-snippets
SNIPPY_PATH=$(PWD) TEST_FILE=$(PWD)/test/functional \
make -C neovim functionaltest
functionaltest: nvim-test
nvim-test/bin/nvim-test test/functional \
--lpath=$(PWD)/lua/?.lua \
--lpath=$(PWD)/test/functional/?.lua \
--verbose \
--coverage

-@stty sane

unittest:
unittest: vim-snippets
vusted --shuffle test/unit

test: functionaltest unittest
Expand Down
25 changes: 18 additions & 7 deletions test/functional/helpers.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
local luassert = require('luassert')
local Screen = require('test.functional.ui.screen')
local Screen = require('nvim-test.screen')

local ok, helpers = pcall(require, 'nvim-test.helpers')

local ok, helpers = pcall(require, 'test.functional.testnvim')
if not ok then
ok, helpers = pcall(require, 'test.functional.helpers')
error('Failed to load nvim-test helpers')
end

local snippy_src = os.getenv('SNIPPY_PATH') or '.'

local H = helpers()
local H = helpers

function H.eq(expected, actual, context)
return luassert.are.same(expected, actual, context)
Expand All @@ -18,6 +19,9 @@ function H.neq(expected, actual, context)
return luassert.are_not.same(expected, actual, context)
end

H.command = H.api.nvim_command
H.eval = H.api.nvim_eval

H.setup_test_snippets = function()
H.exec_lua(string.format(
[[
Expand All @@ -37,26 +41,33 @@ end
H.before_each = function()
H.clear()
H.screen = Screen.new(50, 5)
H.screen:attach()

local defaults = {
[1] = { foreground = Screen.colors.Blue1, bold = true },
[2] = { bold = true },
[3] = { background = Screen.colors.LightGrey },
}

if H.eval('has("nvim-0.10")') > 0 then
if H.fn.has('nvim-0.10') > 0 then
H.command('colorscheme vim')
defaults[3] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }
end

H.screen:set_default_attr_ids(defaults)

H.command('set rtp=$VIMRUNTIME')
H.command('language en_US.utf8')
-- No syntax-based highlighting
H.command('syntax off')
-- No tree-siter-based highlighting
H.exec_lua([[vim.treesitter.start = function() end]])
-- No matching parentheses highlighting
H.command('NoMatchParen')
H.command('set rtp+=' .. snippy_src)
H.command('runtime plugin/snippy.lua')
H.command('lua snippy = require("snippy")')
H.exec_lua([[snippy.setup({ choice_delay = 0 })]])

H.screen:attach()
end

return H
2 changes: 1 addition & 1 deletion test/functional/markers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Virtual markers', function()
pending('feature requires nvim >= 0.10')
return true
end
command('set filetype=lua')
-- command('set filetype=lua')
exec_lua([[snippy.setup({
virtual_markers = {
enabled = true,
Expand Down
41 changes: 33 additions & 8 deletions test/functional/options_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local insert = helpers.insert
local eq = helpers.eq
local exec_lua = helpers.exec_lua
local setup_test_snippets = helpers.setup_test_snippets
local sleep = vim and vim.uv and vim.uv.sleep or helpers.sleep

describe('Options', function()
local screen
Expand Down Expand Up @@ -60,11 +61,23 @@ describe('Options', function()
{2:-- INSERT --} |
]],
})
feed('<Esc>:%d<CR>')
end)

it('should expand with beginning option', function()
setup_test_snippets()
command('set filetype=python')
insert('foo begin')
screen:expect({
grid = [[
foo begi^n |
{1:~ }|
{1:~ }|
{1:~ }|
|
]],
})
feed('a')
feed('<plug>(snippy-expand)')
-- screen:snapshot_util()
screen:expect({
grid = [[
foo begin^ |
Expand All @@ -76,12 +89,21 @@ describe('Options', function()
})
end)

it('should expand with custom option', function()
it('should expand with custom option 1', function()
setup_test_snippets()
command('set filetype=python')
insert('comment')
feed('a')
feed('<plug>(snippy-expand)')
screen:expect({
grid = [[
commen^t |
{1:~ }|
{1:~ }|
{1:~ }|
|
]],
})
feed('a<plug>(snippy-expand)')
eq(false, exec_lua([[return snippy.is_active()]]))
screen:expect({
grid = [[
comment^ |
Expand All @@ -91,10 +113,13 @@ describe('Options', function()
{2:-- INSERT --} |
]],
})
feed('<Esc>:%d<CR>')
end)

it('should expand with custom option', function()
setup_test_snippets()
command('set filetype=python')
insert('# comment')
feed('a')
feed('<plug>(snippy-expand)')
feed('a<plug>(snippy-expand)')
-- screen:snapshot_util()
screen:expect({
grid = [[
Expand Down

0 comments on commit 2321815

Please sign in to comment.