Skip to content

Commit

Permalink
feat: plenary
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed May 12, 2024
1 parent ae439bd commit ba6e20c
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 161 deletions.
17 changes: 0 additions & 17 deletions .busted

This file was deleted.

29 changes: 15 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ jobs:
with:
neovim: true
version: ${{ matrix.version }}
- name: Set up pkgx with LuaJIT and LuaRocks
uses: pkgxdev/setup@v1
with:
+: luajit.org@2 luarocks.org

# Install into LuaRocks (not Neovim)
- name: Install neotest
run: luarocks --lua-dir=$HOME/.pkgx/luajit.org/v2 --lua-version=5.1 install neotest
- name: Install nvim-treesitter
run: luarocks --lua-dir=$HOME/.pkgx/luajit.org/v2 --lua-version=5.1 install nvim-treesitter
- name: Install busted
run: luarocks --lua-dir=$HOME/.pkgx/luajit.org/v2 --lua-version=5.1 install busted

- name: Neovim version
run: nvim --version
# TODO: figure out how to avoid duplicate setups
- name: For CI
run: |
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
git clone --depth 1 https://github.com/nvim-neotest/neotest.git ~/.local/share/nvim/site/pack/vendor/start/neotest
git clone --depth 1 https://github.com/nvim-neotest/nvim-nio.git ~/.local/share/nvim/site/pack/vendor/start/nvim-nio
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
nvim --headless -c 'TSInstallSync lua go | quit'
- name: For local neotest-plenary setup
run: ./test/install.sh
- name: Run tests
run: make unit-test
run: nvim --headless -c "PlenaryBustedDirectory test {minimal_init = 'test/minimal_init.lua', sequential = true}"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/xdg
.tests
4 changes: 0 additions & 4 deletions .luarc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .nvimrc

This file was deleted.

3 changes: 0 additions & 3 deletions .pkgx.yml

This file was deleted.

15 changes: 0 additions & 15 deletions Makefile

This file was deleted.

34 changes: 0 additions & 34 deletions test/busted

This file was deleted.

34 changes: 34 additions & 0 deletions test/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -e

# This script is executed via tests/minimal_init.lua

GITHUB="https://github.com"
GITHUB_PLENARY="$GITHUB/nvim-lua/plenary.nvim"
GITHUB_TELESCOPE="$GITHUB/nvim-telescope/telescope.nvim"
GITHUB_LSPCONFIG="$GITHUB/neovim/nvim-lspconfig"
GITHUB_NIO="$GITHUB/nvim-neotest/nvim-nio"
GITHUB_NEOTEST="$GITHUB/nvim-neotest/neotest"
GITHUB_TREESITTER="$GITHUB/nvim-treesitter/nvim-treesitter"

SCRIPT_FILE=$(readlink -f "${BASH_SOURCE[0]}")
REPO_DIR=$(dirname "$(dirname "$SCRIPT_FILE")")

TEST_ALL_DIR="$REPO_DIR/.tests/all/site/pack/deps/start"

clone() {
repo=$1
dest=$2
if [ ! -d "$dest" ]; then
git clone --depth 1 "$repo" "$dest"
fi
}

# Just for the main minimal_init.lua for neotest
mkdir -p $TEST_ALL_DIR
clone $GITHUB_PLENARY "$TEST_ALL_DIR/plenary.nvim"
clone $GITHUB_LSPCONFIG "$TEST_ALL_DIR/lspconfig.nvim"
clone $GITHUB_TELESCOPE "$TEST_ALL_DIR/telescope.nvim"
clone $GITHUB_NIO "$TEST_ALL_DIR/nvim-nio"
clone $GITHUB_NEOTEST "$TEST_ALL_DIR/neotest"
clone $GITHUB_TREESITTER "$TEST_ALL_DIR/nvim-treesitter"
29 changes: 29 additions & 0 deletions test/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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

function M.init()
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.opt.runtimepath:append(".")
vim.opt.swapfile = false

vim.opt.packpath = {
".tests/all/site",
}

vim.cmd([[
packadd plenary.nvim
packadd neotest
packadd nvim-nio
packadd nvim-treesitter
]])
-- vim.cmd("TSInstall go")
end

-- Ensure the required Neovim plugins are installed/cloned
-- os.execute("test/install.sh")

M.init()
71 changes: 0 additions & 71 deletions test/nvim-shim

This file was deleted.

3 changes: 3 additions & 0 deletions test/unit/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/fredrikaverpil/neotest-golang

go 1.22.2
Empty file added test/unit/go.sum
Empty file.
11 changes: 11 additions & 0 deletions test/unit/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}

func Add(a, b int) int {
return a + b
}
31 changes: 31 additions & 0 deletions test/unit/main_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local nio = require("nio")
local adapter = require("neotest-golang")

describe("Discovery of test positions", function()
it("Discover OK", function()
local test_filepath = vim.loop.cwd() .. "/test/unit/main_test.go"
print(test_filepath)
local tree =
nio.tests.with_async_context(adapter.discover_positions, test_filepath)

local result = tree:to_list()
local expected = {
{
id = test_filepath,
name = vim.fn.fnamemodify(test_filepath, ":t"),
path = test_filepath,
range = { 0, 0, 10, 0 },
type = "file",
},
{
id = test_filepath .. "::TestAdd",
name = "TestAdd",
path = test_filepath,
range = { 0, 0, 10, 4 },
type = "test",
},
}

assert.are.same(expected, result)
end)
end)
10 changes: 10 additions & 0 deletions test/unit/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import "testing"

// A dummy test, just to assert that Go tests can run
func TestAdd(t *testing.T) {
if Add(1, 2) != 3 {
t.Fail()
}
}

0 comments on commit ba6e20c

Please sign in to comment.