From cbe72160b957b3d719f273e9a83f122fb1bc2723 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Thu, 9 Apr 2026 11:36:41 -0600 Subject: [PATCH] ci: add GitHub Actions workflow and minimal test suite --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++ scripts/minimal_init.lua | 4 +++ scripts/test.sh | 11 ++++++++ tests/test_init.lua | 55 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 scripts/minimal_init.lua create mode 100755 scripts/test.sh create mode 100644 tests/test_init.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dea83c1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: JohnnyMorganz/stylua-action@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check lua/ plugin/ + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Neovim + run: | + wget -q https://github.com/neovim/neovim/releases/download/v0.12.0/nvim-linux-x86_64.appimage -O /tmp/nvim.appimage + chmod +x /tmp/nvim.appimage + /tmp/nvim.appimage --appimage-extract > /dev/null 2>&1 + echo "$PWD/squashfs-root/usr/bin" >> $GITHUB_PATH + - name: Run tests + run: ./scripts/test.sh diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua new file mode 100644 index 0000000..bfa1468 --- /dev/null +++ b/scripts/minimal_init.lua @@ -0,0 +1,4 @@ +-- Minimal init for testing tiny-packupdate.nvim +vim.opt.rtp:prepend(".") +vim.opt.rtp:prepend("deps/mini.nvim") +vim.cmd("runtime plugin/tiny-packupdate.lua") diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..f54b001 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Clone mini.nvim for test framework (if not cached) +if [ ! -d deps/mini.nvim ]; then + mkdir -p deps + git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim +fi + +# Run tests +nvim --headless -u scripts/minimal_init.lua -c "lua require('mini.test').setup(); MiniTest.run_file('tests/test_init.lua')" diff --git a/tests/test_init.lua b/tests/test_init.lua new file mode 100644 index 0000000..e943780 --- /dev/null +++ b/tests/test_init.lua @@ -0,0 +1,55 @@ +local T = MiniTest.new_set() +local eq = MiniTest.expect.equality + +-- ── Setup tests ─────────────────────────────────────────────────────── + +T["setup"] = MiniTest.new_set() + +T["setup"]["creates user command with default name"] = function() + -- plugin/ auto-loaded via minimal_init, so PackUpdate should exist + local cmds = vim.api.nvim_get_commands({}) + eq(cmds["PackUpdate"] ~= nil, true) +end + +T["setup"]["respects custom command name"] = function() + require("tiny-packupdate").setup({ command = "PlugSync" }) + local cmds = vim.api.nvim_get_commands({}) + eq(cmds["PlugSync"] ~= nil, true) + -- Cleanup: delete the custom command + vim.api.nvim_del_user_command("PlugSync") +end + +T["setup"]["is idempotent"] = function() + -- Calling setup twice should not error + require("tiny-packupdate").setup() + require("tiny-packupdate").setup() + local cmds = vim.api.nvim_get_commands({}) + eq(cmds["PackUpdate"] ~= nil, true) +end + +T["setup"]["sets highlight group"] = function() + require("tiny-packupdate").setup() + local hl = vim.api.nvim_get_hl(0, { name = "TinyPackProgress" }) + eq(hl.link ~= nil or hl.fg ~= nil, true) +end + +-- ── Timestamp tests ─────────────────────────────────────────────────── + +T["timestamp"] = MiniTest.new_set() + +T["timestamp"]["roundtrip read/write"] = function() + local path = vim.fn.stdpath("data") .. "/tiny-packupdate-last" + -- Write a known timestamp + local f = io.open(path, "w") + f:write("1700000000") + f:close() + -- Read it back through the module's stamp path + local f2 = io.open(path, "r") + local val = tonumber(f2:read("*a")) + f2:close() + eq(val, 1700000000) + -- Cleanup + os.remove(path) +end + +return T