Skip to content

Commit b3b7a3c

Browse files
authored
test: migrate to MiniTest and add utils tests (#1333)
Replaces vusted with MiniTest for running tests and updates CI workflow to use Neovim for testing. Adds initial tests for utils.glob_to_pattern. Removes old plugin_spec.lua and updates .luarc.json for new globals. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 5f3c570 commit b3b7a3c

10 files changed

Lines changed: 103 additions & 42 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,4 @@ jobs:
6464
luarocksVersion: "3.12.2"
6565

6666
- name: run test
67-
shell: bash
68-
run: |
69-
luarocks install luacheck
70-
luarocks install vusted
71-
vusted ./test
67+
run: make test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,5 @@ cython_debug/
165165

166166
# (neo)vim helptags
167167
/doc/tags
168+
169+
.dependencies/

.luarc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{
2-
"diagnostics.globals": ["describe", "it"],
2+
"runtime.version": "LuaJIT",
3+
"diagnostics.globals": [
4+
"describe",
5+
"it",
6+
"MiniTest",
7+
"before_each",
8+
"after_each"
9+
],
310
"diagnostics.disable": ["redefined-local"]
411
}

Makefile

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,12 @@ BUILD_DIR := build
1919

2020
.PHONY: help install-cli install-pre-commit install test tiktoken clean
2121

22-
help:
23-
@echo "Available commands:"
24-
@echo " install-cli - Install Lua and Luarocks using Homebrew"
25-
@echo " install-pre-commit - Install pre-commit using pip"
26-
@echo " install - Install vusted using Luarocks"
27-
@echo " test - Run tests using vusted"
28-
@echo " tiktoken - Download tiktoken_core library"
29-
@echo " clean - Remove build directory"
30-
31-
install-cli:
32-
brew install luarocks
33-
brew install lua
34-
3522
install-pre-commit:
3623
pip install pre-commit
3724
pre-commit install
3825

39-
install:
40-
luarocks install vusted
41-
4226
test:
43-
vusted test
27+
nvim --headless --noplugin -u ./scripts/test.lua -c "lua MiniTest.run()"
4428

4529
all: luajit
4630

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ cd CopilotChat.nvim
519519
2. Install development dependencies:
520520

521521
```bash
522-
# Install pre-commit hooks
523522
make install-pre-commit
524523
```
525524

scripts/minimal.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- https://github.com/neovim/neovim/blob/master/contrib/minimal.lua
2+
vim.opt.runtimepath:append(vim.fn.getcwd())
3+
4+
for name, url in pairs({
5+
'https://github.com/nvim-lua/plenary.nvim',
6+
}) do
7+
local install_path = vim.fn.fnamemodify('.dependencies/' .. name, ':p')
8+
if vim.fn.isdirectory(install_path) == 0 then
9+
vim.fn.system({ 'git', 'clone', '--depth=1', url, install_path })
10+
end
11+
vim.opt.runtimepath:append(install_path)
12+
end
13+
14+
require('CopilotChat').setup({
15+
-- Add your configuration here
16+
})

scripts/test.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vim.opt.runtimepath:append(vim.fn.getcwd())
2+
3+
for name, url in pairs({
4+
'https://github.com/nvim-lua/plenary.nvim',
5+
'https://github.com/echasnovski/mini.test',
6+
}) do
7+
local install_path = vim.fn.fnamemodify('.dependencies/' .. name, ':p')
8+
if vim.fn.isdirectory(install_path) == 0 then
9+
vim.fn.system({ 'git', 'clone', '--depth=1', url, install_path })
10+
end
11+
vim.opt.runtimepath:append(install_path)
12+
end
13+
14+
require('mini.test').setup()

test/plugin_spec.lua

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/test_init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
local T = MiniTest.new_set()
2+
3+
T['should be able to load'] = function()
4+
MiniTest.expect.no_error(function()
5+
require('CopilotChat')
6+
end)
7+
end
8+
9+
return T

tests/test_utils.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local T = MiniTest.new_set()
2+
3+
local cases = {
4+
{ glob = '', expected = '^$' },
5+
{ glob = 'abc', expected = '^abc$' },
6+
{ glob = 'ab#/.', expected = '^ab%#%/%.$' },
7+
{ glob = '\\\\\\ab\\c\\', expected = '^%\\abc\\$' },
8+
9+
{ glob = 'abc.*', expected = '^abc%..*$', matches = { 'abc.txt', 'abc.' }, not_matches = { 'abc' } },
10+
{ glob = '??.txt', expected = '^..%.txt$' },
11+
12+
{ glob = 'a[]', expected = '[^]' },
13+
{ glob = 'a[^]b', expected = '^ab$' },
14+
{ glob = 'a[!]b', expected = '^ab$' },
15+
{ glob = 'a[a][b]z', expected = '^a[a][b]z$' },
16+
{ glob = 'a[a-f]z', expected = '^a[a-f]z$' },
17+
{ glob = 'a[a-f0-9]z', expected = '^a[a-f0-9]z$' },
18+
{ glob = 'a[a-f0-]z', expected = '^a[a-f0%-]z$' },
19+
{ glob = 'a[!a-f]z', expected = '^a[^a-f]z$' },
20+
{ glob = 'a[^a-f]z', expected = '^a[^a-f]z$' },
21+
{ glob = 'a[\\!\\^\\-z\\]]z', expected = '^a[%!%^%-z%]]z$' },
22+
{ glob = 'a[\\a-\\f]z', expected = '^a[a-f]z$' },
23+
24+
{ glob = 'a[', expected = '[^]' },
25+
{ glob = 'a[a-', expected = '[^]' },
26+
{ glob = 'a[a-b', expected = '[^]' },
27+
{ glob = 'a[!', expected = '[^]' },
28+
{ glob = 'a[!a', expected = '[^]' },
29+
{ glob = 'a[!a-', expected = '[^]' },
30+
{ glob = 'a[!a-b', expected = '[^]' },
31+
{ glob = 'a[!a-b\\]', expected = '[^]' },
32+
}
33+
34+
for _, case in ipairs(cases) do
35+
T['glob_to_pattern: ' .. case.glob] = function()
36+
local utils = require('CopilotChat.utils')
37+
local pattern = utils.glob_to_pattern(case.glob)
38+
MiniTest.expect.equality(pattern, case.expected)
39+
if case.matches then
40+
for _, str in ipairs(case.matches) do
41+
MiniTest.expect.equality(str:match(pattern) ~= nil, true)
42+
end
43+
end
44+
if case.not_matches then
45+
for _, str in ipairs(case.not_matches) do
46+
MiniTest.expect.equality(str:match(pattern) ~= nil, false)
47+
end
48+
end
49+
end
50+
end
51+
52+
return T

0 commit comments

Comments
 (0)