From c031f7077245e85e1b2c174820d2cdfd282f0a00 Mon Sep 17 00:00:00 2001 From: Asiel Cabrera Date: Sun, 3 May 2026 16:00:49 -0400 Subject: [PATCH] test: initialize test suite with plenary.nvim Adds tests/minimal_init.lua, a unit test for project_detector, and configures GitHub Actions CI to run tests on pull requests. --- .github/workflows/ci.yml | 4 ++++ tests/minimal_init.lua | 19 +++++++++++++++++++ tests/swift/project_detector_spec.lua | 23 +++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/minimal_init.lua create mode 100644 tests/swift/project_detector_spec.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e696fb3..41f1fc4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,10 @@ jobs: nvim --version nvim --headless -c "checkhealth swift" -c "quit" || true + - name: Run Unit Tests + run: | + nvim --headless -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }" + labeler: name: Auto Label runs-on: ubuntu-latest diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua new file mode 100644 index 0000000..ba40343 --- /dev/null +++ b/tests/minimal_init.lua @@ -0,0 +1,19 @@ +local root = vim.fn.fnamemodify("./.tests", ":p") + +-- set stdpaths to use .tests +for _, name in ipairs({ "config", "data", "state", "cache" }) do + vim.env[string.format("XDG_%s_HOME", name:upper())] = root .. "/" .. name +end + +local function load_plugin(plugin_repo) + local name = plugin_repo:match(".*/(.*)%.git") or plugin_repo:match(".*/(.*)") + local plugin_path = root .. "/plugins/" .. name + if vim.fn.isdirectory(plugin_path) == 0 then + vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/" .. plugin_repo, plugin_path }) + end + vim.opt.runtimepath:prepend(plugin_path) +end + +load_plugin("nvim-lua/plenary.nvim") + +vim.opt.runtimepath:prepend(".") diff --git a/tests/swift/project_detector_spec.lua b/tests/swift/project_detector_spec.lua new file mode 100644 index 0000000..8d2418a --- /dev/null +++ b/tests/swift/project_detector_spec.lua @@ -0,0 +1,23 @@ +local detector = require("swift.features.project_detector") + +describe("Project Detector", function() + it("should be able to require the module", function() + assert.is_not_nil(detector) + end) + + it("should return none when no project files are found", function() + local temp_dir = vim.fn.tempname() + vim.fn.mkdir(temp_dir, "p") + + local old_cwd = vim.fn.getcwd() + vim.api.nvim_set_current_dir(temp_dir) + + -- Force refresh cache + local info = detector.get_project_info(true) + + assert.are.same("none", info.type) + + vim.api.nvim_set_current_dir(old_cwd) + vim.fn.delete(temp_dir, "rf") + end) +end)