diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e722714f..9ce3f370 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,8 +64,4 @@ jobs: luarocksVersion: "3.12.2" - name: run test - shell: bash - run: | - luarocks install luacheck - luarocks install vusted - vusted ./test + run: make test diff --git a/.gitignore b/.gitignore index 94e6f763..fc3fe2ac 100644 --- a/.gitignore +++ b/.gitignore @@ -165,3 +165,5 @@ cython_debug/ # (neo)vim helptags /doc/tags + +.dependencies/ diff --git a/.luarc.json b/.luarc.json index b97a9f11..ad90d858 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,4 +1,11 @@ { - "diagnostics.globals": ["describe", "it"], + "runtime.version": "LuaJIT", + "diagnostics.globals": [ + "describe", + "it", + "MiniTest", + "before_each", + "after_each" + ], "diagnostics.disable": ["redefined-local"] } diff --git a/Makefile b/Makefile index c5d53c52..240be629 100644 --- a/Makefile +++ b/Makefile @@ -19,28 +19,12 @@ BUILD_DIR := build .PHONY: help install-cli install-pre-commit install test tiktoken clean -help: - @echo "Available commands:" - @echo " install-cli - Install Lua and Luarocks using Homebrew" - @echo " install-pre-commit - Install pre-commit using pip" - @echo " install - Install vusted using Luarocks" - @echo " test - Run tests using vusted" - @echo " tiktoken - Download tiktoken_core library" - @echo " clean - Remove build directory" - -install-cli: - brew install luarocks - brew install lua - install-pre-commit: pip install pre-commit pre-commit install -install: - luarocks install vusted - test: - vusted test + nvim --headless --noplugin -u ./scripts/test.lua -c "lua MiniTest.run()" all: luajit diff --git a/README.md b/README.md index ef385174..62d03ee5 100644 --- a/README.md +++ b/README.md @@ -519,7 +519,6 @@ cd CopilotChat.nvim 2. Install development dependencies: ```bash -# Install pre-commit hooks make install-pre-commit ``` diff --git a/scripts/minimal.lua b/scripts/minimal.lua new file mode 100644 index 00000000..69c5cefb --- /dev/null +++ b/scripts/minimal.lua @@ -0,0 +1,16 @@ +-- https://github.com/neovim/neovim/blob/master/contrib/minimal.lua +vim.opt.runtimepath:append(vim.fn.getcwd()) + +for name, url in pairs({ + 'https://github.com/nvim-lua/plenary.nvim', +}) do + local install_path = vim.fn.fnamemodify('.dependencies/' .. name, ':p') + if vim.fn.isdirectory(install_path) == 0 then + vim.fn.system({ 'git', 'clone', '--depth=1', url, install_path }) + end + vim.opt.runtimepath:append(install_path) +end + +require('CopilotChat').setup({ + -- Add your configuration here +}) diff --git a/scripts/test.lua b/scripts/test.lua new file mode 100644 index 00000000..fd391b37 --- /dev/null +++ b/scripts/test.lua @@ -0,0 +1,14 @@ +vim.opt.runtimepath:append(vim.fn.getcwd()) + +for name, url in pairs({ + 'https://github.com/nvim-lua/plenary.nvim', + 'https://github.com/echasnovski/mini.test', +}) do + local install_path = vim.fn.fnamemodify('.dependencies/' .. name, ':p') + if vim.fn.isdirectory(install_path) == 0 then + vim.fn.system({ 'git', 'clone', '--depth=1', url, install_path }) + end + vim.opt.runtimepath:append(install_path) +end + +require('mini.test').setup() diff --git a/test/plugin_spec.lua b/test/plugin_spec.lua deleted file mode 100644 index 9497f016..00000000 --- a/test/plugin_spec.lua +++ /dev/null @@ -1,18 +0,0 @@ --- Mock packages -package.loaded['plenary.async'] = { - wrap = function(fn) - return function(...) - return fn(...) - end - end, -} -package.loaded['plenary.curl'] = {} -package.loaded['plenary.log'] = {} -package.loaded['plenary.scandir'] = {} -package.loaded['plenary.filetype'] = {} - -describe('CopilotChat plugin', function() - it('should be able to load', function() - assert.truthy(require('CopilotChat')) - end) -end) diff --git a/tests/test_init.lua b/tests/test_init.lua new file mode 100644 index 00000000..e4329607 --- /dev/null +++ b/tests/test_init.lua @@ -0,0 +1,9 @@ +local T = MiniTest.new_set() + +T['should be able to load'] = function() + MiniTest.expect.no_error(function() + require('CopilotChat') + end) +end + +return T diff --git a/tests/test_utils.lua b/tests/test_utils.lua new file mode 100644 index 00000000..ca23a4bb --- /dev/null +++ b/tests/test_utils.lua @@ -0,0 +1,52 @@ +local T = MiniTest.new_set() + +local cases = { + { glob = '', expected = '^$' }, + { glob = 'abc', expected = '^abc$' }, + { glob = 'ab#/.', expected = '^ab%#%/%.$' }, + { glob = '\\\\\\ab\\c\\', expected = '^%\\abc\\$' }, + + { glob = 'abc.*', expected = '^abc%..*$', matches = { 'abc.txt', 'abc.' }, not_matches = { 'abc' } }, + { glob = '??.txt', expected = '^..%.txt$' }, + + { glob = 'a[]', expected = '[^]' }, + { glob = 'a[^]b', expected = '^ab$' }, + { glob = 'a[!]b', expected = '^ab$' }, + { glob = 'a[a][b]z', expected = '^a[a][b]z$' }, + { glob = 'a[a-f]z', expected = '^a[a-f]z$' }, + { glob = 'a[a-f0-9]z', expected = '^a[a-f0-9]z$' }, + { glob = 'a[a-f0-]z', expected = '^a[a-f0%-]z$' }, + { glob = 'a[!a-f]z', expected = '^a[^a-f]z$' }, + { glob = 'a[^a-f]z', expected = '^a[^a-f]z$' }, + { glob = 'a[\\!\\^\\-z\\]]z', expected = '^a[%!%^%-z%]]z$' }, + { glob = 'a[\\a-\\f]z', expected = '^a[a-f]z$' }, + + { glob = 'a[', expected = '[^]' }, + { glob = 'a[a-', expected = '[^]' }, + { glob = 'a[a-b', expected = '[^]' }, + { glob = 'a[!', expected = '[^]' }, + { glob = 'a[!a', expected = '[^]' }, + { glob = 'a[!a-', expected = '[^]' }, + { glob = 'a[!a-b', expected = '[^]' }, + { glob = 'a[!a-b\\]', expected = '[^]' }, +} + +for _, case in ipairs(cases) do + T['glob_to_pattern: ' .. case.glob] = function() + local utils = require('CopilotChat.utils') + local pattern = utils.glob_to_pattern(case.glob) + MiniTest.expect.equality(pattern, case.expected) + if case.matches then + for _, str in ipairs(case.matches) do + MiniTest.expect.equality(str:match(pattern) ~= nil, true) + end + end + if case.not_matches then + for _, str in ipairs(case.not_matches) do + MiniTest.expect.equality(str:match(pattern) ~= nil, false) + end + end + end +end + +return T