Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,83 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-22.04]
rev: [nightly, v0.9.1, v0.10.0]
rev: [v0.10.0, v0.12.0, nightly]
gtest_tag: [main]
# Pin nvim-treesitter for older Neovim versions that are no longer
# supported by nvim-treesitter main (which requires Nvim 0.12+).
nvim_treesitter_ref: [main]
include:
# Older Neovim needs pinned nvim-treesitter (last version before 0.12 requirement)
- os: ubuntu-22.04
rev: v0.10.0
gtest_tag: main
nvim_treesitter_ref: 310f0925
# Google Test version matrix (on nightly)
- os: ubuntu-22.04
rev: nightly
gtest_tag: release-1.10.0
nvim_treesitter_ref: main
- os: ubuntu-22.04
rev: nightly
gtest_tag: release-1.11.0
nvim_treesitter_ref: main
- os: ubuntu-22.04
rev: nightly
gtest_tag: release-1.12.1
nvim_treesitter_ref: main
- os: ubuntu-22.04
rev: nightly
gtest_tag: v1.13.0
nvim_treesitter_ref: main
- os: ubuntu-22.04
rev: nightly
gtest_tag: v1.14.0
nvim_treesitter_ref: main
- os: ubuntu-22.04
rev: nightly
gtest_tag: main
nvim_treesitter_ref: main
exclude:
# Exclude the default v0.10.0 entry (overridden in include with pinned TS)
- rev: v0.10.0
nvim_treesitter_ref: main
steps:
- uses: actions/checkout@v4
- name: Prepare dependencies
run: |
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}/nvim-linux64.tar.gz" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
NEOVIM_URL="https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}"
# Neovim >= v0.10.4 changed the archive name from nvim-linux64 to nvim-linux-x86_64
if curl -fsL "${NEOVIM_URL}/nvim-linux-x86_64.tar.gz" -o /tmp/nvim.tar.gz; then
tar xzf /tmp/nvim.tar.gz --strip-components=1 -C "${PWD}/_neovim"
else
curl -fsL "${NEOVIM_URL}/nvim-linux64.tar.gz" -o /tmp/nvim.tar.gz
tar xzf /tmp/nvim.tar.gz --strip-components=1 -C "${PWD}/_neovim"
fi
git clone --depth 1 --branch ${{ matrix.gtest_tag }} https://github.com/google/googletest ${PWD}/_googletest
export PLUGINS_PATH=~/.local/share/nvim/site/pack/vendor/start
mkdir -p $PLUGINS_PATH
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ${PLUGINS_PATH}/plenary.nvim
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ${PLUGINS_PATH}/nvim-treesitter
git clone https://github.com/nvim-treesitter/nvim-treesitter ${PLUGINS_PATH}/nvim-treesitter
git -C ${PLUGINS_PATH}/nvim-treesitter checkout ${{ matrix.nvim_treesitter_ref }}
git clone --depth 1 https://github.com/nvim-neotest/nvim-nio ${PLUGINS_PATH}/nvim-nio
git clone --depth 1 https://github.com/mfussenegger/nvim-dap ${PLUGINS_PATH}/nvim-dap
git clone --depth 1 https://github.com/nvim-neotest/neotest ${PLUGINS_PATH}/neotest
ln -s ${PLUGINS_PATH} ~/.local/share/nvim/lazy
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --headless -c 'TSInstallSync lua cpp | quit'

- name: Install TreeSitter parsers
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
if nvim --headless -c 'TSInstallSync lua cpp | quit' 2>/dev/null; then
echo "Installed parsers via TSInstallSync"
else
npm install -g tree-sitter-cli
nvim --headless -c 'lua require("nvim-treesitter").install({"cpp", "lua"}); vim.wait(120000, function() local i = require("nvim-treesitter").get_installed(); for _, l in ipairs(i) do if l == "cpp" then return true end end; return false end, 1000)' -c 'quit'
echo "Installed parsers via nvim-treesitter Lua API"
fi

- name: Run tests
run: |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export GTEST_PATH
test: unit-test integration-test ;

