From 7c33371b8b30a16a911607607a7ed4d6898aa779 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 11 May 2024 23:41:03 +0200 Subject: [PATCH] feat: plenary --- .busted | 17 --------- .github/workflows/test.yml | 23 +++++------- .gitignore | 2 +- .luarc.json | 4 --- .nvimrc | 2 -- .pkgx.yml | 3 -- Makefile | 15 -------- test/busted | 34 ------------------ test/install.sh | 32 +++++++++++++++++ test/minimal_init.lua | 27 +++++++++++++++ test/nvim-shim | 71 -------------------------------------- 11 files changed, 69 insertions(+), 161 deletions(-) delete mode 100644 .busted delete mode 100644 .luarc.json delete mode 100644 .nvimrc delete mode 100644 .pkgx.yml delete mode 100644 Makefile delete mode 100755 test/busted create mode 100755 test/install.sh create mode 100644 test/minimal_init.lua delete mode 100755 test/nvim-shim diff --git a/.busted b/.busted deleted file mode 100644 index 3b51f1b..0000000 --- a/.busted +++ /dev/null @@ -1,17 +0,0 @@ -return { - _all = { - coverage = false, - lua = "./test/nvim-shim", - }, - default = { - verbose = true, - }, - unit = { - ROOT = { "./test/unit/" }, - verbose = true, - }, - -- e2e = { - -- ROOT = {'./test/e2e/'}, - -- pattern = '', -- No fancy names for E2E tests - -- }, -} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f99bd33..45b8f89 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,18 +14,13 @@ 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 + - name: Install dependencies + run: ./test/install.sh + - name: Run Init + run: nvim --headless -c 'luafile test/minimal_init.lua' + - name: Run TSInstall + run: nvim --headless -c 'TSInstallSync lua go | quit' - name: Run tests - run: make unit-test + run: nvim --headless -c "lua PlenaryBustedDirectory test {minimal_init = 'test/minimal_init.lua', sequential = true}" -c "qa!" diff --git a/.gitignore b/.gitignore index a76deee..f0d4bc0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -test/xdg +.tests diff --git a/.luarc.json b/.luarc.json deleted file mode 100644 index 8c8662d..0000000 --- a/.luarc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", - "workspace.ignoreDir": ["test/xdg"] -} diff --git a/.nvimrc b/.nvimrc deleted file mode 100644 index c7a30dc..0000000 --- a/.nvimrc +++ /dev/null @@ -1,2 +0,0 @@ -" Use the custom shim as the busted binary for testing -let g:bustedprg='./test/busted' diff --git a/.pkgx.yml b/.pkgx.yml deleted file mode 100644 index 999e0ca..0000000 --- a/.pkgx.yml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - - luajit.org - - luarocks.org diff --git a/Makefile b/Makefile deleted file mode 100644 index 5950d87..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -.PHONY: check unit-test e2e-test clean - -check: unit-test e2e-test - -unit-test: - @./test/busted --run unit - -# e2e-test: -# @./test/busted --run e2e - -clean: - @rm -rf test/xdg/local/state/nvim/* - @rm -rf test/xdg/local/share/nvim/site/pack/testing/start/nvim-treesitter/parser/* - @# The symlink might have been left over from a failed test run - @rm -rf test/xdg/local/share/nvim/site/pack/self-* diff --git a/test/busted b/test/busted deleted file mode 100755 index f1b7ce3..0000000 --- a/test/busted +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: Unlicense - -# This is free and unencumbered software released into the public domain. -# -# Anyone is free to copy, modify, publish, use, compile, sell, or distribute -# this software, either in source code form or as a compiled binary, for any -# purpose, commercial or non-commercial, and by any means. -# -# In jurisdictions that recognize copyright laws, the author or authors of -# this software dedicate any and all copyright interest in the software to -# the public domain. We make this dedication for the benefit of the public -# at large and to the detriment of our heirs and successors. We intend this -# dedication to be an overt act of relinquishment in perpetuity of all -# present and future rights to this software under copyright law. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# For more information, please refer to - -# A shim which acts as a command-line interface adapter for the busted test -# framework. If busted is installed using LuaRocks we cannot invoke it -# directly, but some tools might want to do so. This thin adapter can be used -# as a drop-in replacement for the busted executable. - -export LUA_PATH="./lua/?.lua;;" -export LUA_CPATH="./lua/?.so;;" - -eval $(luarocks path --lua-version 5.1 --bin) && $HOME/.luarocks/bin/busted $@ diff --git a/test/install.sh b/test/install.sh new file mode 100755 index 0000000..7796059 --- /dev/null +++ b/test/install.sh @@ -0,0 +1,32 @@ +#!/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" + +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" diff --git a/test/minimal_init.lua b/test/minimal_init.lua new file mode 100644 index 0000000..4faf662 --- /dev/null +++ b/test/minimal_init.lua @@ -0,0 +1,27 @@ +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 + ]]) +end + +-- Ensure the required Neovim plugins are installed/cloned +os.execute("test/install.sh") + +M.init() diff --git a/test/nvim-shim b/test/nvim-shim deleted file mode 100755 index d53b4cf..0000000 --- a/test/nvim-shim +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: Unlicense - -# This is free and unencumbered software released into the public domain. -# -# Anyone is free to copy, modify, publish, use, compile, sell, or distribute -# this software, either in source code form or as a compiled binary, for any -# purpose, commercial or non-commercial, and by any means. -# -# In jurisdictions that recognize copyright laws, the author or authors of -# this software dedicate any and all copyright interest in the software to -# the public domain. We make this dedication for the benefit of the public -# at large and to the detriment of our heirs and successors. We intend this -# dedication to be an overt act of relinquishment in perpetuity of all -# present and future rights to this software under copyright law. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# For more information, please refer to - - -# A shim which acts as a command-line interface adapter to use Neovim as a Lua -# interpreter. - -# Set custom XDG base directory paths to isolate the test Neovim from the -# user's own configuration and data files. -export XDG_CONFIG_HOME='test/xdg/config/' -export XDG_STATE_HOME='test/xdg/local/state/' -export XDG_DATA_HOME='test/xdg/local/share/' - -# Handle Lua command-line arguments; not all options are supported -while getopts 'ilEve:' opt; do - case $opt in - e) lua_expr=$OPTARG;; - v) nvim --version; exit;; - i | l | E) echo "Option '$opt' not supported by shim"; exit 1;; - esac -done - - -# We need to add this plugin to the custom configuration. The easiest way is -# to create a symlink. Why not always have a symlink in the project? The Lua -# language server will search for Lua files in every directory, so if it enters -# the symlink it will be trapped in a cycle. What we do instead is create the -# symlink only for the duration of a test session and remove it again -# afterwards. - -# We need separate symlinks if we want to run different tasks in parallel. -# Otherwise the one the finishes first would delete the symlink from underneath -# the one that is still running. -uuid=$(uuidgen) -mkdir -p ${XDG_DATA_HOME}/nvim/site/pack/self-${uuid}/start/ -ln -fs $(pwd) ${XDG_DATA_HOME}/nvim/site/pack/self-${uuid}/start/ - -if [ -n "$lua_expr" ]; then - nvim --headless -c "lua $lua_expr" -c 'quitall!' -else - # We have to explicitly enable plugins, see ':h -l' - nvim --cmd 'set loadplugins' -l $@ -fi - -exit_code=$? - -rm -rf ${XDG_DATA_HOME}/nvim/site/pack/self-${uuid}/ - -exit $exit_code