From 61c1bf8bfe949fb894a48e61f77830df99995ee6 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 31 Jul 2025 10:33:31 -0700 Subject: [PATCH] feat(luatest): create a self-contained test runner Adds a new scripts/run-luatest.sh script to provide a consistent, self-contained way to run project unit tests, including locally. The script handles: - Checking for necessary tools (rg, ag) - Cloning or updating plenary.nvim into the target/tests/deps directory The Makefile is updated to use this new script, making make luatest the single entry point for running unit tests. The lua.yaml workflow is simplified to use this new make target, ensuring the CI environment uses the exact same testing logic. --- .github/workflows/lua.yaml | 2 -- Makefile | 2 +- scripts/run-luatest.sh | 59 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100755 scripts/run-luatest.sh diff --git a/.github/workflows/lua.yaml b/.github/workflows/lua.yaml index 0290dae..c9778b4 100644 --- a/.github/workflows/lua.yaml +++ b/.github/workflows/lua.yaml @@ -48,8 +48,6 @@ jobs: run: | export PATH="${PWD}/_neovim/bin:${PATH}" export VIM="${PWD}/_neovim/share/nvim/runtime" - # install nvim-lua/plenary.nvim - git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim nvim --version make luatest diff --git a/Makefile b/Makefile index 69d8bbe..ea1c3a7 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,7 @@ rusttest: .PHONY: luatest luatest: - nvim --headless -c "PlenaryBustedDirectory tests/" + @./scripts/run-luatest.sh .PHONY: lint lint: luacheck luastylecheck ruststylecheck rustlint diff --git a/scripts/run-luatest.sh b/scripts/run-luatest.sh new file mode 100755 index 0000000..7b0ee9d --- /dev/null +++ b/scripts/run-luatest.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +set -e + +DEST_DIR="$PWD/target/tests" +DEPS_DIR="$DEST_DIR/deps" + +log() { + echo "$1" >&2 +} + +check_tools() { + command -v rg &>/dev/null || { + log "Error: ripgrep (rg) is not installed. Please install it." + exit 1 + } + command -v ag &>/dev/null || { + log "Error: silversearcher-ag (ag) is not installed. Please install it." + exit 1 + } +} + +setup_deps() { + local plenary_path="$DEPS_DIR/plenary.nvim" + if [ -d "$plenary_path/.git" ]; then + log "plenary.nvim already exists. Updating..." + ( + cd "$plenary_path" + git fetch -q + if git show-ref --verify --quiet refs/remotes/origin/main; then + git reset -q --hard origin/main + elif git show-ref --verify --quiet refs/remotes/origin/master; then + git reset -q --hard origin/master + fi + ) + else + if [ -d "$plenary_path" ]; then + log "Removing non-git plenary.nvim directory and re-cloning." + rm -rf "$plenary_path" + fi + log "Cloning plenary.nvim..." + mkdir -p "$DEPS_DIR" + git clone --depth 1 "https://github.com/nvim-lua/plenary.nvim.git" "$plenary_path" + fi +} + +run_tests() { + log "Running tests..." + nvim --headless --clean \ + -c "set runtimepath+=$DEPS_DIR/plenary.nvim" \ + -c "lua require('plenary.test_harness').test_directory('tests/', { minimal_init = 'NONE' })" +} + +main() { + check_tools + setup_deps + run_tests +} + +main "$@"