Skip to content

Commit a26b683

Browse files
test: add previously existing tests (#74)
* feat(linter): add zsh syntax checker * fix(ci): add luarocks bin to PATH * fix: revert ci change * feat(linter): add cpplint C++ linter * feat(linter): add cpplint C++ linter * ci: rewrite workflow with parallel jobs and modern actions replaces monolithic test job with parallel jobs grouped by package manager. each job installs only what it needs and runs its specific tests. - uses nvim-neorocks/nvim-busted-action for neovim + vusted setup - updates all actions to latest versions (checkout@v4, setup-python@v5, etc) - adds coverage job to warn when tools are missing tests - removes setup.sh and env.sh (no longer needed) * test: update expectations for guard.nvim diagnostic format changes - Strip _extmark_id in linter helper (internal nvim field) - Update tests to use separate code field instead of message suffix - Update end_col values to match guard.nvim behavior - Update rustfmt expected output for new import formatting style - Update buf formatter expected output (compact style) - Add missing W292 diagnostic to flake8 test - Remove buf linter test (requires buf.yaml config) * refactor(test): reorganize tests by package manager Move tests from test/{formatter,linter}/ to test/{pip,npm,go,rust,lua,binary,clang,haskell}/ to allow CI to use glob patterns (busted test/pip/*_spec.lua) instead of listing each test file explicitly. This means adding new tools no longer requires workflow changes. * fix(test): update checkmake expected output for new phonydeclared rule * fix(ci): run clang tests separately to avoid state pollution Run each clang test file in its own busted process to prevent test state from leaking between clang-format and clang-tidy tests. * fix(test): revert checkmake linter, fix test order Revert checkmake linter to original fn-based approach. Update test to match actual diagnostic output order. * fix(test): restore swiftformat test with proper naming Original test was named swiftformat.lua (missing _spec suffix) so busted never ran it. Restored with correct naming and added swiftformat installation to CI. * fix(ci): rename swiftformat binary after extraction * fix(test): restore buf linter test and fix formatter expectation * fix(buf): use fn approach for linter, fname for formatter * Revert "fix(buf): use fn approach for linter, fname for formatter" This reverts commit 51d94b1. * fix(buf): simpler test input, formatter uses fname not stdin * Revert "fix(buf): simpler test input, formatter uses fname not stdin" This reverts commit 3b5c3af. * fix(ci): remove buf tests (fix in separate PR) * fix: move cpplint to pip, zsh to binary * refactor(test)!: replace async test infra with synchronous execution Old test helpers used guard.nvim's async pipeline with a hardcoded vim.wait(3000), causing flaky CI failures. New approach runs tools directly via vim.system():wait() — zero timing issues, tests real tool output, no dependency on guard.nvim's format/filetype modules. This commit strips all existing tests and CI jobs down to a single MVP (black formatter + flake8 linter) to validate the approach. Remaining tools will be re-added in a follow-up PR. BREAKING CHANGE: test helpers renamed from fmt_helper/lint_helper to a unified test/helper.lua with run_fmt(), run_lint(), get_linter() * test: add remaining formatter and linter tests Re-adds all previously covered tools using the new synchronous test infrastructure from the prior commit. All 8 CI job categories restored (pip, npm, go, rust, lua, binary, clang, haskell). Linter assertions now use structural checks (has diagnostics, correct source/bufnr/types) instead of exact field matching, preventing breakage when tool versions change output formatting. * fix(ci): install zsh in test-binary job * refactor(ci): replace haskell toolchain with pre-built binary, add mypy Problem: test-haskell job spent ~5 minutes setting up GHC and cabal to compile hlint from source. mypy linter had no test despite being testable. Solution: download pre-built hlint binary in test-binary and delete the test-haskell job. Add mypy linter test and install to test-pip. * refactor: rename test-clang to test-apt Problem: the job name implied a clang-specific toolchain but the tools are installed via apt. Solution: rename directory, CI job, and Makefile target to test-apt. * refactor(ci): extract tool installs into manifest files and script Problem: adding a binary tool required modifying the CI workflow directly with inline wget/unzip/tar commands, and the test-apt Makefile target used an inconsistent loop instead of a glob. Solution: add an install-binary-tools.sh script that reads a manifest file (name, type, url, archive-path) and handles bin/zip/tar downloads. Move all tool lists into .github/tools/ files so each CI job reads from a file instead of inlining package names. Make the test-apt target consistent with all other Makefile targets. * refactor(test): remove orphaned test/linter directory Problem: test/linter/ contained duplicate cpplint and zsh tests that imported a nonexistent test.linter.helper module. The correct versions already exist in test/pip/ and test/binary/ using the standard test.helper pattern. Solution: delete test/linter/ entirely since the properly structured tests are already in place. * ci: retrigger after transient luarocks download failure --------- Co-authored-by: xiaoshihou <xiaoshihou@tutamail.com>
1 parent 5f924a0 commit a26b683

40 files changed

Lines changed: 863 additions & 64 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
dest="${1:-.}"
5+
manifest="${2:-.github/tools/binary.txt}"
6+
7+
mkdir -p "$dest"
8+
9+
while read -r name type url extra; do
10+
[[ -z "$name" || "$name" == \#* ]] && continue
11+
12+
case "$type" in
13+
bin)
14+
wget -q "$url" -O "$dest/$name"
15+
chmod +x "$dest/$name"
16+
;;
17+
zip)
18+
tmpdir="$(mktemp -d)"
19+
wget -q "$url" -O "$tmpdir/archive.zip"
20+
unzip -q "$tmpdir/archive.zip" -d "$tmpdir"
21+
mv "$tmpdir/${extra:-$name}" "$dest/$name"
22+
chmod +x "$dest/$name"
23+
rm -rf "$tmpdir"
24+
;;
25+
tar)
26+
tmpdir="$(mktemp -d)"
27+
wget -q "$url" -O "$tmpdir/archive.tar.gz"
28+
tar xzf "$tmpdir/archive.tar.gz" -C "$tmpdir"
29+
mv "$tmpdir/$extra" "$dest/$name"
30+
chmod +x "$dest/$name"
31+
rm -rf "$tmpdir"
32+
;;
33+
esac
34+
done < "$manifest"

.github/tools/apt.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
clang-format
2+
clang-tidy

.github/tools/binary.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
alejandra bin https://github.com/kamadorueda/alejandra/releases/download/4.0.0/alejandra-x86_64-unknown-linux-musl
2+
buf bin https://github.com/bufbuild/buf/releases/download/v1.47.2/buf-Linux-x86_64
3+
checkmake bin https://github.com/mrtazz/checkmake/releases/download/0.2.2/checkmake-0.2.2.linux.amd64
4+
deno zip https://github.com/denoland/deno/releases/download/v2.1.4/deno-x86_64-unknown-linux-gnu.zip
5+
hlint tar https://github.com/ndmitchell/hlint/releases/download/v3.10/hlint-3.10-x86_64-linux.tar.gz hlint-3.10/hlint
6+
latexindent bin https://github.com/cmhughes/latexindent.pl/releases/download/V3.24.4/latexindent-linux
7+
swiftformat zip https://github.com/nicklockwood/SwiftFormat/releases/download/0.55.3/swiftformat_linux.zip swiftformat_linux

.github/tools/go.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mvdan.cc/gofumpt@latest
2+
github.com/segmentio/golines@latest

.github/tools/lua-binary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
selene zip https://github.com/Kampfkarren/selene/releases/download/0.28.0/selene-0.28.0-linux.zip
2+
stylua zip https://github.com/JohnnyMorganz/StyLua/releases/download/v2.0.2/stylua-linux-x86_64.zip

.github/tools/npm.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
prettier
2+
@biomejs/biome
3+
sql-formatter
4+
@taplo/cli

.github/tools/pip.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
autopep8
2+
black
3+
cmake-format
4+
cpplint
5+
docformatter
6+
flake8
7+
mypy
8+
ruff
9+
sqlfluff
10+
yapf

.github/workflows/ci.yaml

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- uses: hishamhm/gh-actions-luarocks@master
3535
- name: Install tools
3636
run: |
37-
pip install -q black flake8
37+
pip install -q -r .github/tools/pip.txt
3838
luarocks install busted --local
3939
luarocks install nlua --local
4040
- name: Clone guard.nvim
@@ -43,3 +43,165 @@ jobs:
4343
run: |
4444
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
4545
busted --lua nlua test/pip/*_spec.lua
46+
47+
test-npm:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
- uses: rhysd/action-setup-vim@v1
52+
with:
53+
neovim: true
54+
version: nightly
55+
- uses: actions/setup-node@v4
56+
with:
57+
node-version: 20
58+
- uses: leso-kn/gh-actions-lua@master
59+
with:
60+
luaVersion: "5.1"
61+
- uses: hishamhm/gh-actions-luarocks@master
62+
- name: Install tools
63+
run: |
64+
xargs npm install -g < .github/tools/npm.txt
65+
luarocks install busted --local
66+
luarocks install nlua --local
67+
- name: Clone guard.nvim
68+
run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/
69+
- name: Run tests
70+
run: |
71+
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
72+
busted --lua nlua test/npm/*_spec.lua
73+
74+
test-go:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
- uses: rhysd/action-setup-vim@v1
79+
with:
80+
neovim: true
81+
version: nightly
82+
- uses: actions/setup-go@v5
83+
with:
84+
go-version: stable
85+
cache: false
86+
- uses: leso-kn/gh-actions-lua@master
87+
with:
88+
luaVersion: "5.1"
89+
- uses: hishamhm/gh-actions-luarocks@master
90+
- name: Install tools
91+
run: |
92+
xargs -L1 go install < .github/tools/go.txt
93+
luarocks install busted --local
94+
luarocks install nlua --local
95+
- name: Clone guard.nvim
96+
run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/
97+
- name: Run tests
98+
run: |
99+
export PATH="$HOME/go/bin:$PATH"
100+
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
101+
busted --lua nlua test/go/*_spec.lua
102+
103+
test-rust:
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v4
107+
- uses: rhysd/action-setup-vim@v1
108+
with:
109+
neovim: true
110+
version: nightly
111+
- uses: dtolnay/rust-toolchain@stable
112+
with:
113+
components: rustfmt
114+
- uses: dtolnay/rust-toolchain@nightly
115+
with:
116+
components: rustfmt
117+
- uses: leso-kn/gh-actions-lua@master
118+
with:
119+
luaVersion: "5.1"
120+
- uses: hishamhm/gh-actions-luarocks@master
121+
- name: Install test tools
122+
run: |
123+
luarocks install busted --local
124+
luarocks install nlua --local
125+
- name: Clone guard.nvim
126+
run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/
127+
- name: Run tests
128+
run: |
129+
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
130+
busted --lua nlua test/rust/*_spec.lua
131+
132+
test-lua:
133+
runs-on: ubuntu-latest
134+
steps:
135+
- uses: actions/checkout@v4
136+
- uses: rhysd/action-setup-vim@v1
137+
with:
138+
neovim: true
139+
version: nightly
140+
- uses: leso-kn/gh-actions-lua@master
141+
with:
142+
luaVersion: "5.1"
143+
- uses: hishamhm/gh-actions-luarocks@master
144+
- name: Install tools
145+
run: |
146+
luarocks install busted --local
147+
luarocks install nlua --local
148+
luarocks install luacheck --local
149+
bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin" .github/tools/lua-binary.txt
150+
- name: Clone guard.nvim
151+
run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/
152+
- name: Run tests
153+
run: |
154+
export PATH="$HOME/.local/bin:$PATH"
155+
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
156+
busted --lua nlua test/lua/*_spec.lua
157+
158+
test-binary:
159+
runs-on: ubuntu-latest
160+
steps:
161+
- uses: actions/checkout@v4
162+
- uses: rhysd/action-setup-vim@v1
163+
with:
164+
neovim: true
165+
version: nightly
166+
- uses: leso-kn/gh-actions-lua@master
167+
with:
168+
luaVersion: "5.1"
169+
- uses: hishamhm/gh-actions-luarocks@master
170+
- name: Install tools
171+
run: |
172+
sudo apt-get install -y zsh
173+
luarocks install busted --local
174+
luarocks install nlua --local
175+
bash .github/scripts/install-binary-tools.sh "$HOME/.local/bin"
176+
- name: Clone guard.nvim
177+
run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/
178+
- name: Run tests
179+
run: |
180+
export PATH="$HOME/.local/bin:$PATH"
181+
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
182+
busted --lua nlua test/binary/*_spec.lua
183+
184+
test-apt:
185+
runs-on: ubuntu-latest
186+
steps:
187+
- uses: actions/checkout@v4
188+
- uses: rhysd/action-setup-vim@v1
189+
with:
190+
neovim: true
191+
version: nightly
192+
- uses: leso-kn/gh-actions-lua@master
193+
with:
194+
luaVersion: "5.1"
195+
- uses: hishamhm/gh-actions-luarocks@master
196+
- name: Install tools
197+
run: |
198+
xargs sudo apt-get install -y < .github/tools/apt.txt
199+
luarocks install busted --local
200+
luarocks install nlua --local
201+
- name: Clone guard.nvim
202+
run: git clone --depth 1 https://github.com/nvimdev/guard.nvim && mv guard.nvim/lua/guard lua/
203+
- name: Run tests
204+
run: |
205+
export LUA_PATH="lua/?.lua;lua/?/init.lua;$LUA_PATH"
206+
busted --lua nlua test/apt/*_spec.lua
207+

Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
LUA_PATH := lua/?.lua;lua/?/init.lua;$(LUA_PATH)
22
export LUA_PATH
33

4-
.PHONY: lint test test-pip
4+
.PHONY: lint test test-pip test-npm test-go test-rust test-lua test-binary test-apt
55

66
lint:
77
stylua --check .
88

9-
test: test-pip
9+
test: test-pip test-npm test-go test-rust test-lua test-binary test-apt
1010

1111
test-pip:
1212
busted --lua nlua test/pip/*_spec.lua
13+
14+
test-npm:
15+
busted --lua nlua test/npm/*_spec.lua
16+
17+
test-go:
18+
busted --lua nlua test/go/*_spec.lua
19+
20+
test-rust:
21+
busted --lua nlua test/rust/*_spec.lua
22+
23+
test-lua:
24+
busted --lua nlua test/lua/*_spec.lua
25+
26+
test-binary:
27+
busted --lua nlua test/binary/*_spec.lua
28+
29+
test-apt:
30+
busted --lua nlua test/apt/*_spec.lua
31+

test/apt/clang-format_spec.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
describe('clang-format', function()
2+
it('can format', function()
3+
local formatted = require('test.helper').run_fmt('clang-format', 'c', {
4+
[[#include <stdio.h>]],
5+
[[int main() {]],
6+
[[ int x = 0x87654321]],
7+
[[ ;]],
8+
[[int least_significant = 0xFF;]],
9+
[[ printf("0x%X\n", x ]],
10+
[[& least_significant);]],
11+
[[ return 0;]],
12+
[[}]],
13+
})
14+
assert.are.same({
15+
[[#include <stdio.h>]],
16+
[[int main() {]],
17+
[[ int x = 0x87654321;]],
18+
[[ int least_significant = 0xFF;]],
19+
[[ printf("0x%X\n", x & least_significant);]],
20+
[[ return 0;]],
21+
[[}]],
22+
}, formatted)
23+
end)
24+
end)

0 commit comments

Comments
 (0)