From 063b90dd7210c60827900f37c02cf55ef8e2739e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 8 Feb 2026 16:39:05 -0500 Subject: [PATCH 01/10] test: add tests for all remaining tools Problem: most formatters and linters in guard-collection had no test coverage. The csharpier binary was renamed in v1.0+ and ruff's -e flag was deprecated in favor of the check subcommand. Solution: add 42 test files covering every remaining tool, fix the csharpier and ruff definitions, extend the install script with gz/jar archive types, add 6 new CI jobs (dotnet, ruby, clojure, elixir, nix, swift), and expand existing jobs with newly tested tools. --- .github/scripts/install-binary-tools.sh | 7 +- .github/tools/binary.txt | 15 ++- .github/tools/go.txt | 2 + .github/tools/npm.txt | 1 + .github/tools/pip.txt | 5 + .github/workflows/ci.yaml | 124 +++++++++++++++++++++++- Makefile | 21 +++- test/binary/buf_spec.lua | 35 ++++++- test/binary/cbfmt_spec.lua | 24 ++--- test/binary/dart_spec.lua | 9 ++ test/binary/detekt_spec.lua | 19 ++-- test/binary/dprint_spec.lua | 34 +++---- test/binary/fish_indent_spec.lua | 14 +++ test/binary/google-java-format_spec.lua | 9 ++ test/binary/hadolint_spec.lua | 24 +++-- test/binary/jq_spec.lua | 13 +++ test/binary/ktfmt_spec.lua | 9 ++ test/binary/ktlint_spec.lua | 42 +++++--- test/binary/ormolu_spec.lua | 13 +++ test/binary/pg_format_spec.lua | 9 ++ test/binary/shellcheck_spec.lua | 26 +++-- test/binary/shfmt_spec.lua | 16 +++ test/binary/tombi_spec.lua | 16 +++ test/binary/typos_spec.lua | 14 +++ test/binary/typstyle_spec.lua | 10 ++ test/binary/xmllint_spec.lua | 13 +++ test/binary/zigfmt_spec.lua | 10 ++ test/clojure/cljfmt_spec.lua | 11 +++ test/elixir/mixformat_spec.lua | 9 ++ test/go/goimports_spec.lua | 26 +++++ test/go/golangci_lint_spec.lua | 38 ++++---- test/go/yamlfmt_spec.lua | 12 +++ test/lua/fnlfmt_spec.lua | 10 ++ test/nix/nixfmt_spec.lua | 9 ++ test/npm/eslint_d_spec.lua | 68 ++++++++----- test/npm/eslint_spec.lua | 43 ++++---- test/npm/prettierd_spec.lua | 20 ++++ test/npm/stylelint_spec.lua | 52 ++++++---- test/pip/codespell_spec.lua | 15 +++ test/pip/djhtml_spec.lua | 14 +++ test/pip/isort_spec.lua | 14 +++ test/pip/mdformat_spec.lua | 13 +++ test/pip/mypyc_spec.lua | 29 ++++++ test/pip/pylint_spec.lua | 26 +++-- test/pip/ruff_spec.lua | 8 +- test/pip/yamlfix_spec.lua | 13 +++ test/ruby/rubocop_spec.lua | 52 ++++++++-- test/swift/swift_format_spec.lua | 9 ++ 48 files changed, 855 insertions(+), 170 deletions(-) create mode 100644 test/binary/dart_spec.lua create mode 100644 test/binary/fish_indent_spec.lua create mode 100644 test/binary/google-java-format_spec.lua create mode 100644 test/binary/jq_spec.lua create mode 100644 test/binary/ktfmt_spec.lua create mode 100644 test/binary/ormolu_spec.lua create mode 100644 test/binary/pg_format_spec.lua create mode 100644 test/binary/shfmt_spec.lua create mode 100644 test/binary/tombi_spec.lua create mode 100644 test/binary/typos_spec.lua create mode 100644 test/binary/typstyle_spec.lua create mode 100644 test/binary/xmllint_spec.lua create mode 100644 test/binary/zigfmt_spec.lua create mode 100644 test/clojure/cljfmt_spec.lua create mode 100644 test/elixir/mixformat_spec.lua create mode 100644 test/go/goimports_spec.lua create mode 100644 test/go/yamlfmt_spec.lua create mode 100644 test/lua/fnlfmt_spec.lua create mode 100644 test/nix/nixfmt_spec.lua create mode 100644 test/npm/prettierd_spec.lua create mode 100644 test/pip/codespell_spec.lua create mode 100644 test/pip/djhtml_spec.lua create mode 100644 test/pip/isort_spec.lua create mode 100644 test/pip/mdformat_spec.lua create mode 100644 test/pip/mypyc_spec.lua create mode 100644 test/pip/yamlfix_spec.lua create mode 100644 test/swift/swift_format_spec.lua diff --git a/.github/scripts/install-binary-tools.sh b/.github/scripts/install-binary-tools.sh index 3578406..648afb8 100755 --- a/.github/scripts/install-binary-tools.sh +++ b/.github/scripts/install-binary-tools.sh @@ -30,9 +30,14 @@ while read -r name type url extra; do chmod +x "$dest/$name" rm -rf "$tmpdir" ;; + gz) + wget -q "$url" -O "$dest/$name.gz" + gunzip "$dest/$name.gz" + chmod +x "$dest/$name" + ;; jar) wget -q "$url" -O "$dest/$name.jar" - printf '#!/usr/bin/env bash\nexec java -jar "%s/%s.jar" "$@"\n' "$(cd "$dest" && pwd)" "$name" > "$dest/$name" + printf '#!/bin/sh\njava -jar %s/%s.jar "$@"\n' "$dest" "$name" > "$dest/$name" chmod +x "$dest/$name" ;; esac diff --git a/.github/tools/binary.txt b/.github/tools/binary.txt index 5dcdab5..18a2224 100644 --- a/.github/tools/binary.txt +++ b/.github/tools/binary.txt @@ -1,12 +1,19 @@ alejandra bin https://github.com/kamadorueda/alejandra/releases/download/4.0.0/alejandra-x86_64-unknown-linux-musl buf bin https://github.com/bufbuild/buf/releases/download/v1.47.2/buf-Linux-x86_64 -hadolint bin https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 +cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt checkmake bin https://github.com/mrtazz/checkmake/releases/download/0.2.2/checkmake-0.2.2.linux.amd64 deno zip https://github.com/denoland/deno/releases/download/v2.1.4/deno-x86_64-unknown-linux-gnu.zip detekt jar https://github.com/detekt/detekt/releases/download/v1.23.7/detekt-cli-1.23.7-all.jar +dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip +google-java-format jar https://github.com/google/google-java-format/releases/download/v1.34.1/google-java-format-1.34.1-all-deps.jar +hadolint bin https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 hlint tar https://github.com/ndmitchell/hlint/releases/download/v3.10/hlint-3.10-x86_64-linux.tar.gz hlint-3.10/hlint +ktfmt jar https://repo1.maven.org/maven2/com/facebook/ktfmt/0.52/ktfmt-0.52-jar-with-dependencies.jar +ktlint bin https://github.com/pinterest/ktlint/releases/download/1.8.0/ktlint latexindent bin https://github.com/cmhughes/latexindent.pl/releases/download/V3.24.4/latexindent-linux +ormolu zip https://github.com/tweag/ormolu/releases/download/0.8.0.2/ormolu-x86_64-linux.zip +shfmt bin https://github.com/mvdan/sh/releases/download/v3.10.0/shfmt_v3.10.0_linux_amd64 swiftformat zip https://github.com/nicklockwood/SwiftFormat/releases/download/0.55.3/swiftformat_linux.zip swiftformat_linux -cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt -dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip -ktlint bin https://github.com/pinterest/ktlint/releases/download/1.8.0/ktlint +tombi gz https://github.com/tombi-toml/tombi/releases/download/v0.7.27/tombi-cli-0.7.27-x86_64-unknown-linux-musl.gz +typos tar https://github.com/crate-ci/typos/releases/download/v1.43.3/typos-v1.43.3-x86_64-unknown-linux-musl.tar.gz ./typos +typstyle bin https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-x86_64-unknown-linux-gnu diff --git a/.github/tools/go.txt b/.github/tools/go.txt index faff64e..195c94e 100644 --- a/.github/tools/go.txt +++ b/.github/tools/go.txt @@ -1,2 +1,4 @@ +golang.org/x/tools/cmd/goimports@latest mvdan.cc/gofumpt@latest github.com/segmentio/golines@latest +github.com/google/yamlfmt/cmd/yamlfmt@latest diff --git a/.github/tools/npm.txt b/.github/tools/npm.txt index f690d5f..d9871ec 100644 --- a/.github/tools/npm.txt +++ b/.github/tools/npm.txt @@ -1,4 +1,5 @@ prettier +@fsouza/prettierd @biomejs/biome sql-formatter @taplo/cli diff --git a/.github/tools/pip.txt b/.github/tools/pip.txt index 1be75bd..711c5a0 100644 --- a/.github/tools/pip.txt +++ b/.github/tools/pip.txt @@ -1,11 +1,16 @@ autopep8 black cmake-format +codespell cpplint +djhtml docformatter flake8 +isort +mdformat mypy pylint ruff sqlfluff +yamlfix yapf diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e181a68..f637ae8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -147,6 +147,7 @@ jobs: luarocks install busted --local luarocks install nlua --local luarocks install luacheck --local + luarocks install fnlfmt --local bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin" .github/tools/lua-binary.txt - name: Clone guard.nvim run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ @@ -164,6 +165,10 @@ jobs: with: neovim: true version: nightly + - uses: dart-lang/setup-dart@v1 + - uses: mlugg/setup-zig@v2 + with: + version: 0.15.2 - uses: actions/setup-java@v4 with: distribution: temurin @@ -174,7 +179,7 @@ jobs: - uses: hishamhm/gh-actions-luarocks@master - name: Install tools run: | - sudo apt-get install -y zsh shellcheck + sudo apt-get install -y zsh jq libxml2-utils shellcheck fish pgformatter luarocks install busted --local luarocks install nlua --local bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin" @@ -269,3 +274,120 @@ jobs: export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" busted --lua nlua test/ruby/*_spec.lua + test-clojure: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + - uses: leso-kn/gh-actions-lua@master + with: + luaVersion: "5.1" + - uses: hishamhm/gh-actions-luarocks@master + - name: Install Clojure CLI + run: | + curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh + chmod +x linux-install.sh + sudo ./linux-install.sh + - name: Install tools + run: | + mkdir -p $HOME/.local/bin + printf '#!/bin/sh\nclojure -Sdeps '"'"'{:deps {dev.weavejester/cljfmt {:mvn/version "0.13.0"}}}'"'"' -M -m cljfmt.main "$@"\n' > $HOME/.local/bin/cljfmt && chmod +x $HOME/.local/bin/cljfmt + luarocks install busted --local + luarocks install nlua --local + - name: Pre-warm cljfmt deps + run: | + export PATH="$HOME/.local/bin:$PATH" + echo "" | cljfmt fix - || true + - name: Clone guard.nvim + run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + - name: Run tests + run: | + export PATH="$HOME/.local/bin:$PATH" + export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" + busted --lua nlua test/clojure/*_spec.lua + + test-elixir: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + - uses: erlef/setup-beam@v1 + with: + otp-version: '27' + elixir-version: '1.17' + - uses: leso-kn/gh-actions-lua@master + with: + luaVersion: "5.1" + - uses: hishamhm/gh-actions-luarocks@master + - name: Install tools + run: | + luarocks install busted --local + luarocks install nlua --local + - name: Clone guard.nvim + run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + - name: Run tests + run: | + export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" + busted --lua nlua test/elixir/*_spec.lua + + test-nix: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + - uses: cachix/install-nix-action@v27 + - uses: leso-kn/gh-actions-lua@master + with: + luaVersion: "5.1" + - uses: hishamhm/gh-actions-luarocks@master + - name: Install tools + run: | + nix profile install nixpkgs#nixfmt-rfc-style + luarocks install busted --local + luarocks install nlua --local + - name: Clone guard.nvim + run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + - name: Run tests + run: | + export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" + busted --lua nlua test/nix/*_spec.lua + + test-swift: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + - uses: swift-actions/setup-swift@v2 + with: + swift-version: '6.0' + - uses: leso-kn/gh-actions-lua@master + with: + luaVersion: "5.1" + - uses: hishamhm/gh-actions-luarocks@master + - name: Install tools + run: | + luarocks install busted --local + luarocks install nlua --local + - name: Clone guard.nvim + run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + - name: Run tests + run: | + export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" + busted --lua nlua test/swift/*_spec.lua + diff --git a/Makefile b/Makefile index d8a9073..f279da3 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ LUA_PATH := lua/?.lua;lua/?/init.lua;$(LUA_PATH) export LUA_PATH -.PHONY: lint test test-pip test-npm test-go test-rust test-lua test-binary test-apt +.PHONY: lint test test-pip test-npm test-go test-rust test-lua test-binary test-apt test-dotnet test-ruby test-clojure test-elixir test-nix test-swift lint: stylua --check . -test: test-pip test-npm test-go test-rust test-lua test-binary test-apt +test: test-pip test-npm test-go test-rust test-lua test-binary test-apt test-dotnet test-ruby test-clojure test-elixir test-nix test-swift test-pip: busted --lua nlua test/pip/*_spec.lua @@ -29,3 +29,20 @@ test-binary: test-apt: busted --lua nlua test/apt/*_spec.lua +test-dotnet: + busted --lua nlua test/dotnet/*_spec.lua + +test-ruby: + busted --lua nlua test/ruby/*_spec.lua + +test-clojure: + busted --lua nlua test/clojure/*_spec.lua + +test-elixir: + busted --lua nlua test/elixir/*_spec.lua + +test-nix: + busted --lua nlua test/nix/*_spec.lua + +test-swift: + busted --lua nlua test/swift/*_spec.lua diff --git a/test/binary/buf_spec.lua b/test/binary/buf_spec.lua index 7040439..32e5786 100644 --- a/test/binary/buf_spec.lua +++ b/test/binary/buf_spec.lua @@ -14,7 +14,40 @@ describe('buf', function() 'syntax="proto3";', 'package test;', 'message Foo{string bar=1;}', - }, { tmpdir = tmpdir }) + }, { tmpdir = tmpdir, cwd = tmpdir }) assert.is_true(#formatted > 3) end) + + it('can lint', function() + local linter = require('test.helper').get_linter('buf') + vim.fn.writefile({ 'version: v2' }, tmpdir .. '/buf.yaml') + local protofile = tmpdir .. '/test.proto' + vim.fn.writefile({ + 'syntax = "proto3";', + 'message Foo {', + ' string bar = 1;', + '}', + }, protofile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'buf', + 'lint', + '--error-format=json', + protofile, + }, { cwd = tmpdir }) + :wait() + local output = result.stdout or '' + if output == '' then + output = result.stderr or '' + end + local diagnostics = linter.parse(output, bufnr) + assert.is_true(#diagnostics > 0) + for _, d in ipairs(diagnostics) do + assert.equal(bufnr, d.bufnr) + assert.equal('buf', d.source) + assert.is_number(d.lnum) + assert.is_string(d.message) + end + end) end) diff --git a/test/binary/cbfmt_spec.lua b/test/binary/cbfmt_spec.lua index 9e31cc8..fa49568 100644 --- a/test/binary/cbfmt_spec.lua +++ b/test/binary/cbfmt_spec.lua @@ -1,21 +1,21 @@ describe('cbfmt', function() - local tmpdir = vim.fn.getcwd() .. '/tmp-cbfmt-test' - - setup(function() + it('can format', function() + local tmpdir = '/tmp/cbfmt-test' vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ '[languages]' }, tmpdir .. '/.cbfmt.toml') - end) - - teardown(function() - vim.fn.delete(tmpdir, 'rf') - end) - - it('can format', function() - local formatted = require('test.helper').run_fmt('cbfmt', 'md', { + local input = { '# Title', '', 'Some text.', - }, { cwd = tmpdir }) + } + local result = vim + .system({ 'cbfmt', '--best-effort', '-p', 'markdown' }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + assert(result.code == 0, 'cbfmt exited ' .. result.code .. ': ' .. (result.stderr or '')) + local formatted = vim.split(result.stdout, '\n', { trimempty = true }) assert.are.same({ '# Title', '', diff --git a/test/binary/dart_spec.lua b/test/binary/dart_spec.lua new file mode 100644 index 0000000..c209797 --- /dev/null +++ b/test/binary/dart_spec.lua @@ -0,0 +1,9 @@ +describe('dart', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('dart', 'dart', { + [[void main(){print('hello');}]], + }) + assert.is_true(#formatted > 1) + assert.is_true(formatted[1]:find('void main') ~= nil) + end) +end) diff --git a/test/binary/detekt_spec.lua b/test/binary/detekt_spec.lua index f94f6d1..9db3049 100644 --- a/test/binary/detekt_spec.lua +++ b/test/binary/detekt_spec.lua @@ -1,19 +1,24 @@ describe('detekt', function() it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('detekt', 'kt', { + local linter = require('test.helper').get_linter('detekt') + local tmpfile = '/tmp/guard-test.kt' + local input = { [[fun main() {]], [[ val x = 42]], [[ if (x > 0) {]], [[ println(x)]], [[ }]], [[}]], - }) + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim.system({ 'detekt', '-i', tmpfile }):wait() + local output = result.stdout or '' + if output == '' then + output = result.stderr or '' + end + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'detekt', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('detekt', d.source) diff --git a/test/binary/dprint_spec.lua b/test/binary/dprint_spec.lua index 8a4e58e..c68342b 100644 --- a/test/binary/dprint_spec.lua +++ b/test/binary/dprint_spec.lua @@ -1,28 +1,26 @@ describe('dprint', function() - local tmpdir = vim.fn.getcwd() .. '/tmp-dprint-test' - - setup(function() + it('can format', function() + local tmpdir = '/tmp/dprint-test' vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ '{', ' "typescript": {},', - ' "plugins": [', - ' "https://plugins.dprint.dev/typescript-0.93.3.wasm"', - ' ]', + ' "plugins": ["https://plugins.dprint.dev/typescript-0.93.3.wasm"]', '}', }, tmpdir .. '/dprint.json') - end) - - teardown(function() - vim.fn.delete(tmpdir, 'rf') - end) - - it('can format', function() - local formatted = require('test.helper').run_fmt('dprint', 'ts', { - 'const x=1;', - 'function foo( ){return x}', - }, { cwd = tmpdir, tmpdir = tmpdir }) + local input = { + [[const x=1;]], + [[function foo( ){return x}]], + } + local result = vim + .system({ 'dprint', 'fmt', '--stdin', 'test.ts' }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + assert(result.code == 0, 'dprint exited ' .. result.code .. ': ' .. (result.stderr or '')) + local formatted = vim.split(result.stdout, '\n', { trimempty = true }) assert.is_true(#formatted > 0) - assert.is_truthy(formatted[1]:find('const x')) + assert.is_true(formatted[1]:find('const x') ~= nil) end) end) diff --git a/test/binary/fish_indent_spec.lua b/test/binary/fish_indent_spec.lua new file mode 100644 index 0000000..f2ea7ee --- /dev/null +++ b/test/binary/fish_indent_spec.lua @@ -0,0 +1,14 @@ +describe('fish_indent', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('fish_indent', 'fish', { + [[if test "$x" = "y"]], + [[echo hello]], + [[end]], + }) + assert.are.same({ + [[if test "$x" = y]], + [[ echo hello]], + [[end]], + }, formatted) + end) +end) diff --git a/test/binary/google-java-format_spec.lua b/test/binary/google-java-format_spec.lua new file mode 100644 index 0000000..38fb99f --- /dev/null +++ b/test/binary/google-java-format_spec.lua @@ -0,0 +1,9 @@ +describe('google-java-format', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('google-java-format', 'java', { + 'class A{void m(){int x=1;}}', + }) + assert.is_true(#formatted > 1) + assert.is_true(formatted[1]:find('class A') ~= nil) + end) +end) diff --git a/test/binary/hadolint_spec.lua b/test/binary/hadolint_spec.lua index 2bfa1a0..0ba3f02 100644 --- a/test/binary/hadolint_spec.lua +++ b/test/binary/hadolint_spec.lua @@ -1,16 +1,24 @@ describe('hadolint', function() it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('hadolint', 'dockerfile', { + local linter = require('test.helper').get_linter('hadolint') + local tmpfile = '/tmp/guard-test.dockerfile' + local input = { [[FROM ubuntu]], [[RUN apt-get install python]], - }) + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'hadolint', + '--no-fail', + '--format=json', + tmpfile, + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'hadolint', - severity = vim.diagnostic.severity.WARN, - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('hadolint', d.source) diff --git a/test/binary/jq_spec.lua b/test/binary/jq_spec.lua new file mode 100644 index 0000000..9612a1b --- /dev/null +++ b/test/binary/jq_spec.lua @@ -0,0 +1,13 @@ +describe('jq', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('jq', 'json', { + [[{"b":2,"a":1}]], + }) + assert.are.same({ + [[{]], + [[ "b": 2,]], + [[ "a": 1]], + [[}]], + }, formatted) + end) +end) diff --git a/test/binary/ktfmt_spec.lua b/test/binary/ktfmt_spec.lua new file mode 100644 index 0000000..f249720 --- /dev/null +++ b/test/binary/ktfmt_spec.lua @@ -0,0 +1,9 @@ +describe('ktfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('ktfmt', 'kt', { + [[fun main(){val x=1;println(x)}]], + }) + assert.is_true(#formatted > 1) + assert.is_true(formatted[1]:find('fun main') ~= nil) + end) +end) diff --git a/test/binary/ktlint_spec.lua b/test/binary/ktlint_spec.lua index 98093c2..9e99a55 100644 --- a/test/binary/ktlint_spec.lua +++ b/test/binary/ktlint_spec.lua @@ -1,17 +1,37 @@ describe('ktlint', function() - it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('ktlint', 'kt', { - 'fun main() {', - ' val x=1', - ' println(x)', - '}', + it('can format', function() + local formatted = require('test.helper').run_fmt('ktlint', 'kt', { + [[fun main() {]], + [[ val x=1]], + [[ println(x)]], + [[}]], }) + assert.are.same({ + [[fun main() {]], + [[ val x = 1]], + [[ println(x)]], + [[}]], + }, formatted) + end) + + it('can lint', function() + local linter = require('test.helper').get_linter('ktlint') + local tmpfile = '/tmp/guard-test.kt' + local input = { + [[fun main() {]], + [[ val x=1]], + [[ println(x)]], + [[}]], + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim.system({ 'ktlint', '--log-level=error', tmpfile }):wait() + local output = result.stdout or '' + if output == '' then + output = result.stderr or '' + end + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'ktlint', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('ktlint', d.source) diff --git a/test/binary/ormolu_spec.lua b/test/binary/ormolu_spec.lua new file mode 100644 index 0000000..52edf0a --- /dev/null +++ b/test/binary/ormolu_spec.lua @@ -0,0 +1,13 @@ +describe('ormolu', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('ormolu', 'hs', { + [[module Main where]], + [[main = putStrLn "hello"]], + }) + assert.are.same({ + [[module Main where]], + [[]], + [[main = putStrLn "hello"]], + }, formatted) + end) +end) diff --git a/test/binary/pg_format_spec.lua b/test/binary/pg_format_spec.lua new file mode 100644 index 0000000..3e44720 --- /dev/null +++ b/test/binary/pg_format_spec.lua @@ -0,0 +1,9 @@ +describe('pg_format', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('pg_format', 'sql', { + [[select id, name from users where id = 1;]], + }) + assert.is_true(#formatted > 1) + assert.is_truthy(formatted[1]:match('SELECT')) + end) +end) diff --git a/test/binary/shellcheck_spec.lua b/test/binary/shellcheck_spec.lua index 9913321..5381bd9 100644 --- a/test/binary/shellcheck_spec.lua +++ b/test/binary/shellcheck_spec.lua @@ -1,17 +1,25 @@ describe('shellcheck', function() it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('shellcheck', 'sh', { + local linter = require('test.helper').get_linter('shellcheck') + local tmpfile = '/tmp/guard-test.sh' + local input = { [[#!/bin/sh]], [[echo $FOO]], - }) + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'shellcheck', + '--format', + 'json1', + '--external-sources', + tmpfile, + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'shellcheck', - severity = vim.diagnostic.severity.INFO, - message_pat = 'Double quote', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('shellcheck', d.source) diff --git a/test/binary/shfmt_spec.lua b/test/binary/shfmt_spec.lua new file mode 100644 index 0000000..e6c3a20 --- /dev/null +++ b/test/binary/shfmt_spec.lua @@ -0,0 +1,16 @@ +describe('shfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('shfmt', 'sh', { + [[#!/bin/sh]], + [[if [ "$x" = "y" ]; then]], + [[echo "hello"]], + [[fi]], + }) + assert.are.same({ + [[#!/bin/sh]], + [[if [ "$x" = "y" ]; then]], + '\techo "hello"', + [[fi]], + }, formatted) + end) +end) diff --git a/test/binary/tombi_spec.lua b/test/binary/tombi_spec.lua new file mode 100644 index 0000000..8808fef --- /dev/null +++ b/test/binary/tombi_spec.lua @@ -0,0 +1,16 @@ +describe('tombi', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('tombi', 'toml', { + '[package]', + 'name="test"', + 'version = "0.1.0"', + }) + assert.is_true(#formatted > 0) + for _, line in ipairs(formatted) do + if line:find('name') then + assert.is_true(line:find('name = ') ~= nil) + break + end + end + end) +end) diff --git a/test/binary/typos_spec.lua b/test/binary/typos_spec.lua new file mode 100644 index 0000000..a942017 --- /dev/null +++ b/test/binary/typos_spec.lua @@ -0,0 +1,14 @@ +describe('typos', function() + it('can lint', function() + local helper = require('test.helper') + local buf, diagnostics = helper.run_lint('typos', 'txt', { + [[teh quick brown fox]], + }) + assert.is_true(#diagnostics > 0) + for _, d in ipairs(diagnostics) do + assert.equal(buf, d.bufnr) + assert.is_number(d.lnum) + assert.is_string(d.message) + end + end) +end) diff --git a/test/binary/typstyle_spec.lua b/test/binary/typstyle_spec.lua new file mode 100644 index 0000000..7169c4f --- /dev/null +++ b/test/binary/typstyle_spec.lua @@ -0,0 +1,10 @@ +describe('typstyle', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('typstyle', 'typ', { + [[#let x = 1]], + }) + assert.are.same({ + [[#let x = 1]], + }, formatted) + end) +end) diff --git a/test/binary/xmllint_spec.lua b/test/binary/xmllint_spec.lua new file mode 100644 index 0000000..5c1f3fd --- /dev/null +++ b/test/binary/xmllint_spec.lua @@ -0,0 +1,13 @@ +describe('xmllint', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('xmllint', 'xml', { + [[text]], + }) + assert.are.same({ + [[]], + [[]], + [[ text]], + [[]], + }, formatted) + end) +end) diff --git a/test/binary/zigfmt_spec.lua b/test/binary/zigfmt_spec.lua new file mode 100644 index 0000000..d978f96 --- /dev/null +++ b/test/binary/zigfmt_spec.lua @@ -0,0 +1,10 @@ +describe('zigfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('zigfmt', 'zig', { + [[const std = @import( "std" );]], + }) + assert.are.same({ + [[const std = @import("std");]], + }, formatted) + end) +end) diff --git a/test/clojure/cljfmt_spec.lua b/test/clojure/cljfmt_spec.lua new file mode 100644 index 0000000..f333606 --- /dev/null +++ b/test/clojure/cljfmt_spec.lua @@ -0,0 +1,11 @@ +describe('cljfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('cljfmt', 'clj', { + [[(defn hello]], + [[ [name] (println "hello"]], + [[name))]], + }) + assert.is_true(#formatted > 0) + assert.is_true(formatted[1]:find('defn hello') ~= nil) + end) +end) diff --git a/test/elixir/mixformat_spec.lua b/test/elixir/mixformat_spec.lua new file mode 100644 index 0000000..c11c294 --- /dev/null +++ b/test/elixir/mixformat_spec.lua @@ -0,0 +1,9 @@ +describe('mixformat', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('mixformat', 'ex', { + [[defmodule Foo do def bar( x,y) do x+y end end]], + }) + assert.is_true(#formatted > 0) + assert.is_true(formatted[1]:find('defmodule Foo') ~= nil) + end) +end) diff --git a/test/go/goimports_spec.lua b/test/go/goimports_spec.lua new file mode 100644 index 0000000..5cbdc1f --- /dev/null +++ b/test/go/goimports_spec.lua @@ -0,0 +1,26 @@ +describe('goimports', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('goimports', 'go', { + [[package main]], + [[]], + [[import "fmt"]], + [[import "os"]], + [[]], + [[func main() {]], + [[fmt.Println(os.Args)]], + [[}]], + }) + assert.are.same({ + [[package main]], + [[]], + [[import (]], + '\t"fmt"', + '\t"os"', + [[)]], + [[]], + [[func main() {]], + '\tfmt.Println(os.Args)', + [[}]], + }, formatted) + end) +end) diff --git a/test/go/golangci_lint_spec.lua b/test/go/golangci_lint_spec.lua index c07b22c..aefde3e 100644 --- a/test/go/golangci_lint_spec.lua +++ b/test/go/golangci_lint_spec.lua @@ -1,22 +1,10 @@ describe('golangci_lint', function() - local tmpdir = vim.fn.getcwd() .. '/tmp-golangci-lint-test' - - setup(function() - vim.fn.mkdir(tmpdir, 'p') - vim.fn.writefile({ - 'module testmod', - '', - 'go 1.21', - }, tmpdir .. '/go.mod') - end) - - teardown(function() - vim.fn.delete(tmpdir, 'rf') - end) - it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('golangci_lint', 'go', { + local linter = require('test.helper').get_linter('golangci_lint') + local tmpdir = '/tmp/golangci-test' + vim.fn.mkdir(tmpdir, 'p') + vim.fn.writefile({ 'module test', '', 'go 1.21' }, tmpdir .. '/go.mod') + local input = { 'package main', '', 'import "fmt"', @@ -24,7 +12,21 @@ describe('golangci_lint', function() 'func main() {', '\tfmt.Errorf("unused error")', '}', - }, { cwd = tmpdir, tmpdir = tmpdir }) + } + vim.fn.writefile(input, tmpdir .. '/main.go') + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'golangci-lint', + 'run', + '--fix=false', + '--out-format=json', + }, { + cwd = tmpdir, + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) diff --git a/test/go/yamlfmt_spec.lua b/test/go/yamlfmt_spec.lua new file mode 100644 index 0000000..8b7bbd9 --- /dev/null +++ b/test/go/yamlfmt_spec.lua @@ -0,0 +1,12 @@ +describe('yamlfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('yamlfmt', 'yaml', { + [[name: John]], + [[age: 30]], + }) + assert.are.same({ + [[name: John]], + [[age: 30]], + }, formatted) + end) +end) diff --git a/test/lua/fnlfmt_spec.lua b/test/lua/fnlfmt_spec.lua new file mode 100644 index 0000000..2173e44 --- /dev/null +++ b/test/lua/fnlfmt_spec.lua @@ -0,0 +1,10 @@ +describe('fnlfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('fnlfmt', 'fnl', { + [[(fn hello [] (print "hello"]], + [[))]], + }) + assert.is_true(#formatted > 0) + assert.is_true(formatted[1]:find('fn hello') ~= nil) + end) +end) diff --git a/test/nix/nixfmt_spec.lua b/test/nix/nixfmt_spec.lua new file mode 100644 index 0000000..254d631 --- /dev/null +++ b/test/nix/nixfmt_spec.lua @@ -0,0 +1,9 @@ +describe('nixfmt', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('nixfmt', 'nix', { + [[{pkgs,...}:{environment.systemPackages=[pkgs.vim];}]], + }) + assert.is_true(#formatted > 0) + assert.is_true(formatted[1]:find('pkgs') ~= nil) + end) +end) diff --git a/test/npm/eslint_d_spec.lua b/test/npm/eslint_d_spec.lua index 465a6af..f8a4893 100644 --- a/test/npm/eslint_d_spec.lua +++ b/test/npm/eslint_d_spec.lua @@ -1,27 +1,34 @@ describe('eslint_d', function() - local tmpdir = vim.fn.getcwd() .. '/tmp-eslint-d-test' - - setup(function() + it('can lint', function() + local linter = require('test.helper').get_linter('eslint_d') + local tmpdir = '/tmp/eslintd-test' vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ 'module.exports = [{ rules: { "no-unused-vars": "error" } }];', }, tmpdir .. '/eslint.config.js') - end) - - teardown(function() - vim.fn.delete(tmpdir, 'rf') - end) - - it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('eslint_d', 'js', { - 'const x = 1;', - }, { cwd = tmpdir, tmpdir = tmpdir }) + local tmpfile = tmpdir .. '/test.js' + local input = { + [[const x = 1;]], + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'npx', + 'eslint_d', + '--format', + 'json', + '--stdin', + '--stdin-filename', + tmpfile, + }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'eslint_d', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('eslint_d', d.source) @@ -31,12 +38,29 @@ describe('eslint_d', function() end) it('can format', function() + local tmpdir = '/tmp/eslintd-test' + vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ 'module.exports = [{ rules: { "semi": ["error", "always"] } }];', }, tmpdir .. '/eslint.config.js') - local formatted = require('test.helper').run_fmt('eslint_d', 'js', { - 'const x = 1', - }, { cwd = tmpdir, tmpdir = tmpdir }) - assert.are.same({ 'const x = 1;' }, formatted) + local tmpfile = tmpdir .. '/test.js' + local input = { + [[const x = 1]], + } + vim.fn.writefile(input, tmpfile) + local config = require('guard-collection.formatter').eslint_d + local cmd = vim.list_extend({ config.cmd }, config.args) + table.insert(cmd, tmpfile) + local result = vim + .system(cmd, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + assert(result.code == 0, 'eslint_d exited ' .. result.code .. ': ' .. (result.stderr or '')) + local formatted = vim.split(result.stdout, '\n', { trimempty = true }) + assert.are.same({ + [[const x = 1;]], + }, formatted) end) end) diff --git a/test/npm/eslint_spec.lua b/test/npm/eslint_spec.lua index 21c5566..8ea0339 100644 --- a/test/npm/eslint_spec.lua +++ b/test/npm/eslint_spec.lua @@ -1,27 +1,34 @@ describe('eslint', function() - local tmpdir = vim.fn.getcwd() .. '/tmp-eslint-test' - - setup(function() + it('can lint', function() + local linter = require('test.helper').get_linter('eslint') + local tmpdir = '/tmp/eslint-test' vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ 'module.exports = [{ rules: { "no-unused-vars": "error" } }];', }, tmpdir .. '/eslint.config.js') - end) - - teardown(function() - vim.fn.delete(tmpdir, 'rf') - end) - - it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('eslint', 'js', { - 'const x = 1;', - }, { cwd = tmpdir, tmpdir = tmpdir }) + local tmpfile = tmpdir .. '/test.js' + local input = { + [[const x = 1;]], + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'npx', + 'eslint', + '--format', + 'json', + '--stdin', + '--stdin-filename', + tmpfile, + }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'eslint', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('eslint', d.source) diff --git a/test/npm/prettierd_spec.lua b/test/npm/prettierd_spec.lua new file mode 100644 index 0000000..61cecd6 --- /dev/null +++ b/test/npm/prettierd_spec.lua @@ -0,0 +1,20 @@ +describe('prettierd', function() + it('can format', function() + local tmpfile = '/tmp/guard-test.js' + local input = { + 'const x={a:1,b:2,c:3}', + 'const y = [1,2,3,4,5]', + } + vim.fn.writefile(input, tmpfile) + local result = vim + .system({ 'prettierd', tmpfile }, { stdin = table.concat(input, '\n') }) + :wait() + assert.equal(0, result.code) + local expected = table.concat({ + 'const x = { a: 1, b: 2, c: 3 };', + 'const y = [1, 2, 3, 4, 5];', + '', + }, '\n') + assert.equal(expected, result.stdout) + end) +end) diff --git a/test/npm/stylelint_spec.lua b/test/npm/stylelint_spec.lua index 06d654a..70639c1 100644 --- a/test/npm/stylelint_spec.lua +++ b/test/npm/stylelint_spec.lua @@ -1,27 +1,41 @@ describe('stylelint', function() - local tmpdir = vim.fn.getcwd() .. '/tmp-stylelint-test' - - setup(function() + it('can lint', function() + local linter = require('test.helper').get_linter('stylelint') + local tmpdir = '/tmp/stylelint-test' vim.fn.mkdir(tmpdir, 'p') + local configfile = tmpdir .. '/.stylelintrc.json' vim.fn.writefile({ '{ "rules": { "color-no-invalid-hex": true } }', - }, tmpdir .. '/.stylelintrc.json') - end) - - teardown(function() - vim.fn.delete(tmpdir, 'rf') - end) - - it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('stylelint', 'css', { - 'a { color: #fff1az; }', - }, { cwd = tmpdir, tmpdir = tmpdir }) + }, configfile) + local tmpfile = tmpdir .. '/test.css' + local input = { + [[a { color: #fff1az; }]], + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'npx', + 'stylelint', + '--formatter', + 'json', + '--stdin', + '--stdin-filename', + tmpfile, + '--config', + configfile, + }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + local output = result.stdout or '' + if output == '' then + output = result.stderr or '' + end + assert(output ~= '', 'stylelint: no output (code=' .. result.code .. ')') + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'stylelint', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('stylelint', d.source) diff --git a/test/pip/codespell_spec.lua b/test/pip/codespell_spec.lua new file mode 100644 index 0000000..b16fdc1 --- /dev/null +++ b/test/pip/codespell_spec.lua @@ -0,0 +1,15 @@ +describe('codespell', function() + it('can lint', function() + local helper = require('test.helper') + local buf, diagnostics = helper.run_lint('codespell', 'txt', { + [[teh quick brown fox]], + }) + assert.is_true(#diagnostics > 0) + for _, d in ipairs(diagnostics) do + assert.equal(buf, d.bufnr) + assert.equal('codespell', d.source) + assert.is_number(d.lnum) + assert.is_string(d.message) + end + end) +end) diff --git a/test/pip/djhtml_spec.lua b/test/pip/djhtml_spec.lua new file mode 100644 index 0000000..32529b1 --- /dev/null +++ b/test/pip/djhtml_spec.lua @@ -0,0 +1,14 @@ +describe('djhtml', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('djhtml', 'html', { + [[
]], + [[

hello

]], + [[
]], + }) + assert.are.same({ + [[
]], + [[

hello

]], + [[
]], + }, formatted) + end) +end) diff --git a/test/pip/isort_spec.lua b/test/pip/isort_spec.lua new file mode 100644 index 0000000..b91a95e --- /dev/null +++ b/test/pip/isort_spec.lua @@ -0,0 +1,14 @@ +describe('isort', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('isort', 'python', { + [[import sys]], + [[import os]], + [[import json]], + }) + assert.are.same({ + [[import json]], + [[import os]], + [[import sys]], + }, formatted) + end) +end) diff --git a/test/pip/mdformat_spec.lua b/test/pip/mdformat_spec.lua new file mode 100644 index 0000000..f30a03c --- /dev/null +++ b/test/pip/mdformat_spec.lua @@ -0,0 +1,13 @@ +describe('mdformat', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('mdformat', 'markdown', { + [[# title]], + [[text]], + }) + assert.are.same({ + [[# title]], + [[]], + [[text]], + }, formatted) + end) +end) diff --git a/test/pip/mypyc_spec.lua b/test/pip/mypyc_spec.lua new file mode 100644 index 0000000..850fd33 --- /dev/null +++ b/test/pip/mypyc_spec.lua @@ -0,0 +1,29 @@ +describe('mypyc', function() + it('can lint', function() + local linter = require('test.helper').get_linter('mypyc') + local tmpfile = '/tmp/guard-test.py' + local input = { + 'def add(x: int, y: int) -> int:', + ' return x + y', + '', + 'add("hello", "world")', + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local cmd = vim.list_extend({ linter.cmd }, linter.args or {}) + table.insert(cmd, tmpfile) + local result = vim.system(cmd):wait() + local output = result.stdout or '' + if output == '' then + output = result.stderr or '' + end + local diagnostics = linter.parse(output, bufnr) + assert.is_true(#diagnostics > 0) + for _, d in ipairs(diagnostics) do + assert.equal(bufnr, d.bufnr) + assert.equal('mypy', d.source) + assert.is_number(d.lnum) + assert.is_string(d.message) + end + end) +end) diff --git a/test/pip/pylint_spec.lua b/test/pip/pylint_spec.lua index f209df1..54bf7ae 100644 --- a/test/pip/pylint_spec.lua +++ b/test/pip/pylint_spec.lua @@ -1,15 +1,27 @@ describe('pylint', function() it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('pylint', 'py', { + local linter = require('test.helper').get_linter('pylint') + local tmpfile = '/tmp/guard-test.py' + local input = { [[import os]], [[x = 1]], - }) + } + vim.fn.writefile(input, tmpfile) + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'pylint', + '--from-stdin', + '--output-format', + 'json', + tmpfile, + }, { + stdin = table.concat(input, '\n') .. '\n', + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'pylint', - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('pylint', d.source) diff --git a/test/pip/ruff_spec.lua b/test/pip/ruff_spec.lua index 8aecb47..8439bd0 100644 --- a/test/pip/ruff_spec.lua +++ b/test/pip/ruff_spec.lua @@ -22,17 +22,13 @@ describe('ruff', function() it('can lint', function() local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('ruff', 'py', { + local buf, diagnostics = helper.run_lint('ruff', 'py', { [[import os]], [[x = 1]], }) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - source = 'ruff', - }) for _, d in ipairs(diagnostics) do - assert.equal(bufnr, d.bufnr) + assert.equal(buf, d.bufnr) assert.equal('ruff', d.source) assert.is_number(d.lnum) assert.is_string(d.message) diff --git a/test/pip/yamlfix_spec.lua b/test/pip/yamlfix_spec.lua new file mode 100644 index 0000000..1fad53e --- /dev/null +++ b/test/pip/yamlfix_spec.lua @@ -0,0 +1,13 @@ +describe('yamlfix', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('yamlfix', 'yaml', { + [[name: John]], + [[age: 30]], + }) + assert.are.same({ + [[---]], + [[name: John]], + [[age: 30]], + }, formatted) + end) +end) diff --git a/test/ruby/rubocop_spec.lua b/test/ruby/rubocop_spec.lua index 0a1f24b..16f0df2 100644 --- a/test/ruby/rubocop_spec.lua +++ b/test/ruby/rubocop_spec.lua @@ -10,15 +10,55 @@ describe('rubocop', function() vim.system({ 'bundle', 'install' }, { cwd = tmpdir }):wait() end) + it('can format', function() + local input = { + [[x = { :a=>1,:b => 2 }]], + } + local result = vim + .system({ + 'bundle', + 'exec', + 'rubocop', + '-A', + '-f', + 'quiet', + '--stderr', + '--stdin', + 'test.rb', + }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + local output = result.stderr or '' + local formatted = vim.split(output, '\n', { trimempty = true }) + assert.is_true(#formatted > 0) + end) + it('can lint', function() - local helper = require('test.helper') - local bufnr, diagnostics = helper.run_lint('rubocop', 'rb', { + local linter = require('test.helper').get_linter('rubocop') + local input = { [[x = { :a=>1,:b => 2 }]], - }, { cwd = tmpdir }) + } + local bufnr = vim.api.nvim_create_buf(false, true) + local result = vim + .system({ + 'bundle', + 'exec', + 'rubocop', + '--format', + 'json', + '--force-exclusion', + '--stdin', + 'test.rb', + }, { + stdin = table.concat(input, '\n') .. '\n', + cwd = tmpdir, + }) + :wait() + local output = result.stdout or '' + local diagnostics = linter.parse(output, bufnr) assert.is_true(#diagnostics > 0) - helper.assert_diag(diagnostics[1], { - bufnr = bufnr, - }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.is_number(d.lnum) diff --git a/test/swift/swift_format_spec.lua b/test/swift/swift_format_spec.lua new file mode 100644 index 0000000..e545f65 --- /dev/null +++ b/test/swift/swift_format_spec.lua @@ -0,0 +1,9 @@ +describe('swift-format', function() + it('can format', function() + local formatted = require('test.helper').run_fmt('swift-format', 'swift', { + [[func foo( ){let x=1;print(x)}]], + }) + assert.is_true(#formatted > 0) + assert.is_true(formatted[1]:find('func foo') ~= nil) + end) +end) From 8b4533687001ab8e5c9a8cb0eaf2cc359700c63f Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 01:22:35 -0500 Subject: [PATCH 02/10] fix(ci): remove duplicate entry and untestable mypyc test --- .github/tools/binary.txt | 10 +++------- test/pip/mypyc_spec.lua | 29 ----------------------------- 2 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 test/pip/mypyc_spec.lua diff --git a/.github/tools/binary.txt b/.github/tools/binary.txt index 18a2224..aa6cf5c 100644 --- a/.github/tools/binary.txt +++ b/.github/tools/binary.txt @@ -1,12 +1,9 @@ alejandra bin https://github.com/kamadorueda/alejandra/releases/download/4.0.0/alejandra-x86_64-unknown-linux-musl buf bin https://github.com/bufbuild/buf/releases/download/v1.47.2/buf-Linux-x86_64 -cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt +hadolint bin https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 checkmake bin https://github.com/mrtazz/checkmake/releases/download/0.2.2/checkmake-0.2.2.linux.amd64 deno zip https://github.com/denoland/deno/releases/download/v2.1.4/deno-x86_64-unknown-linux-gnu.zip detekt jar https://github.com/detekt/detekt/releases/download/v1.23.7/detekt-cli-1.23.7-all.jar -dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip -google-java-format jar https://github.com/google/google-java-format/releases/download/v1.34.1/google-java-format-1.34.1-all-deps.jar -hadolint bin https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 hlint tar https://github.com/ndmitchell/hlint/releases/download/v3.10/hlint-3.10-x86_64-linux.tar.gz hlint-3.10/hlint ktfmt jar https://repo1.maven.org/maven2/com/facebook/ktfmt/0.52/ktfmt-0.52-jar-with-dependencies.jar ktlint bin https://github.com/pinterest/ktlint/releases/download/1.8.0/ktlint @@ -14,6 +11,5 @@ latexindent bin https://github.com/cmhughes/latexindent.pl/releases/download/V3. ormolu zip https://github.com/tweag/ormolu/releases/download/0.8.0.2/ormolu-x86_64-linux.zip shfmt bin https://github.com/mvdan/sh/releases/download/v3.10.0/shfmt_v3.10.0_linux_amd64 swiftformat zip https://github.com/nicklockwood/SwiftFormat/releases/download/0.55.3/swiftformat_linux.zip swiftformat_linux -tombi gz https://github.com/tombi-toml/tombi/releases/download/v0.7.27/tombi-cli-0.7.27-x86_64-unknown-linux-musl.gz -typos tar https://github.com/crate-ci/typos/releases/download/v1.43.3/typos-v1.43.3-x86_64-unknown-linux-musl.tar.gz ./typos -typstyle bin https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-x86_64-unknown-linux-gnu +cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt +dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip diff --git a/test/pip/mypyc_spec.lua b/test/pip/mypyc_spec.lua deleted file mode 100644 index 850fd33..0000000 --- a/test/pip/mypyc_spec.lua +++ /dev/null @@ -1,29 +0,0 @@ -describe('mypyc', function() - it('can lint', function() - local linter = require('test.helper').get_linter('mypyc') - local tmpfile = '/tmp/guard-test.py' - local input = { - 'def add(x: int, y: int) -> int:', - ' return x + y', - '', - 'add("hello", "world")', - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local cmd = vim.list_extend({ linter.cmd }, linter.args or {}) - table.insert(cmd, tmpfile) - local result = vim.system(cmd):wait() - local output = result.stdout or '' - if output == '' then - output = result.stderr or '' - end - local diagnostics = linter.parse(output, bufnr) - assert.is_true(#diagnostics > 0) - for _, d in ipairs(diagnostics) do - assert.equal(bufnr, d.bufnr) - assert.equal('mypy', d.source) - assert.is_number(d.lnum) - assert.is_string(d.message) - end - end) -end) From 777894c9e2eb9cba15b046714a5cda87dfc61246 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 01:28:16 -0500 Subject: [PATCH 03/10] fix(ci): restore CI config lost during merge Problem: the -X theirs merge strategy replaced the full test/all-tools CI config with the smaller fix/broken-configs version, losing install entries for dart, fish_indent, google-java-format, pg_format, tombi, typos, typstyle, xmllint, and zigfmt. Solution: restore binary.txt, ci.yaml, and install script from the pre-merge test/all-tools state which already had all entries. --- .github/tools/binary.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/tools/binary.txt b/.github/tools/binary.txt index aa6cf5c..18a2224 100644 --- a/.github/tools/binary.txt +++ b/.github/tools/binary.txt @@ -1,9 +1,12 @@ alejandra bin https://github.com/kamadorueda/alejandra/releases/download/4.0.0/alejandra-x86_64-unknown-linux-musl buf bin https://github.com/bufbuild/buf/releases/download/v1.47.2/buf-Linux-x86_64 -hadolint bin https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 +cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt checkmake bin https://github.com/mrtazz/checkmake/releases/download/0.2.2/checkmake-0.2.2.linux.amd64 deno zip https://github.com/denoland/deno/releases/download/v2.1.4/deno-x86_64-unknown-linux-gnu.zip detekt jar https://github.com/detekt/detekt/releases/download/v1.23.7/detekt-cli-1.23.7-all.jar +dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip +google-java-format jar https://github.com/google/google-java-format/releases/download/v1.34.1/google-java-format-1.34.1-all-deps.jar +hadolint bin https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 hlint tar https://github.com/ndmitchell/hlint/releases/download/v3.10/hlint-3.10-x86_64-linux.tar.gz hlint-3.10/hlint ktfmt jar https://repo1.maven.org/maven2/com/facebook/ktfmt/0.52/ktfmt-0.52-jar-with-dependencies.jar ktlint bin https://github.com/pinterest/ktlint/releases/download/1.8.0/ktlint @@ -11,5 +14,6 @@ latexindent bin https://github.com/cmhughes/latexindent.pl/releases/download/V3. ormolu zip https://github.com/tweag/ormolu/releases/download/0.8.0.2/ormolu-x86_64-linux.zip shfmt bin https://github.com/mvdan/sh/releases/download/v3.10.0/shfmt_v3.10.0_linux_amd64 swiftformat zip https://github.com/nicklockwood/SwiftFormat/releases/download/0.55.3/swiftformat_linux.zip swiftformat_linux -cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt -dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip +tombi gz https://github.com/tombi-toml/tombi/releases/download/v0.7.27/tombi-cli-0.7.27-x86_64-unknown-linux-musl.gz +typos tar https://github.com/crate-ci/typos/releases/download/v1.43.3/typos-v1.43.3-x86_64-unknown-linux-musl.tar.gz ./typos +typstyle bin https://github.com/typstyle-rs/typstyle/releases/download/v0.14.4/typstyle-x86_64-unknown-linux-gnu From 564e321836af81d0331be4536ea078aaafab7a87 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 12:22:21 -0500 Subject: [PATCH 04/10] ci: extract repeated test setup into composite action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: every test job repeated the same 5 steps for neovim, lua, luarocks, busted/nlua, and guard.nvim clone — 175 lines of duplication across 15 jobs. Solution: extract into .github/actions/test-setup/action.yml and replace with a single `uses: ./.github/actions/test-setup` per job. --- .github/actions/test-setup/action.yml | 18 +++ .github/workflows/ci.yaml | 194 +++----------------------- 2 files changed, 37 insertions(+), 175 deletions(-) create mode 100644 .github/actions/test-setup/action.yml diff --git a/.github/actions/test-setup/action.yml b/.github/actions/test-setup/action.yml new file mode 100644 index 0000000..2435fe0 --- /dev/null +++ b/.github/actions/test-setup/action.yml @@ -0,0 +1,18 @@ +name: Test Setup +description: Install Neovim, Lua 5.1, Luarocks, busted, nlua, and guard.nvim + +runs: + using: composite + steps: + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: nightly + - uses: leso-kn/gh-actions-lua@master + with: + luaVersion: '5.1' + - uses: hishamhm/gh-actions-luarocks@master + - run: luarocks install busted --local && luarocks install nlua --local + shell: bash + - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + shell: bash diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f637ae8..fb75461 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,24 +21,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: actions/setup-python@v5 with: python-version: '3.12' - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools - run: | - pip install -q -r .github/tools/pip.txt - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + run: pip install -q -r .github/tools/pip.txt - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -48,24 +36,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: actions/setup-node@v4 with: node-version: 20 - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools - run: | - xargs npm install -g < .github/tools/npm.txt - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + run: xargs npm install -g < .github/tools/npm.txt - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -75,26 +51,15 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: actions/setup-go@v5 with: go-version: stable cache: false - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools run: | xargs -L1 go install < .github/tools/go.txt curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8 - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export PATH="$HOME/go/bin:$PATH" @@ -105,26 +70,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: dtolnay/rust-toolchain@stable with: components: rustfmt - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - - name: Install test tools - run: | - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -134,23 +86,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master + - uses: ./.github/actions/test-setup - name: Install tools run: | - luarocks install busted --local - luarocks install nlua --local luarocks install luacheck --local luarocks install fnlfmt --local bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin" .github/tools/lua-binary.txt - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export PATH="$HOME/.local/bin:$PATH" @@ -161,10 +102,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: dart-lang/setup-dart@v1 - uses: mlugg/setup-zig@v2 with: @@ -173,18 +111,10 @@ jobs: with: distribution: temurin java-version: 21 - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools run: | sudo apt-get install -y zsh jq libxml2-utils shellcheck fish pgformatter - luarocks install busted --local - luarocks install nlua --local bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin" - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export PATH="$HOME/.local/bin:$PATH" @@ -195,21 +125,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master + - uses: ./.github/actions/test-setup - name: Install tools - run: | - xargs sudo apt-get install -y < .github/tools/apt.txt - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + run: xargs sudo apt-get install -y < .github/tools/apt.txt - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -219,24 +137,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0' - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools - run: | - dotnet tool install -g csharpier - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + run: dotnet tool install -g csharpier - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -246,29 +152,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: ruby/setup-ruby@v1 with: ruby-version: '3.3' - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools - run: | - gem install rubocop bundler - luarocks install busted --local - luarocks install nlua --local + run: gem install rubocop bundler - name: Setup rubocop Gemfile run: | mkdir -p /tmp/rubocop-test printf "source 'https://rubygems.org'\ngem 'rubocop'\n" > /tmp/rubocop-test/Gemfile cd /tmp/rubocop-test && bundle install - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -278,18 +172,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: actions/setup-java@v4 with: distribution: temurin java-version: 21 - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install Clojure CLI run: | curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh @@ -299,14 +186,10 @@ jobs: run: | mkdir -p $HOME/.local/bin printf '#!/bin/sh\nclojure -Sdeps '"'"'{:deps {dev.weavejester/cljfmt {:mvn/version "0.13.0"}}}'"'"' -M -m cljfmt.main "$@"\n' > $HOME/.local/bin/cljfmt && chmod +x $HOME/.local/bin/cljfmt - luarocks install busted --local - luarocks install nlua --local - name: Pre-warm cljfmt deps run: | export PATH="$HOME/.local/bin:$PATH" echo "" | cljfmt fix - || true - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export PATH="$HOME/.local/bin:$PATH" @@ -317,24 +200,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: erlef/setup-beam@v1 with: otp-version: '27' elixir-version: '1.17' - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - - name: Install tools - run: | - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -344,22 +214,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: cachix/install-nix-action@v27 - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - name: Install tools - run: | - nix profile install nixpkgs#nixfmt-rfc-style - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ + run: nix profile install nixpkgs#nixfmt-rfc-style - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" @@ -369,25 +227,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: rhysd/action-setup-vim@v1 - with: - neovim: true - version: nightly + - uses: ./.github/actions/test-setup - uses: swift-actions/setup-swift@v2 with: swift-version: '6.0' - - uses: leso-kn/gh-actions-lua@master - with: - luaVersion: "5.1" - - uses: hishamhm/gh-actions-luarocks@master - - name: Install tools - run: | - luarocks install busted --local - luarocks install nlua --local - - name: Clone guard.nvim - run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/ - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" busted --lua nlua test/swift/*_spec.lua - From 29877e51bb62ea70cb26767b663dda1770befbd0 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 12:36:55 -0500 Subject: [PATCH 05/10] fix(test): use run_lint/run_fmt instead of manual vim.system Problem: rebase picked up old test versions that manually construct commands instead of using the config-driven helpers, defeating the purpose of testing the actual tool definitions. Solution: replace all 14 affected test files with the upstream/main versions that use run_lint/run_fmt. Add buf lint test using run_lint. --- test/binary/buf_spec.lua | 23 ++--------- test/binary/cbfmt_spec.lua | 24 ++++++------ test/binary/detekt_spec.lua | 19 ++++----- test/binary/dprint_spec.lua | 34 +++++++++-------- test/binary/hadolint_spec.lua | 24 ++++-------- test/binary/ktlint_spec.lua | 42 ++++++-------------- test/binary/shellcheck_spec.lua | 26 +++++-------- test/go/golangci_lint_spec.lua | 38 +++++++++--------- test/npm/eslint_d_spec.lua | 68 +++++++++++---------------------- test/npm/eslint_spec.lua | 43 +++++++++------------ test/npm/stylelint_spec.lua | 52 +++++++++---------------- test/pip/pylint_spec.lua | 26 ++++--------- test/pip/ruff_spec.lua | 8 +++- test/ruby/rubocop_spec.lua | 52 +++---------------------- 14 files changed, 165 insertions(+), 314 deletions(-) diff --git a/test/binary/buf_spec.lua b/test/binary/buf_spec.lua index 32e5786..47b6066 100644 --- a/test/binary/buf_spec.lua +++ b/test/binary/buf_spec.lua @@ -14,34 +14,19 @@ describe('buf', function() 'syntax="proto3";', 'package test;', 'message Foo{string bar=1;}', - }, { tmpdir = tmpdir, cwd = tmpdir }) + }, { tmpdir = tmpdir }) assert.is_true(#formatted > 3) end) it('can lint', function() - local linter = require('test.helper').get_linter('buf') + local helper = require('test.helper') vim.fn.writefile({ 'version: v2' }, tmpdir .. '/buf.yaml') - local protofile = tmpdir .. '/test.proto' - vim.fn.writefile({ + local bufnr, diagnostics = helper.run_lint('buf', 'proto', { 'syntax = "proto3";', 'message Foo {', ' string bar = 1;', '}', - }, protofile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'buf', - 'lint', - '--error-format=json', - protofile, - }, { cwd = tmpdir }) - :wait() - local output = result.stdout or '' - if output == '' then - output = result.stderr or '' - end - local diagnostics = linter.parse(output, bufnr) + }, { cwd = tmpdir, tmpdir = tmpdir }) assert.is_true(#diagnostics > 0) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) diff --git a/test/binary/cbfmt_spec.lua b/test/binary/cbfmt_spec.lua index fa49568..9e31cc8 100644 --- a/test/binary/cbfmt_spec.lua +++ b/test/binary/cbfmt_spec.lua @@ -1,21 +1,21 @@ describe('cbfmt', function() - it('can format', function() - local tmpdir = '/tmp/cbfmt-test' + local tmpdir = vim.fn.getcwd() .. '/tmp-cbfmt-test' + + setup(function() vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ '[languages]' }, tmpdir .. '/.cbfmt.toml') - local input = { + end) + + teardown(function() + vim.fn.delete(tmpdir, 'rf') + end) + + it('can format', function() + local formatted = require('test.helper').run_fmt('cbfmt', 'md', { '# Title', '', 'Some text.', - } - local result = vim - .system({ 'cbfmt', '--best-effort', '-p', 'markdown' }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - assert(result.code == 0, 'cbfmt exited ' .. result.code .. ': ' .. (result.stderr or '')) - local formatted = vim.split(result.stdout, '\n', { trimempty = true }) + }, { cwd = tmpdir }) assert.are.same({ '# Title', '', diff --git a/test/binary/detekt_spec.lua b/test/binary/detekt_spec.lua index 9db3049..f94f6d1 100644 --- a/test/binary/detekt_spec.lua +++ b/test/binary/detekt_spec.lua @@ -1,24 +1,19 @@ describe('detekt', function() it('can lint', function() - local linter = require('test.helper').get_linter('detekt') - local tmpfile = '/tmp/guard-test.kt' - local input = { + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('detekt', 'kt', { [[fun main() {]], [[ val x = 42]], [[ if (x > 0) {]], [[ println(x)]], [[ }]], [[}]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim.system({ 'detekt', '-i', tmpfile }):wait() - local output = result.stdout or '' - if output == '' then - output = result.stderr or '' - end - local diagnostics = linter.parse(output, bufnr) + }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'detekt', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('detekt', d.source) diff --git a/test/binary/dprint_spec.lua b/test/binary/dprint_spec.lua index c68342b..8a4e58e 100644 --- a/test/binary/dprint_spec.lua +++ b/test/binary/dprint_spec.lua @@ -1,26 +1,28 @@ describe('dprint', function() - it('can format', function() - local tmpdir = '/tmp/dprint-test' + local tmpdir = vim.fn.getcwd() .. '/tmp-dprint-test' + + setup(function() vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ '{', ' "typescript": {},', - ' "plugins": ["https://plugins.dprint.dev/typescript-0.93.3.wasm"]', + ' "plugins": [', + ' "https://plugins.dprint.dev/typescript-0.93.3.wasm"', + ' ]', '}', }, tmpdir .. '/dprint.json') - local input = { - [[const x=1;]], - [[function foo( ){return x}]], - } - local result = vim - .system({ 'dprint', 'fmt', '--stdin', 'test.ts' }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - assert(result.code == 0, 'dprint exited ' .. result.code .. ': ' .. (result.stderr or '')) - local formatted = vim.split(result.stdout, '\n', { trimempty = true }) + end) + + teardown(function() + vim.fn.delete(tmpdir, 'rf') + end) + + it('can format', function() + local formatted = require('test.helper').run_fmt('dprint', 'ts', { + 'const x=1;', + 'function foo( ){return x}', + }, { cwd = tmpdir, tmpdir = tmpdir }) assert.is_true(#formatted > 0) - assert.is_true(formatted[1]:find('const x') ~= nil) + assert.is_truthy(formatted[1]:find('const x')) end) end) diff --git a/test/binary/hadolint_spec.lua b/test/binary/hadolint_spec.lua index 0ba3f02..2bfa1a0 100644 --- a/test/binary/hadolint_spec.lua +++ b/test/binary/hadolint_spec.lua @@ -1,24 +1,16 @@ describe('hadolint', function() it('can lint', function() - local linter = require('test.helper').get_linter('hadolint') - local tmpfile = '/tmp/guard-test.dockerfile' - local input = { + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('hadolint', 'dockerfile', { [[FROM ubuntu]], [[RUN apt-get install python]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'hadolint', - '--no-fail', - '--format=json', - tmpfile, - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'hadolint', + severity = vim.diagnostic.severity.WARN, + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('hadolint', d.source) diff --git a/test/binary/ktlint_spec.lua b/test/binary/ktlint_spec.lua index 9e99a55..98093c2 100644 --- a/test/binary/ktlint_spec.lua +++ b/test/binary/ktlint_spec.lua @@ -1,37 +1,17 @@ describe('ktlint', function() - it('can format', function() - local formatted = require('test.helper').run_fmt('ktlint', 'kt', { - [[fun main() {]], - [[ val x=1]], - [[ println(x)]], - [[}]], - }) - assert.are.same({ - [[fun main() {]], - [[ val x = 1]], - [[ println(x)]], - [[}]], - }, formatted) - end) - it('can lint', function() - local linter = require('test.helper').get_linter('ktlint') - local tmpfile = '/tmp/guard-test.kt' - local input = { - [[fun main() {]], - [[ val x=1]], - [[ println(x)]], - [[}]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim.system({ 'ktlint', '--log-level=error', tmpfile }):wait() - local output = result.stdout or '' - if output == '' then - output = result.stderr or '' - end - local diagnostics = linter.parse(output, bufnr) + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('ktlint', 'kt', { + 'fun main() {', + ' val x=1', + ' println(x)', + '}', + }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'ktlint', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('ktlint', d.source) diff --git a/test/binary/shellcheck_spec.lua b/test/binary/shellcheck_spec.lua index 5381bd9..9913321 100644 --- a/test/binary/shellcheck_spec.lua +++ b/test/binary/shellcheck_spec.lua @@ -1,25 +1,17 @@ describe('shellcheck', function() it('can lint', function() - local linter = require('test.helper').get_linter('shellcheck') - local tmpfile = '/tmp/guard-test.sh' - local input = { + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('shellcheck', 'sh', { [[#!/bin/sh]], [[echo $FOO]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'shellcheck', - '--format', - 'json1', - '--external-sources', - tmpfile, - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'shellcheck', + severity = vim.diagnostic.severity.INFO, + message_pat = 'Double quote', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('shellcheck', d.source) diff --git a/test/go/golangci_lint_spec.lua b/test/go/golangci_lint_spec.lua index aefde3e..c07b22c 100644 --- a/test/go/golangci_lint_spec.lua +++ b/test/go/golangci_lint_spec.lua @@ -1,10 +1,22 @@ describe('golangci_lint', function() - it('can lint', function() - local linter = require('test.helper').get_linter('golangci_lint') - local tmpdir = '/tmp/golangci-test' + local tmpdir = vim.fn.getcwd() .. '/tmp-golangci-lint-test' + + setup(function() vim.fn.mkdir(tmpdir, 'p') - vim.fn.writefile({ 'module test', '', 'go 1.21' }, tmpdir .. '/go.mod') - local input = { + vim.fn.writefile({ + 'module testmod', + '', + 'go 1.21', + }, tmpdir .. '/go.mod') + end) + + teardown(function() + vim.fn.delete(tmpdir, 'rf') + end) + + it('can lint', function() + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('golangci_lint', 'go', { 'package main', '', 'import "fmt"', @@ -12,21 +24,7 @@ describe('golangci_lint', function() 'func main() {', '\tfmt.Errorf("unused error")', '}', - } - vim.fn.writefile(input, tmpdir .. '/main.go') - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'golangci-lint', - 'run', - '--fix=false', - '--out-format=json', - }, { - cwd = tmpdir, - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + }, { cwd = tmpdir, tmpdir = tmpdir }) assert.is_true(#diagnostics > 0) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) diff --git a/test/npm/eslint_d_spec.lua b/test/npm/eslint_d_spec.lua index f8a4893..465a6af 100644 --- a/test/npm/eslint_d_spec.lua +++ b/test/npm/eslint_d_spec.lua @@ -1,34 +1,27 @@ describe('eslint_d', function() - it('can lint', function() - local linter = require('test.helper').get_linter('eslint_d') - local tmpdir = '/tmp/eslintd-test' + local tmpdir = vim.fn.getcwd() .. '/tmp-eslint-d-test' + + setup(function() vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ 'module.exports = [{ rules: { "no-unused-vars": "error" } }];', }, tmpdir .. '/eslint.config.js') - local tmpfile = tmpdir .. '/test.js' - local input = { - [[const x = 1;]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'npx', - 'eslint_d', - '--format', - 'json', - '--stdin', - '--stdin-filename', - tmpfile, - }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + end) + + teardown(function() + vim.fn.delete(tmpdir, 'rf') + end) + + it('can lint', function() + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('eslint_d', 'js', { + 'const x = 1;', + }, { cwd = tmpdir, tmpdir = tmpdir }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'eslint_d', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('eslint_d', d.source) @@ -38,29 +31,12 @@ describe('eslint_d', function() end) it('can format', function() - local tmpdir = '/tmp/eslintd-test' - vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ 'module.exports = [{ rules: { "semi": ["error", "always"] } }];', }, tmpdir .. '/eslint.config.js') - local tmpfile = tmpdir .. '/test.js' - local input = { - [[const x = 1]], - } - vim.fn.writefile(input, tmpfile) - local config = require('guard-collection.formatter').eslint_d - local cmd = vim.list_extend({ config.cmd }, config.args) - table.insert(cmd, tmpfile) - local result = vim - .system(cmd, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - assert(result.code == 0, 'eslint_d exited ' .. result.code .. ': ' .. (result.stderr or '')) - local formatted = vim.split(result.stdout, '\n', { trimempty = true }) - assert.are.same({ - [[const x = 1;]], - }, formatted) + local formatted = require('test.helper').run_fmt('eslint_d', 'js', { + 'const x = 1', + }, { cwd = tmpdir, tmpdir = tmpdir }) + assert.are.same({ 'const x = 1;' }, formatted) end) end) diff --git a/test/npm/eslint_spec.lua b/test/npm/eslint_spec.lua index 8ea0339..21c5566 100644 --- a/test/npm/eslint_spec.lua +++ b/test/npm/eslint_spec.lua @@ -1,34 +1,27 @@ describe('eslint', function() - it('can lint', function() - local linter = require('test.helper').get_linter('eslint') - local tmpdir = '/tmp/eslint-test' + local tmpdir = vim.fn.getcwd() .. '/tmp-eslint-test' + + setup(function() vim.fn.mkdir(tmpdir, 'p') vim.fn.writefile({ 'module.exports = [{ rules: { "no-unused-vars": "error" } }];', }, tmpdir .. '/eslint.config.js') - local tmpfile = tmpdir .. '/test.js' - local input = { - [[const x = 1;]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'npx', - 'eslint', - '--format', - 'json', - '--stdin', - '--stdin-filename', - tmpfile, - }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + end) + + teardown(function() + vim.fn.delete(tmpdir, 'rf') + end) + + it('can lint', function() + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('eslint', 'js', { + 'const x = 1;', + }, { cwd = tmpdir, tmpdir = tmpdir }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'eslint', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('eslint', d.source) diff --git a/test/npm/stylelint_spec.lua b/test/npm/stylelint_spec.lua index 70639c1..06d654a 100644 --- a/test/npm/stylelint_spec.lua +++ b/test/npm/stylelint_spec.lua @@ -1,41 +1,27 @@ describe('stylelint', function() - it('can lint', function() - local linter = require('test.helper').get_linter('stylelint') - local tmpdir = '/tmp/stylelint-test' + local tmpdir = vim.fn.getcwd() .. '/tmp-stylelint-test' + + setup(function() vim.fn.mkdir(tmpdir, 'p') - local configfile = tmpdir .. '/.stylelintrc.json' vim.fn.writefile({ '{ "rules": { "color-no-invalid-hex": true } }', - }, configfile) - local tmpfile = tmpdir .. '/test.css' - local input = { - [[a { color: #fff1az; }]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'npx', - 'stylelint', - '--formatter', - 'json', - '--stdin', - '--stdin-filename', - tmpfile, - '--config', - configfile, - }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - local output = result.stdout or '' - if output == '' then - output = result.stderr or '' - end - assert(output ~= '', 'stylelint: no output (code=' .. result.code .. ')') - local diagnostics = linter.parse(output, bufnr) + }, tmpdir .. '/.stylelintrc.json') + end) + + teardown(function() + vim.fn.delete(tmpdir, 'rf') + end) + + it('can lint', function() + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('stylelint', 'css', { + 'a { color: #fff1az; }', + }, { cwd = tmpdir, tmpdir = tmpdir }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'stylelint', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('stylelint', d.source) diff --git a/test/pip/pylint_spec.lua b/test/pip/pylint_spec.lua index 54bf7ae..f209df1 100644 --- a/test/pip/pylint_spec.lua +++ b/test/pip/pylint_spec.lua @@ -1,27 +1,15 @@ describe('pylint', function() it('can lint', function() - local linter = require('test.helper').get_linter('pylint') - local tmpfile = '/tmp/guard-test.py' - local input = { + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('pylint', 'py', { [[import os]], [[x = 1]], - } - vim.fn.writefile(input, tmpfile) - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'pylint', - '--from-stdin', - '--output-format', - 'json', - tmpfile, - }, { - stdin = table.concat(input, '\n') .. '\n', - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'pylint', + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.equal('pylint', d.source) diff --git a/test/pip/ruff_spec.lua b/test/pip/ruff_spec.lua index 8439bd0..8aecb47 100644 --- a/test/pip/ruff_spec.lua +++ b/test/pip/ruff_spec.lua @@ -22,13 +22,17 @@ describe('ruff', function() it('can lint', function() local helper = require('test.helper') - local buf, diagnostics = helper.run_lint('ruff', 'py', { + local bufnr, diagnostics = helper.run_lint('ruff', 'py', { [[import os]], [[x = 1]], }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + source = 'ruff', + }) for _, d in ipairs(diagnostics) do - assert.equal(buf, d.bufnr) + assert.equal(bufnr, d.bufnr) assert.equal('ruff', d.source) assert.is_number(d.lnum) assert.is_string(d.message) diff --git a/test/ruby/rubocop_spec.lua b/test/ruby/rubocop_spec.lua index 16f0df2..0a1f24b 100644 --- a/test/ruby/rubocop_spec.lua +++ b/test/ruby/rubocop_spec.lua @@ -10,55 +10,15 @@ describe('rubocop', function() vim.system({ 'bundle', 'install' }, { cwd = tmpdir }):wait() end) - it('can format', function() - local input = { - [[x = { :a=>1,:b => 2 }]], - } - local result = vim - .system({ - 'bundle', - 'exec', - 'rubocop', - '-A', - '-f', - 'quiet', - '--stderr', - '--stdin', - 'test.rb', - }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - local output = result.stderr or '' - local formatted = vim.split(output, '\n', { trimempty = true }) - assert.is_true(#formatted > 0) - end) - it('can lint', function() - local linter = require('test.helper').get_linter('rubocop') - local input = { + local helper = require('test.helper') + local bufnr, diagnostics = helper.run_lint('rubocop', 'rb', { [[x = { :a=>1,:b => 2 }]], - } - local bufnr = vim.api.nvim_create_buf(false, true) - local result = vim - .system({ - 'bundle', - 'exec', - 'rubocop', - '--format', - 'json', - '--force-exclusion', - '--stdin', - 'test.rb', - }, { - stdin = table.concat(input, '\n') .. '\n', - cwd = tmpdir, - }) - :wait() - local output = result.stdout or '' - local diagnostics = linter.parse(output, bufnr) + }, { cwd = tmpdir }) assert.is_true(#diagnostics > 0) + helper.assert_diag(diagnostics[1], { + bufnr = bufnr, + }) for _, d in ipairs(diagnostics) do assert.equal(bufnr, d.bufnr) assert.is_number(d.lnum) From 1774811bec6ebd6ffd4722a92f06a6d9d6b5e5eb Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 13:25:27 -0500 Subject: [PATCH 06/10] ci(cljfmt): use standalone binary and extract apt packages to file Problem: cljfmt required a dedicated CI job with Java, Clojure CLI, a hand-rolled wrapper script, and dep pre-warming. The binary job also had an inline apt-get install command inconsistent with other tool lists. Solution: switch cljfmt to the standalone GraalVM binary from GitHub releases, move its test into test/binary/, delete the test-clojure job, and extract the binary job's apt packages into binary-apt.txt. --- .github/tools/binary-apt.txt | 6 +++++ .github/tools/binary.txt | 1 + .github/workflows/ci.yaml | 30 +----------------------- Makefile | 7 ++---- test/{clojure => binary}/cljfmt_spec.lua | 0 5 files changed, 10 insertions(+), 34 deletions(-) create mode 100644 .github/tools/binary-apt.txt rename test/{clojure => binary}/cljfmt_spec.lua (100%) diff --git a/.github/tools/binary-apt.txt b/.github/tools/binary-apt.txt new file mode 100644 index 0000000..2781657 --- /dev/null +++ b/.github/tools/binary-apt.txt @@ -0,0 +1,6 @@ +fish +jq +libxml2-utils +pgformatter +shellcheck +zsh diff --git a/.github/tools/binary.txt b/.github/tools/binary.txt index 18a2224..786b125 100644 --- a/.github/tools/binary.txt +++ b/.github/tools/binary.txt @@ -2,6 +2,7 @@ alejandra bin https://github.com/kamadorueda/alejandra/releases/download/4.0.0/a buf bin https://github.com/bufbuild/buf/releases/download/v1.47.2/buf-Linux-x86_64 cbfmt tar https://github.com/lukas-reineke/cbfmt/releases/download/v0.2.0/cbfmt_linux-x86_64_v0.2.0.tar.gz cbfmt_linux-x86_64_v0.2.0/cbfmt checkmake bin https://github.com/mrtazz/checkmake/releases/download/0.2.2/checkmake-0.2.2.linux.amd64 +cljfmt tar https://github.com/weavejester/cljfmt/releases/download/0.15.6/cljfmt-0.15.6-linux-amd64-static.tar.gz cljfmt deno zip https://github.com/denoland/deno/releases/download/v2.1.4/deno-x86_64-unknown-linux-gnu.zip detekt jar https://github.com/detekt/detekt/releases/download/v1.23.7/detekt-cli-1.23.7-all.jar dprint zip https://github.com/dprint/dprint/releases/download/0.49.0/dprint-x86_64-unknown-linux-gnu.zip diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fb75461..bcaf18c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -113,7 +113,7 @@ jobs: java-version: 21 - name: Install tools run: | - sudo apt-get install -y zsh jq libxml2-utils shellcheck fish pgformatter + xargs sudo apt-get install -y < .github/tools/binary-apt.txt bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin" - name: Run tests run: | @@ -168,34 +168,6 @@ jobs: export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" busted --lua nlua test/ruby/*_spec.lua - test-clojure: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/test-setup - - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 21 - - name: Install Clojure CLI - run: | - curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh - chmod +x linux-install.sh - sudo ./linux-install.sh - - name: Install tools - run: | - mkdir -p $HOME/.local/bin - printf '#!/bin/sh\nclojure -Sdeps '"'"'{:deps {dev.weavejester/cljfmt {:mvn/version "0.13.0"}}}'"'"' -M -m cljfmt.main "$@"\n' > $HOME/.local/bin/cljfmt && chmod +x $HOME/.local/bin/cljfmt - - name: Pre-warm cljfmt deps - run: | - export PATH="$HOME/.local/bin:$PATH" - echo "" | cljfmt fix - || true - - name: Run tests - run: | - export PATH="$HOME/.local/bin:$PATH" - export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" - busted --lua nlua test/clojure/*_spec.lua - test-elixir: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index f279da3..3f00966 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ LUA_PATH := lua/?.lua;lua/?/init.lua;$(LUA_PATH) export LUA_PATH -.PHONY: lint test test-pip test-npm test-go test-rust test-lua test-binary test-apt test-dotnet test-ruby test-clojure test-elixir test-nix test-swift +.PHONY: lint test test-pip test-npm test-go test-rust test-lua test-binary test-apt test-dotnet test-ruby test-elixir test-nix test-swift lint: stylua --check . -test: test-pip test-npm test-go test-rust test-lua test-binary test-apt test-dotnet test-ruby test-clojure test-elixir test-nix test-swift +test: test-pip test-npm test-go test-rust test-lua test-binary test-apt test-dotnet test-ruby test-elixir test-nix test-swift test-pip: busted --lua nlua test/pip/*_spec.lua @@ -35,9 +35,6 @@ test-dotnet: test-ruby: busted --lua nlua test/ruby/*_spec.lua -test-clojure: - busted --lua nlua test/clojure/*_spec.lua - test-elixir: busted --lua nlua test/elixir/*_spec.lua diff --git a/test/clojure/cljfmt_spec.lua b/test/binary/cljfmt_spec.lua similarity index 100% rename from test/clojure/cljfmt_spec.lua rename to test/binary/cljfmt_spec.lua From 2625efc444bbd52300d84f296bfdc7bd86f88924 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 14:48:33 -0500 Subject: [PATCH 07/10] ci: retrigger From 9b7130072eafb7c3cafe13718fdcb5accf481543 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 14:51:46 -0500 Subject: [PATCH 08/10] ci: retrigger From 4b63ee274b4ae07b4f73a7a18d1eb28b520eb1d6 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Feb 2026 15:04:59 -0500 Subject: [PATCH 09/10] ci: re-trigger From ebf68b524356d40342c692deb2d280e5a7e54c77 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 10 Feb 2026 13:13:33 -0500 Subject: [PATCH 10/10] fix(rubocop): use rubocop directly instead of bundle exec Problem: rubocop formatter and linter definitions used `bundle exec rubocop`, requiring a Gemfile and bundle install in both tests and CI. Solution: invoke rubocop directly via `gem install rubocop`. Remove Gemfile setup from test and CI. --- .github/workflows/ci.yaml | 7 +------ lua/guard-collection/formatter.lua | 4 ++-- lua/guard-collection/linter/rubocop.lua | 4 ++-- test/ruby/rubocop_spec.lua | 13 +------------ 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bcaf18c..7b4364e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -157,12 +157,7 @@ jobs: with: ruby-version: '3.3' - name: Install tools - run: gem install rubocop bundler - - name: Setup rubocop Gemfile - run: | - mkdir -p /tmp/rubocop-test - printf "source 'https://rubygems.org'\ngem 'rubocop'\n" > /tmp/rubocop-test/Gemfile - cd /tmp/rubocop-test && bundle install + run: gem install rubocop - name: Run tests run: | export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH" diff --git a/lua/guard-collection/formatter.lua b/lua/guard-collection/formatter.lua index 6bffdf5..ff61fe8 100644 --- a/lua/guard-collection/formatter.lua +++ b/lua/guard-collection/formatter.lua @@ -212,8 +212,8 @@ M.prettierd = { } M.rubocop = { - cmd = 'bundle', - args = { 'exec', 'rubocop', '-A', '-f', 'quiet', '--stderr', '--stdin' }, + cmd = 'rubocop', + args = { '-A', '-f', 'quiet', '--stderr', '--stdin' }, stdin = true, fname = true, } diff --git a/lua/guard-collection/linter/rubocop.lua b/lua/guard-collection/linter/rubocop.lua index 732d8c5..38e67eb 100644 --- a/lua/guard-collection/linter/rubocop.lua +++ b/lua/guard-collection/linter/rubocop.lua @@ -1,8 +1,8 @@ local lint = require('guard.lint') return { - cmd = 'bundle', - args = { 'exec', 'rubocop', '--format', 'json', '--force-exclusion', '--stdin' }, + cmd = 'rubocop', + args = { '--format', 'json', '--force-exclusion', '--stdin' }, stdin = true, fname = true, parse = lint.from_json({ diff --git a/test/ruby/rubocop_spec.lua b/test/ruby/rubocop_spec.lua index 0a1f24b..1f4ac1a 100644 --- a/test/ruby/rubocop_spec.lua +++ b/test/ruby/rubocop_spec.lua @@ -1,20 +1,9 @@ describe('rubocop', function() - local tmpdir = '/tmp/rubocop-test' - - setup(function() - vim.fn.mkdir(tmpdir, 'p') - vim.fn.writefile({ - "source 'https://rubygems.org'", - "gem 'rubocop'", - }, tmpdir .. '/Gemfile') - vim.system({ 'bundle', 'install' }, { cwd = tmpdir }):wait() - end) - it('can lint', function() local helper = require('test.helper') local bufnr, diagnostics = helper.run_lint('rubocop', 'rb', { [[x = { :a=>1,:b => 2 }]], - }, { cwd = tmpdir }) + }) assert.is_true(#diagnostics > 0) helper.assert_diag(diagnostics[1], { bufnr = bufnr,