Skip to content

Commit

Permalink
ci: add initial ci (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfaix committed May 21, 2024
1 parent 57d9aa2 commit 2cca240
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 11 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: neotest-gtest CI
on:
push:
branches:
- main
pull_request: ~
jobs:
style:
name: style
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check lua/ tests/

tests:
name: tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
rev: [nightly, v0.9.1, v0.10.0]
gtest_tag: [main]
include:
- os: ubuntu-22.04
rev: nightly
gtest_tag: release-1.10.0
- os: ubuntu-22.04
rev: nightly
gtest_tag: release-1.11.0
- os: ubuntu-22.04
rev: nightly
gtest_tag: release-1.12.1
- os: ubuntu-22.04
rev: nightly
gtest_tag: v1.13.0
- os: ubuntu-22.04
rev: nightly
gtest_tag: v1.14.0
- os: ubuntu-22.04
rev: nightly
gtest_tag: 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"
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 --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: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
make test
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.PHONY: test unit-test integration-test submodules

MINIMAL_INIT = tests/unit/minimal_init.lua
PLENARY_OPTS = {minimal_init='${MINIMAL_INIT}', sequential=true, timeout=1000}
PLENARY_OPTS = {minimal_init='${MINIMAL_INIT}', sequential=true, timeout=5000}
GTEST_TAG ?= main
export GTEST_TAG
export GTEST_PATH

test: unit-test integration-test ;

Expand Down
20 changes: 16 additions & 4 deletions lua/neotest-gtest/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ local TREESITTER_GTEST_QUERY = vim.treesitter.query.parse(
]]
)

local function add_reverse_lookup(tbl)
local keys = vim.tbl_keys(tbl)
for _, key in ipairs(keys) do
tbl[tbl[key]] = key
end
return tbl
end

---Extracts test positions from a source using the given query
---@param query Query The query to use
---@param query vim.treesitter.Query The query to use
---@param source string The text of the source file.
---@param root LanguageTree The root of the tree
---@param root vim.treesitter.LanguageTree The root of the tree
---@return table
---@return table
local function extract_captures(
Expand All @@ -67,9 +75,13 @@ local function extract_captures(

local namespaces = {}
local tests = {}
pcall(vim.tbl_add_reverse_lookup, query.captures)
add_reverse_lookup(query.captures)
local gettext = function(match, capture_name)
return vim.treesitter.get_node_text(match[query.captures[capture_name]], source)
local node = match[query.captures[capture_name]]
if node == nil then
error(vim.inspect({ node, match, query.captures, capture_name }))
end
return vim.treesitter.get_node_text(node, source)
end

for _, match in query:iter_matches(root, source) do
Expand Down
12 changes: 8 additions & 4 deletions tests/integration/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ add_executable(test-executable2 src/subdirectory/test_three.cpp)

enable_testing()
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG ${GTEST_TAG})
if($GTEST_PATH)
FetchContent_Declare(googletest SOURCE_DIR ${GTEST_PATH})
else()
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG ${GTEST_TAG})
endif()

if(${GTEST_TAG} STREQUAL "main")
set(GTEST_VERSION "999.999")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GTEST_TAG ?= main
.PHONY: build

build:
cmake -S. -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DGTEST_TAG=$(GTEST_TAG) -Bbuild && \
GTEST_PATH=$(GTEST_PATH) cmake -S. -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DGTEST_TAG=$(GTEST_TAG) -Bbuild && \
cmake --build build
clean:
rm -rf build
13 changes: 12 additions & 1 deletion tests/utils/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ local function parent_dir(path)
return string.sub(path, 1, sep_index - 1)
end

local function writefile(path, contents)
local open_err, file_fd = nio.uv.fs_open(path, "w", 438)
assert(not open_err and file_fd, open_err)
local write_err = nio.uv.fs_write(file_fd, contents, 0)
assert(not write_err, write_err)
local sync_err = nio.uv.fs_fsync(file_fd)
assert(not sync_err, sync_err)
local close_err = nio.uv.fs_close(file_fd)
assert(not close_err, close_err)
end

function M.write_file_tree(root, relpath2contents)
M.mkdir(root)
local created = { [root] = true }
Expand All @@ -65,7 +76,7 @@ function M.write_file_tree(root, relpath2contents)
created[parent] = true
end
local abspath = string.format("%s%s%s", root, lib.files.sep, relpath)
lib.files.write(abspath, contents)
writefile(abspath, contents)
end
end

Expand Down

0 comments on commit 2cca240

Please sign in to comment.