unit-test:
nvim --headless -c "PlenaryBustedDirectory tests/unit ${PLENARY_OPTS}"
nvim --headless -u ${MINIMAL_INIT} -c "PlenaryBustedDirectory tests/unit ${PLENARY_OPTS}"

integration-test-all:
@for gtest_tag in release-1.10.0 release-1.11.0 release-1.12.1 v1.13.0 v1.14.0 main; do \
Expand All @@ -18,7 +18,7 @@ integration-test-all:
done

integration-test: build-tests
nvim --headless -c "PlenaryBustedDirectory tests/integration ${PLENARY_OPTS}"
nvim --headless -u ${MINIMAL_INIT} -c "PlenaryBustedDirectory tests/integration ${PLENARY_OPTS}"

build-tests: tests/integration/cpp
$(MAKE) -C tests/integration/cpp build
Expand Down
37 changes: 28 additions & 9 deletions lua/neotest-gtest/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,29 @@ local function extract_captures(
local namespaces = {}
local tests = {}
add_reverse_lookup(query.captures)
local gettext = function(match, capture_name)
local node = match[query.captures[capture_name]]
if node == nil then
error(vim.inspect({ node, match, query.captures, capture_name }))

-- In Neovim 0.12+, iter_matches returns tables of nodes ({node}) instead of
-- single nodes, even with {all=false}. This helper unwraps both formats.
local function get_node(match, capture_name)
local value = match[query.captures[capture_name]]
if value == nil then
error(vim.inspect({ value, match, query.captures, capture_name }))
end
if type(value) == "table" then
return value[1]
end
return vim.treesitter.get_node_text(node, source)
return value
end

local gettext = function(match, capture_name)
return vim.treesitter.get_node_text(get_node(match, capture_name), source)
end

for _, match in query:iter_matches(root, source, nil, nil, { all = false }) do
local namespace_name = gettext(match, "namespace.name")
local test_kind = gettext(match, "test.kind")
local test_name = gettext(match, "test.name")
local test_definition = match[query.captures["test.definition"]]
local test_definition = get_node(match, "test.definition")

tests[#tests + 1] = {
name = test_name,
Expand Down Expand Up @@ -194,13 +204,22 @@ local function parser_get_tree(lang_tree)
if injections_text == nil then
-- TODO can there be more than one?...
local injection_file = vim.treesitter.query.get_files("cpp", "injections")[1]
injections_text = files.read(injection_file)
if injection_file then
injections_text = files.read(injection_file)
else
injections_text = ""
end
end

if injections_text ~= "" then
vim.treesitter.query.set("cpp", "injections", "")
end
vim.treesitter.query.set("cpp", "injections", "")

local root = ts_lib.fast_parse(lang_tree):root()

vim.treesitter.query.set("cpp", "injections", injections_text)
if injections_text ~= "" then
vim.treesitter.query.set("cpp", "injections", injections_text)
end
return root
end

Expand Down
22 changes: 17 additions & 5 deletions lua/neotest-gtest/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,26 @@ function M.normalized_root(path)
end

function M.schedule_notify(msg, level, opts)
nio.scheduler()
vim.notify(msg, level, opts)
if coroutine.running() then
nio.scheduler()
vim.notify(msg, level, opts)
else
vim.schedule(function()
vim.notify(msg, level, opts)
end)
end
end

function M.schedule_error(message, level)
nio.scheduler()
-- can be overloaded by various plugins to call non-fast API (e.g., noice.nvim)
error(message, level)
if coroutine.running() then
nio.scheduler()
-- can be overloaded by various plugins to call non-fast API (e.g., noice.nvim)
error(message, level)
else
vim.schedule(function()
error(message, level)
end)
end
end

return M
10 changes: 9 additions & 1 deletion tests/unit/minimal_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ vim.notify = print
vim.opt.swapfile = false
vim.opt.rtp:append(".")
for _, plugin in ipairs(plugins) do
vim.opt.rtp:append(lazypath .. "/" .. plugin)
local plugin_path = lazypath .. "/" .. plugin
vim.opt.rtp:append(plugin_path)
package.path = package.path
.. ";"
.. plugin_path
.. "/lua/?.lua"
.. ";"
.. plugin_path
.. "/lua/?/init.lua"
end
Loading