From f453855b805cc7736618dffeb2889aec93971a3d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:10:25 +0000 Subject: [PATCH 01/14] Initial plan From 1c6a361b7768389f89808711c8916d2f704e045f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:15:07 +0000 Subject: [PATCH 02/14] Add unit tests infrastructure and CI pipeline Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- .github/workflows/test.yml | 36 ++++++++++++ .gitignore | 3 + Makefile | 20 +++++++ tests/lazydocker/actions/open_spec.lua | 9 +++ tests/lazydocker/config_spec.lua | 72 +++++++++++++++++++++++ tests/lazydocker/init_spec.lua | 27 +++++++++ tests/lazydocker/state_spec.lua | 19 ++++++ tests/lazydocker/utils/constants_spec.lua | 15 +++++ tests/lazydocker/utils/logger_spec.lua | 27 +++++++++ tests/minimal_init.lua | 12 ++++ 10 files changed, 240 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 Makefile create mode 100644 tests/lazydocker/actions/open_spec.lua create mode 100644 tests/lazydocker/config_spec.lua create mode 100644 tests/lazydocker/init_spec.lua create mode 100644 tests/lazydocker/state_spec.lua create mode 100644 tests/lazydocker/utils/constants_spec.lua create mode 100644 tests/lazydocker/utils/logger_spec.lua create mode 100644 tests/minimal_init.lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9b75a81 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Tests + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + test: + name: Run Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + neovim-version: ['stable', 'nightly'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Neovim + uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: ${{ matrix.neovim-version }} + + - name: Setup test environment + run: | + mkdir -p deps + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim + + - name: Run tests + run: | + nvim --version + nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }" diff --git a/.gitignore b/.gitignore index 6fd0a37..217f020 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ luac.out *.x86_64 *.hex +# Test dependencies +deps/ + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2c31827 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: test prepare + +# Prepare test environment by cloning plenary.nvim +prepare: + @echo "Preparing test environment..." + @mkdir -p deps + @if [ ! -d "deps/plenary.nvim" ]; then \ + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim; \ + fi + @echo "Test environment ready!" + +# Run all tests +test: prepare + @echo "Running tests..." + nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }" + +# Clean test dependencies +clean: + @echo "Cleaning test dependencies..." + @rm -rf deps diff --git a/tests/lazydocker/actions/open_spec.lua b/tests/lazydocker/actions/open_spec.lua new file mode 100644 index 0000000..dfa7f18 --- /dev/null +++ b/tests/lazydocker/actions/open_spec.lua @@ -0,0 +1,9 @@ +local open = require("lazydocker.actions.open") + +describe("actions.open", function() + describe("run", function() + it("should be a function", function() + assert.is_function(open.run) + end) + end) +end) diff --git a/tests/lazydocker/config_spec.lua b/tests/lazydocker/config_spec.lua new file mode 100644 index 0000000..e457258 --- /dev/null +++ b/tests/lazydocker/config_spec.lua @@ -0,0 +1,72 @@ +local config = require("lazydocker.config") + +describe("config", function() + describe("__DEFAULT_OPTIONS", function() + it("should have default options", function() + assert.is_table(config.__DEFAULT_OPTIONS) + end) + + it("should have border option with default value", function() + assert.equals("double", config.__DEFAULT_OPTIONS.border) + end) + end) + + describe("options", function() + it("should be initialized with default options", function() + assert.is_table(config.options) + assert.equals("double", config.options.border) + end) + end) + + describe("__register_namespace", function() + it("should be a function", function() + assert.is_function(config.__register_namespace) + end) + end) + + describe("__register_user_options", function() + it("should be a function", function() + assert.is_function(config.__register_user_options) + end) + + it("should merge user options with defaults", function() + local user_options = { border = "single" } + config.__register_user_options(user_options) + assert.equals("single", config.options.border) + end) + + it("should use defaults when user options are nil", function() + config.__register_user_options(nil) + assert.equals("double", config.options.border) + end) + + it("should keep default values for missing user options", function() + config.__register_user_options({}) + assert.equals("double", config.options.border) + end) + end) + + describe("__prepare_augroup", function() + it("should be a function", function() + assert.is_function(config.__prepare_augroup) + end) + end) + + describe("__register_commands", function() + it("should be a function", function() + assert.is_function(config.__register_commands) + end) + end) + + describe("setup", function() + it("should be a function", function() + assert.is_function(config.setup) + end) + + it("should setup config with user options", function() + local user_options = { border = "curved" } + config.setup(user_options) + assert.equals("curved", config.options.border) + end) + end) +end) diff --git a/tests/lazydocker/init_spec.lua b/tests/lazydocker/init_spec.lua new file mode 100644 index 0000000..ad107ad --- /dev/null +++ b/tests/lazydocker/init_spec.lua @@ -0,0 +1,27 @@ +local lazydocker = require("lazydocker") + +describe("init", function() + describe("setup", function() + it("should be a function", function() + assert.is_function(lazydocker.setup) + end) + + it("should setup without errors", function() + assert.has_no.errors(function() + lazydocker.setup() + end) + end) + + it("should accept options", function() + assert.has_no.errors(function() + lazydocker.setup({ border = "single" }) + end) + end) + end) + + describe("open", function() + it("should be a function", function() + assert.is_function(lazydocker.open) + end) + end) +end) diff --git a/tests/lazydocker/state_spec.lua b/tests/lazydocker/state_spec.lua new file mode 100644 index 0000000..f423e3f --- /dev/null +++ b/tests/lazydocker/state_spec.lua @@ -0,0 +1,19 @@ +local state = require("lazydocker.state") + +describe("state", function() + describe("namespace", function() + it("should exist", function() + assert.is_table(state.namespace) + end) + + it("should have create function", function() + assert.is_function(state.namespace.create) + end) + + it("should create namespace with valid id", function() + state.namespace.create() + assert.is_not_nil(state.namespace.id) + assert.is_number(state.namespace.id) + end) + end) +end) diff --git a/tests/lazydocker/utils/constants_spec.lua b/tests/lazydocker/utils/constants_spec.lua new file mode 100644 index 0000000..a3240ee --- /dev/null +++ b/tests/lazydocker/utils/constants_spec.lua @@ -0,0 +1,15 @@ +local constants = require("lazydocker.utils.constants") + +describe("constants", function() + it("should have COMMANDS table", function() + assert.is_table(constants.COMMANDS) + end) + + it("should have open command", function() + assert.equals("Lazydocker", constants.COMMANDS.open) + end) + + it("should have AUTOGROUP constant", function() + assert.equals("LazydockerAutogroup", constants.AUTOGROUP) + end) +end) diff --git a/tests/lazydocker/utils/logger_spec.lua b/tests/lazydocker/utils/logger_spec.lua new file mode 100644 index 0000000..3623286 --- /dev/null +++ b/tests/lazydocker/utils/logger_spec.lua @@ -0,0 +1,27 @@ +local logger = require("lazydocker.utils.logger") + +describe("logger", function() + describe("__print", function() + it("should be a function", function() + assert.is_function(logger.__print) + end) + end) + + describe("error", function() + it("should be a function", function() + assert.is_function(logger.error) + end) + end) + + describe("warn", function() + it("should be a function", function() + assert.is_function(logger.warn) + end) + end) + + describe("info", function() + it("should be a function", function() + assert.is_function(logger.info) + end) + end) +end) diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua new file mode 100644 index 0000000..c183821 --- /dev/null +++ b/tests/minimal_init.lua @@ -0,0 +1,12 @@ +-- Minimal init file for running tests +-- This ensures the plugin can be loaded in test environment + +-- Add the plugin directory to the runtime path +vim.cmd([[set runtimepath+=.]]) + +-- Add plenary to runtime path (will be cloned in CI) +vim.cmd([[set runtimepath+=deps/plenary.nvim]]) + +-- Disable swapfile and backup for tests +vim.opt.swapfile = false +vim.opt.backup = false From 15949d8f33a911428b35873997a4f19d5c20a71c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:15:44 +0000 Subject: [PATCH 03/14] Add testing documentation to README Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index d229424..f513adf 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,37 @@ require("lazydocker").setup({ ``` **Note**: If you don't specify `width` or `height`, the plugin will use the default values (0.9), ensuring backward compatibility. +## 🧪 Development + +### Running Tests + +This project includes a comprehensive test suite using [plenary.nvim](https://github.com/nvim-lua/plenary.nvim). + +To run tests locally: + +```bash +make test +``` + +This will: +1. Clone `plenary.nvim` into `deps/` directory +2. Run all tests using Neovim in headless mode + +To clean test dependencies: + +```bash +make clean +``` + +### CI/CD + +The project uses GitHub Actions to automatically run tests on: +- Every push to `main`/`master` branch +- Every pull request +- Multiple OS platforms (Ubuntu, macOS) +- Multiple Neovim versions (stable, nightly) + +See `.github/workflows/test.yml` for the full CI configuration. ## Star History From 72d31fc743345cc80e21241542a975ba33d90715 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:17:09 +0000 Subject: [PATCH 04/14] Add test status badge to README Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f513adf..3b7a2b8 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ ![License](https://img.shields.io/badge/License-MIT-brightgreen?style=flat-square) ![Status](https://img.shields.io/badge/Status-Stable-informational?style=flat-square) ![Neovim](https://img.shields.io/badge/Neovim-0.9+-green.svg?style=flat-square&logo=Neovim&logoColor=white) +[![Tests](https://github.com/mgierada/lazydocker.nvim/workflows/Tests/badge.svg)](https://github.com/mgierada/lazydocker.nvim/actions/workflows/test.yml) [![Default keymaps](https://img.shields.io/badge/Default%20keymaps-Documentation-blue.svg)](https://github.com/jesseduffield/lazydocker/blob/master/docs/keybindings/Keybindings_en.md) From aa8ca0bbd052604ff610dc4b5e91a58614755640 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:18:49 +0000 Subject: [PATCH 05/14] Fix GitHub Actions workflow permissions for security Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b75a81..92dac87 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ jobs: test: name: Run Tests runs-on: ${{ matrix.os }} + permissions: + contents: read strategy: matrix: os: [ubuntu-latest, macos-latest] From f54d18d371114b2757498b963e5d69e06eaecff5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:31:46 +0000 Subject: [PATCH 06/14] Address PR feedback: run tests only on main branch, use checkout v5 Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- .github/workflows/test.yml | 6 ++---- README.md | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 92dac87..346cd9a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,7 @@ name: Tests on: push: - branches: [main, master] - pull_request: - branches: [main, master] + branches: [main] jobs: test: @@ -19,7 +17,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Install Neovim uses: rhysd/action-setup-vim@v1 diff --git a/README.md b/README.md index 3b7a2b8..e5116f9 100644 --- a/README.md +++ b/README.md @@ -191,10 +191,9 @@ make clean ### CI/CD The project uses GitHub Actions to automatically run tests on: -- Every push to `main`/`master` branch -- Every pull request +- Every push to `main` branch - Multiple OS platforms (Ubuntu, macOS) -- Multiple Neovim versions (stable, nightly) +- Neovim versions (stable, nightly) See `.github/workflows/test.yml` for the full CI configuration. From 720f94d07bd11386856f24e884819106e022c3f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 10:13:14 +0000 Subject: [PATCH 07/14] Fix test execution command in workflow and Makefile Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- .github/workflows/test.yml | 2 +- Makefile | 2 +- tests/run.lua | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/run.lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 346cd9a..c816ce7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,4 +33,4 @@ jobs: - name: Run tests run: | nvim --version - nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }" + nvim --headless -u tests/minimal_init.lua -c "lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" diff --git a/Makefile b/Makefile index 2c31827..73a0513 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ prepare: # Run all tests test: prepare @echo "Running tests..." - nvim --headless --noplugin -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }" + nvim --headless -u tests/minimal_init.lua -c "lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" # Clean test dependencies clean: diff --git a/tests/run.lua b/tests/run.lua new file mode 100644 index 0000000..768ac05 --- /dev/null +++ b/tests/run.lua @@ -0,0 +1,11 @@ +-- Test runner script for plenary.nvim +-- This script loads the test framework and runs all tests + +-- Load plenary test harness +require("plenary.test_harness").test_directory( + "tests", + { + minimal_init = "tests/minimal_init.lua", + sequential = false, + } +) From 9a8a69a5c23c457ec3a6ba25c70d3c7ff4332137 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:36:26 +0000 Subject: [PATCH 08/14] Fix test command to exit nvim after running and add timeout Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- .github/workflows/test.yml | 3 ++- Makefile | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c816ce7..76d1984 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,7 @@ jobs: git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim - name: Run tests + timeout-minutes: 10 run: | nvim --version - nvim --headless -u tests/minimal_init.lua -c "lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" + nvim --headless -u tests/minimal_init.lua +"lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" +qall diff --git a/Makefile b/Makefile index 73a0513..aa6019e 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ prepare: # Run all tests test: prepare @echo "Running tests..." - nvim --headless -u tests/minimal_init.lua -c "lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" + nvim --headless -u tests/minimal_init.lua +"lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" +qall # Clean test dependencies clean: From 6def7ffe846f8e1b1341316f8be443ec2e0ace7f Mon Sep 17 00:00:00 2001 From: Maciej Gierada Date: Mon, 17 Nov 2025 17:44:34 +0100 Subject: [PATCH 09/14] fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5116f9..af97947 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ make clean The project uses GitHub Actions to automatically run tests on: - Every push to `main` branch -- Multiple OS platforms (Ubuntu, macOS) +- OS platforms (Ubuntu, macOS) - Neovim versions (stable, nightly) See `.github/workflows/test.yml` for the full CI configuration. From b411a10167d6a55e20b137ce067eceaa162562b2 Mon Sep 17 00:00:00 2001 From: Maciej Gierada Date: Mon, 17 Nov 2025 17:46:15 +0100 Subject: [PATCH 10/14] feat: run tests on pull_request --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76d1984..07baa22 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: Tests on: + pull_request: push: branches: [main] @@ -13,8 +14,8 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest] - neovim-version: ['stable', 'nightly'] - + neovim-version: ["stable", "nightly"] + steps: - name: Checkout code uses: actions/checkout@v5 From 5b60ec10d4345639ecca86208568f4c10c39a32e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 16:51:47 +0000 Subject: [PATCH 11/14] Fix test exit: use cquit to properly terminate nvim after tests Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- .github/workflows/test.yml | 2 +- Makefile | 2 +- tests/run.lua | 30 ++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07baa22..07744e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,4 +35,4 @@ jobs: timeout-minutes: 10 run: | nvim --version - nvim --headless -u tests/minimal_init.lua +"lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" +qall + nvim --headless -u tests/minimal_init.lua -c "luafile tests/run.lua" diff --git a/Makefile b/Makefile index aa6019e..abc19c8 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ prepare: # Run all tests test: prepare @echo "Running tests..." - nvim --headless -u tests/minimal_init.lua +"lua require('plenary.test_harness').test_directory('tests', { minimal_init = 'tests/minimal_init.lua' })" +qall + nvim --headless -u tests/minimal_init.lua -c "luafile tests/run.lua" # Clean test dependencies clean: diff --git a/tests/run.lua b/tests/run.lua index 768ac05..6dc4d86 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -1,11 +1,25 @@ -- Test runner script for plenary.nvim -- This script loads the test framework and runs all tests --- Load plenary test harness -require("plenary.test_harness").test_directory( - "tests", - { - minimal_init = "tests/minimal_init.lua", - sequential = false, - } -) +-- Store the exit code +local exit_code = 0 + +-- Wrap test execution to capture failures +local ok, result = pcall(function() + require("plenary.test_harness").test_directory( + "tests", + { + minimal_init = "tests/minimal_init.lua", + sequential = false, + } + ) +end) + +-- Set exit code based on result +if not ok then + print("Test execution failed: " .. tostring(result)) + exit_code = 1 +end + +-- Force exit with the appropriate code +vim.cmd("cquit " .. exit_code) From ea611c514838c410fe15a75939faea0f608cf8e0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:47:37 +0000 Subject: [PATCH 12/14] Fix exit code: use quit for success instead of cquit Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- tests/run.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/run.lua b/tests/run.lua index 6dc4d86..48af4fd 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -22,4 +22,9 @@ if not ok then end -- Force exit with the appropriate code -vim.cmd("cquit " .. exit_code) +-- Use :quit for success (exit code 0) and :cquit for failure (exit code 1) +if exit_code == 0 then + vim.cmd("quit") +else + vim.cmd("cquit") +end From c2c0928a06b1b188893777af7c42161ca530cb30 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Nov 2025 08:41:47 +0000 Subject: [PATCH 13/14] Fix test exit code: use os.exit() instead of vim commands Co-authored-by: mgierada <23472449+mgierada@users.noreply.github.com> --- tests/run.lua | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/run.lua b/tests/run.lua index 48af4fd..5bd346f 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -1,12 +1,9 @@ -- Test runner script for plenary.nvim -- This script loads the test framework and runs all tests --- Store the exit code -local exit_code = 0 - --- Wrap test execution to capture failures -local ok, result = pcall(function() - require("plenary.test_harness").test_directory( +-- Run tests and get results +local ok, results = pcall(function() + return require("plenary.test_harness").test_directory( "tests", { minimal_init = "tests/minimal_init.lua", @@ -15,16 +12,22 @@ local ok, result = pcall(function() ) end) --- Set exit code based on result +-- Check if there were any errors or failures +local exit_code = 0 + if not ok then - print("Test execution failed: " .. tostring(result)) + -- pcall failed - there was an error running tests + print("Test execution error: " .. tostring(results)) exit_code = 1 +elseif type(results) == "table" then + -- Check test results for failures + if results.fail and results.fail > 0 then + exit_code = 1 + elseif results.errs and results.errs > 0 then + exit_code = 1 + end end --- Force exit with the appropriate code --- Use :quit for success (exit code 0) and :cquit for failure (exit code 1) -if exit_code == 0 then - vim.cmd("quit") -else - vim.cmd("cquit") -end +-- Exit with appropriate code +-- Use os.exit to ensure proper exit code +os.exit(exit_code) From 4efb44b67d955dca8a7f53a9fef1f851764cd1ca Mon Sep 17 00:00:00 2001 From: Maciej Gierada Date: Tue, 7 Apr 2026 20:56:25 +0200 Subject: [PATCH 14/14] feat: add toggle term as deps and remove the weird copilot code that handled closing - plenary already handles closing --- .github/workflows/test.yml | 1 + Makefile | 6 +++--- tests/minimal_init.lua | 3 +++ tests/run.lua | 36 +++++------------------------------- 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07744e1..47b609b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,7 @@ jobs: run: | mkdir -p deps git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim + git clone --depth 1 https://github.com/akinsho/toggleterm.nvim deps/toggleterm.nvim - name: Run tests timeout-minutes: 10 diff --git a/Makefile b/Makefile index abc19c8..2a1e753 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,20 @@ .PHONY: test prepare -# Prepare test environment by cloning plenary.nvim prepare: @echo "Preparing test environment..." @mkdir -p deps @if [ ! -d "deps/plenary.nvim" ]; then \ git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim; \ fi + @if [ ! -d "deps/toggleterm.nvim" ]; then \ + git clone --depth 1 https://github.com/akinsho/toggleterm.nvim deps/toggleterm.nvim; \ + fi @echo "Test environment ready!" -# Run all tests test: prepare @echo "Running tests..." nvim --headless -u tests/minimal_init.lua -c "luafile tests/run.lua" -# Clean test dependencies clean: @echo "Cleaning test dependencies..." @rm -rf deps diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index c183821..1f3734e 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -7,6 +7,9 @@ vim.cmd([[set runtimepath+=.]]) -- Add plenary to runtime path (will be cloned in CI) vim.cmd([[set runtimepath+=deps/plenary.nvim]]) +-- Add toggleterm to runtime path (will be cloned in CI) +vim.cmd([[set runtimepath+=deps/toggleterm.nvim]]) + -- Disable swapfile and backup for tests vim.opt.swapfile = false vim.opt.backup = false diff --git a/tests/run.lua b/tests/run.lua index 5bd346f..94afec5 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -1,33 +1,7 @@ -- Test runner script for plenary.nvim --- This script loads the test framework and runs all tests --- Run tests and get results -local ok, results = pcall(function() - return require("plenary.test_harness").test_directory( - "tests", - { - minimal_init = "tests/minimal_init.lua", - sequential = false, - } - ) -end) - --- Check if there were any errors or failures -local exit_code = 0 - -if not ok then - -- pcall failed - there was an error running tests - print("Test execution error: " .. tostring(results)) - exit_code = 1 -elseif type(results) == "table" then - -- Check test results for failures - if results.fail and results.fail > 0 then - exit_code = 1 - elseif results.errs and results.errs > 0 then - exit_code = 1 - end -end - --- Exit with appropriate code --- Use os.exit to ensure proper exit code -os.exit(exit_code) +-- Run tests - plenary handles exit codes internally via vim.cmd "0cq"/"1cq" +require("plenary.test_harness").test_directory("tests", { + minimal_init = "tests/minimal_init.lua", + sequential = true, +})