diff --git a/.actrc b/.actrc new file mode 100644 index 0000000..483cd68 --- /dev/null +++ b/.actrc @@ -0,0 +1,3 @@ +# Act configuration for local CI testing +--platform ubuntu-latest=catthehacker/ubuntu:act-latest +--pull=false diff --git a/.busted b/.busted new file mode 100644 index 0000000..7ae8144 --- /dev/null +++ b/.busted @@ -0,0 +1,13 @@ +return { + _all = { + coverage = false, + lpath = "lua/?.lua;lua/?/init.lua", + lua = "nlua", + pattern = ".*_spec%.lua", + ROOT = { "tests" }, + verbose = true, + ["suppress-pending"] = false, + ["show-error-list"] = true, + }, +} + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b5d766..a98ca92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,13 +10,41 @@ on: jobs: tests: + name: Run tests runs-on: ubuntu-latest timeout-minutes: 5 + strategy: + matrix: + neovim_version: ["nightly", "stable"] steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential gcc make luarocks lua5.1 liblua5.1-dev + - name: Setup Neovim + uses: rhysd/action-setup-vim@v1 with: neovim: true - version: nightly - - name: Run Tests - run: make test + version: ${{ matrix.neovim_version }} + - name: Install test dependencies + run: | + sudo luarocks install busted + sudo luarocks install nlua + sudo luarocks install luassert + - name: Run tests + env: + NEOVIM_VERSION: ${{ matrix.neovim_version }} + run: | + set -euo pipefail + export PATH="/usr/local/bin:$PATH" + + echo "Running tests for Neovim ${{ matrix.neovim_version }}..." + echo "================================================" + + if [ -f "scripts/test-runner.sh" ]; then + chmod +x scripts/test-runner.sh + ./scripts/test-runner.sh || exit $? + else + busted --verbose tests/ || exit $? + fi diff --git a/.github/workflows/luarocks.yml b/.github/workflows/luarocks.yml index 68d8d45..19d876c 100644 --- a/.github/workflows/luarocks.yml +++ b/.github/workflows/luarocks.yml @@ -4,7 +4,6 @@ on: push: tags: # Will upload to luarocks.org when a tag is pushed - "*" - pull_request: # Will test a local install without uploading to luarocks.org workflow_dispatch: jobs: diff --git a/.gitignore b/.gitignore index 86c495e..002b49e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,16 @@ /.tests /test +.env +.env.* +*.private +*.secret +.actrc.local +.luarocks/ +*.rock +*.src.rock +.DS_Store +*.swp +*.swo +*~ +.vscode/ +.idea/ diff --git a/Makefile b/Makefile index c3f74a0..cb898e4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,25 @@ -.PHONY: test +.PHONY: test test-verbose test-minimal test-tap test-ci test-stable test-nightly test: - nvim -l ./tests/busted.lua tests/ + @./scripts/test-runner.sh + +test-verbose: + @./scripts/test-runner.sh --verbose + +test-minimal: + @./scripts/test-runner.sh --minimal + +test-tap: + @./scripts/test-runner.sh --tap + +test-ci: + @command -v act >/dev/null 2>&1 || { echo "act is not installed"; exit 1; } + act -W .github/workflows/ci.yml + +test-ci-stable: + @command -v act >/dev/null 2>&1 || { echo "act is not installed"; exit 1; } + act -W .github/workflows/ci.yml -j tests --matrix neovim_version:stable + +test-ci-nightly: + @command -v act >/dev/null 2>&1 || { echo "act is not installed"; exit 1; } + act -W .github/workflows/ci.yml -j tests --matrix neovim_version:nightly diff --git a/image.nvim-scm-1.rockspec b/image.nvim-scm-1.rockspec index 697ad0c..3b965ca 100644 --- a/image.nvim-scm-1.rockspec +++ b/image.nvim-scm-1.rockspec @@ -18,10 +18,25 @@ dependencies = { } source = { - url = "git://github.com/3rd/image.nvim" + url = "git://github.com/3rd/image.nvim", } -test_dependencies = {} +test_dependencies = { + "nlua", + "busted", + "luassert", +} + +test = { + type = "busted", + platforms = { + unix = { + flags = { + "--config-file=.busted", + }, + }, + }, +} build = { type = "builtin", diff --git a/scripts/test-runner.sh b/scripts/test-runner.sh new file mode 100755 index 0000000..9d4890e --- /dev/null +++ b/scripts/test-runner.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +set -o pipefail + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color +BOLD='\033[1m' + +color() { + echo -e "${1}${2}${NC}" +} + +# Header +echo "" +color "${CYAN}${BOLD}" "╔══════════════════════════════════════════════════════════════╗" +color "${CYAN}${BOLD}" "║ image.nvim Test Suite ║" +color "${CYAN}${BOLD}" "╚══════════════════════════════════════════════════════════════╝" +echo "" + +# check if running in CI +if [ -n "$CI" ]; then + color "${BLUE}" "Environment: GitHub Actions CI" + color "${BLUE}" "Neovim Version: ${NEOVIM_VERSION:-unknown}" +else + color "${BLUE}" "Environment: Local" + if command -v nvim &>/dev/null; then + NVIM_VERSION=$(nvim --version | head -n1) + color "${BLUE}" "Neovim Version: $NVIM_VERSION" + fi +fi + +echo "" +color "${YELLOW}" "Test Files:" +color "${YELLOW}" "───────────" + +# list test files +for file in tests/**/*_spec.lua; do + if [ -f "$file" ]; then + echo " • $(basename $file)" + fi +done + +echo "" +color "${CYAN}" "Running Tests..." +color "${CYAN}" "════════════════" +echo "" + +if [ "$1" == "--tap" ]; then + # TAP + busted --output=TAP --verbose tests/ + TEST_RESULT=$? +elif [ "$1" == "--minimal" ]; then + # minimal output + busted tests/ + TEST_RESULT=$? +else + # default: verbose + busted --output=gtest --verbose tests/ 2>&1 | sed 's/^/ /' + TEST_RESULT=${PIPESTATUS[0]} +fi + +echo "" +color "${CYAN}" "════════════════" + +# summary +if [ $TEST_RESULT -eq 0 ]; then + echo "" + color "${GREEN}${BOLD}" "✓ All tests passed!" + echo "" +else + echo "" + color "${RED}${BOLD}" "✗ Tests failed!" + echo "" + exit $TEST_RESULT +fi +