Skip to content

Commit

Permalink
Merge pull request #106 from Issafalcon/103-fix-unit-test-runners-via…
Browse files Browse the repository at this point in the history
…-plenary

103 fix unit test runners via plenary
  • Loading branch information
Issafalcon authored Jun 1, 2024
2 parents 4cbf726 + cc56f9c commit 2a5db50
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
timeout-minutes: 2
strategy:
matrix:
neovim_version: ['v0.9.1', 'v0.9.4', 'nightly']
neovim_version: ['v0.9.1', 'v0.9.4', 'v0.10.0', 'nightly']

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all:
# runs all the test files.
test:
nvim --version | head -n 1 && echo ''
./scripts/test.sh
./tests/test.sh

# installs `mini.nvim`, used for both the tests and documentation.
deps:
Expand All @@ -15,6 +15,7 @@ deps:
git clone --depth 1 https://github.com/nvim-neotest/neotest.git deps/neotest
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim.git deps/plenary
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter.git deps/nvim-treesitter
git clone --depth 1 https://github.com/nvim-neotest/nvim-nio deps/nvim-nio

# installs deps before running tests, useful for the CI.
test-ci: deps test
Expand Down
30 changes: 0 additions & 30 deletions scripts/minimal_init.lua

This file was deleted.

68 changes: 68 additions & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
-- Add current directory to 'runtimepath' to be able to use 'lua' files
vim.cmd([[let &rtp.=','.getcwd()]])

-- When running headless only (i.e. via Makefile command)
if #vim.api.nvim_list_uis() == 0 then
-- Add dependenices to rtp (installed via the Makefile 'deps' command)
local neotest_path = vim.fn.getcwd() .. "/deps/neotest"
local plenary_path = vim.fn.getcwd() .. "/deps/plenary"
local treesitter_path = vim.fn.getcwd() .. "/deps/nvim-treesitter"
local mini_path = vim.fn.getcwd() .. "/deps/mini.doc.nvim"
local nio_path = vim.fn.getcwd() .. "/deps/nvim-nio"

vim.cmd("set rtp+=" .. neotest_path)
vim.cmd("set rtp+=" .. plenary_path)
vim.cmd("set rtp+=" .. treesitter_path)
vim.cmd("set rtp+=" .. mini_path)
vim.cmd("set rtp+=" .. nio_path)

-- Source the plugin dependency files
vim.cmd("runtime plugin/nvim-treesitter.lua")
vim.cmd("runtime plugin/plenary.vim")
vim.cmd("runtime lua/mini/doc.lua")

