Skip to content

Commit b479d60

Browse files
authored
test: migrate to plenary.nvim for unit testing (CopilotC-Nvim#1335)
Replace mini.test with plenary.nvim for running unit tests. Update test scripts and test files to use plenary's test harness and assertion methods. Remove mini.test references from configuration and codebase. This simplifies dependencies and aligns with common Neovim testing practices.
1 parent c5057d3 commit b479d60

File tree

7 files changed

+97
-67
lines changed

7 files changed

+97
-67
lines changed

.luarc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"diagnostics.globals": [
44
"describe",
55
"it",
6-
"MiniTest",
76
"before_each",
87
"after_each"
98
],

lua/CopilotChat/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ end
157157

158158
--- Writes text to a temporary file and returns path
159159
---@param text string The text to write
160-
---@return string?
160+
---@return string
161161
function M.temp_file(text)
162162
local temp_file = os.tmpname()
163163
local f = io.open(temp_file, 'w+')

scripts/test.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ vim.opt.runtimepath:append(vim.fn.getcwd())
22

33
for name, url in pairs({
44
'https://github.com/nvim-lua/plenary.nvim',
5-
'https://github.com/echasnovski/mini.test',
65
}) do
76
local install_path = vim.fn.fnamemodify('.dependencies/' .. name, ':p')
87
if vim.fn.isdirectory(install_path) == 0 then
@@ -11,6 +10,4 @@ for name, url in pairs({
1110
vim.opt.runtimepath:append(install_path)
1211
end
1312

14-
local minitest = require('mini.test')
15-
minitest.setup()
16-
minitest.run()
13+
require('plenary.test_harness').test_directory('tests')

tests/init_spec.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('CopilotChat module', function()
2+
it('should be able to load', function()
3+
assert.has_no.errors(function()
4+
require('CopilotChat')
5+
end)
6+
end)
7+
end)

tests/test_init.lua

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

tests/test_utils.lua

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

tests/utils_spec.lua

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
local utils = require('CopilotChat.utils')
2+
3+
describe('CopilotChat.utils', function()
4+
local cases = {
5+
{ glob = '', expected = '^$' },
6+
{ glob = 'abc', expected = '^abc$' },
7+
{ glob = 'ab#/.', expected = '^ab%#%/%.$' },
8+
{ glob = '\\\\\\ab\\c\\', expected = '^%\\abc\\$' },
9+
10+
{ glob = 'abc.*', expected = '^abc%..*$', matches = { 'abc.txt', 'abc.' }, not_matches = { 'abc' } },
11+
{ glob = '??.txt', expected = '^..%.txt$' },
12+
13+
{ glob = 'a[]', expected = '[^]' },
14+
{ glob = 'a[^]b', expected = '^ab$' },
15+
{ glob = 'a[!]b', expected = '^ab$' },
16+
{ glob = 'a[a][b]z', expected = '^a[a][b]z$' },
17+
{ glob = 'a[a-f]z', expected = '^a[a-f]z$' },
18+
{ glob = 'a[a-f0-9]z', expected = '^a[a-f0-9]z$' },
19+
{ glob = 'a[a-f0-]z', expected = '^a[a-f0%-]z$' },
20+
{ glob = 'a[!a-f]z', expected = '^a[^a-f]z$' },
21+
{ glob = 'a[^a-f]z', expected = '^a[^a-f]z$' },
22+
{ glob = 'a[\\!\\^\\-z\\]]z', expected = '^a[%!%^%-z%]]z$' },
23+
{ glob = 'a[\\a-\\f]z', expected = '^a[a-f]z$' },
24+
25+
{ glob = 'a[', expected = '[^]' },
26+
{ glob = 'a[a-', expected = '[^]' },
27+
{ glob = 'a[a-b', expected = '[^]' },
28+
{ glob = 'a[!', expected = '[^]' },
29+
{ glob = 'a[!a', expected = '[^]' },
30+
{ glob = 'a[!a-', expected = '[^]' },
31+
{ glob = 'a[!a-b', expected = '[^]' },
32+
{ glob = 'a[!a-b\\]', expected = '[^]' },
33+
}
34+
35+
for _, case in ipairs(cases) do
36+
it('glob_to_pattern: ' .. case.glob, function()
37+
local pattern = utils.glob_to_pattern(case.glob)
38+
assert.equals(case.expected, pattern)
39+
if case.matches then
40+
for _, str in ipairs(case.matches) do
41+
assert.is_true(str:match(pattern) ~= nil)
42+
end
43+
end
44+
if case.not_matches then
45+
for _, str in ipairs(case.not_matches) do
46+
assert.is_false(str:match(pattern) ~= nil)
47+
end
48+
end
49+
end)
50+
end
51+
52+
it('empty', function()
53+
assert.is_true(utils.empty(nil))
54+
assert.is_true(utils.empty(''))
55+
assert.is_true(utils.empty(' '))
56+
assert.is_true(utils.empty({}))
57+
assert.is_false(utils.empty({ 1 }))
58+
assert.is_false(utils.empty('abc'))
59+
assert.is_false(utils.empty(0))
60+
end)
61+
62+
it('split_lines', function()
63+
assert.are.same(utils.split_lines(''), {})
64+
assert.are.same(utils.split_lines('a\nb'), { 'a', 'b' })
65+
assert.are.same(utils.split_lines('a\r\nb'), { 'a', 'b' })
66+
assert.are.same(utils.split_lines('a\nb\n'), { 'a', 'b', '' })
67+
end)
68+
69+
it('make_string', function()
70+
assert.equals('a b 1', utils.make_string('a', 'b', 1))
71+
assert.equals(vim.inspect({ x = 1 }), utils.make_string({ x = 1 }))
72+
assert.equals('msg', utils.make_string('error:1: msg'))
73+
end)
74+
75+
it('uuid', function()
76+
local uuid1 = utils.uuid()
77+
local uuid2 = utils.uuid()
78+
assert.equals('string', type(uuid1))
79+
assert.not_equals(uuid1, uuid2)
80+
assert.equals(36, #uuid1)
81+
end)
82+
83+
it('to_table', function()
84+
assert.are.same({ 1, 2, 3 }, utils.to_table(1, 2, 3))
85+
assert.are.same({ 1, 2, 3 }, utils.to_table({ 1, 2 }, 3))
86+
assert.are.same({ 1 }, utils.to_table(nil, 1))
87+
end)
88+
end)

0 commit comments

Comments
 (0)