-- Setup test plugin dependencies
require("nvim-treesitter.configs").setup({
ensure_installed = "c_sharp",
sync_install = true,
highlight = {
enable = false,
},
})
end
-- local M = {}
--
-- function M.root(root)
-- local f = debug.getinfo(1, "S").source:sub(2)
-- return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
-- end
--
-- ---@param plugin string
-- function M.load(plugin)
-- local name = plugin:match(".*/(.*)")
-- local package_root = M.root(".tests/site/pack/deps/start/")
-- if not vim.loop.fs_stat(package_root .. name) then
-- print("Installing " .. plugin)
-- vim.fn.mkdir(package_root, "p")
-- vim.fn.system({
-- "git",
-- "clone",
-- "--depth=1",
-- "https://github.com/" .. plugin .. ".git",
-- package_root .. "/" .. name,
-- })
-- end
-- end
--
-- function M.setup()
-- vim.cmd([[set runtimepath=$VIMRUNTIME]])
-- vim.opt.runtimepath:append(M.root())
-- vim.opt.packpath = { M.root(".tests/site") }
--
-- M.load("nvim-treesitter/nvim-treesitter")
-- M.load("nvim-lua/plenary.nvim")
-- M.load("Issafalcon/neotest-dotnet")
-- M.load("echasnovski/mini.doc")
-- end
--
-- M.setup()
29 changes: 9 additions & 20 deletions tests/nunit/discover_positions/test_attribute_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,22 @@ describe("discover_positions", function()
{
{
framework = "nunit",
id = spec_file .. "::NUnitSamples",
is_class = false,
name = "NUnitSamples",
id = spec_file .. "::SingleTests",
is_class = true,
name = "SingleTests",
path = spec_file,
range = { 2, 0, 16, 1 },
range = { 4, 0, 16, 1 },
type = "namespace",
},
{
{
framework = "nunit",
id = spec_file .. "::NUnitSamples::SingleTests",
is_class = true,
name = "SingleTests",
id = spec_file .. "::SingleTests::Test1",
is_class = false,
name = "Test1",
path = spec_file,
range = { 4, 0, 16, 1 },
type = "namespace",
},
{
{
framework = "nunit",
id = spec_file .. "::NUnitSamples::SingleTests::Test1",
is_class = false,
name = "Test1",
path = spec_file,
range = { 11, 1, 15, 2 },
type = "test",
},
range = { 11, 1, 15, 2 },
type = "test",
},
},
},
Expand Down
74 changes: 54 additions & 20 deletions tests/nunit/discover_positions/testcasesource_attribute_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,71 @@ describe("discover_positions", function()
{
{
framework = "nunit",
id = file_path .. "::NUnitSamples",
is_class = false,
name = "NUnitSamples",
id = file_path .. "::Tests",
is_class = true,
name = "Tests",
path = file_path,
range = { 2, 0, 24, 1 },
range = { 4, 0, 24, 1 },
type = "namespace",
},
{
{
framework = "nunit",
id = file_path .. "::NUnitSamples::Tests",
is_class = true,
name = "Tests",
id = file_path .. "::Tests::DivideTest",
is_class = false,
name = "DivideTest",
path = file_path,
range = { 4, 0, 24, 1 },
type = "namespace",
},
{
{
framework = "nunit",
id = file_path .. "::NUnitSamples::Tests::DivideTest",
is_class = false,
name = "DivideTest",
path = file_path,
range = { 12, 4, 16, 5 },
type = "test",
},
range = { 12, 4, 16, 5 },
type = "test",
},
},
},
}

-- 01-06-2024: c_sharp treesitter parser changes mean file scoped namespaces don't include content of file as their range anymore
-- - Other spec files have been modified accoridingly until parse has been fixed
-- return {
-- {
-- id = file_path,
-- name = file_name,
-- path = file_path,
-- range = { 0, 0, 25, 0 },
-- type = "file",
-- },
-- {
-- {
-- framework = "nunit",
-- id = file_path .. "::NUnitSamples",
-- is_class = false,
-- name = "NUnitSamples",
-- path = file_path,
-- range = { 2, 0, 24, 1 },
-- type = "namespace",
-- },
-- {
-- {
-- framework = "nunit",
-- id = file_path .. "::NUnitSamples::Tests",
-- is_class = true,
-- name = "Tests",
-- path = file_path,
-- range = { 4, 0, 24, 1 },
-- type = "namespace",
-- },
-- {
-- {
-- framework = "nunit",
-- id = file_path .. "::NUnitSamples::Tests::DivideTest",
-- is_class = false,
-- name = "DivideTest",
-- path = file_path,
-- range = { 12, 4, 16, 5 },
-- type = "test",
-- },
-- },
-- },
-- },
-- }
end

assert.same(positions, get_expected_output(spec_file, spec_file_name))
Expand Down
4 changes: 2 additions & 2 deletions scripts/test.sh → tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
tempfile=".test_output.tmp"
TEST_INIT=scripts/minimal_init.lua
TEST_INIT=tests/minimal_init.lua
TEST_DIR=tests/

if [[ -n $1 ]]; then
Expand All @@ -9,7 +9,7 @@ if [[ -n $1 ]]; then
else
nvim --headless --clean --noplugin -u ${TEST_INIT} \
-c "set rtp?" \
-c "lua vim.cmd([[PlenaryBustedDirectory ${TEST_DIR} { minimal_init = '${TEST_INIT}'}]])" | tee "${tempfile}"
-c "lua vim.cmd([[PlenaryBustedDirectory ${TEST_DIR} { minimal_init = '${TEST_INIT}', sequential = true}]])" | tee "${tempfile}"
fi

# Plenary doesn't emit exit code 1 when tests have errors during setup
Expand Down
Loading

0 comments on commit 2a5db50

Please sign in to comment.