Skip to content

Commit

Permalink
New indentation test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
axvr committed Jan 26, 2025
1 parent 8e9ed28 commit e5f86af
Show file tree
Hide file tree
Showing 48 changed files with 121 additions and 97 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/indent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Indent
on:
push:
branches: [ master ]
pull_request:
workflow_dispatch:

jobs:
vim-latest:
runs-on: ubuntu-latest
steps:
- name: Fetch source
uses: actions/checkout@v3
- name: Install Vim
uses: rhysd/action-setup-vim@v1
with: { version: stable }
- name: Run indentation tests
run: EDITOR=vim do/test-indent
working-directory: ./dev

neovim-latest:
runs-on: ubuntu-latest
steps:
- name: Fetch source
uses: actions/checkout@v3
- name: Install Neovim
uses: rhysd/action-setup-vim@v1
with: { neovim: true, version: stable }
- name: Run indentation tests
run: EDITOR=nvim do/test-indent
working-directory: ./dev
13 changes: 1 addition & 12 deletions .github/workflows/clojure.yml → .github/workflows/syntax.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Syntax
on:
push:
branches:
Expand Down Expand Up @@ -29,17 +29,6 @@ jobs:
with:
lein: 2.11.2

- name: Install Vim
uses: rhysd/action-setup-vim@v1
with:
version: stable

- name: Install Neovim
uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: stable

- name: Cache m2
uses: actions/cache@v3
env:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion clj/resources/indent-test-cases/s-expr_standard/config.edn

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion clj/resources/indent-test-cases/s-expr_uniform/config.edn

This file was deleted.

21 changes: 0 additions & 21 deletions clj/test/vim/helpers.clj

This file was deleted.

49 changes: 0 additions & 49 deletions clj/test/vim/indent_test.clj

This file was deleted.

67 changes: 67 additions & 0 deletions dev/do/test-indent
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

# Run Clojure.vim indentation tests

# TODO: colour messages?

if [ "$EDITOR" != 'vim' ] && [ "$EDITOR" != 'nvim' ]; then
echo 'ERROR: Set the "EDITOR" environment variable to "vim" or "nvim" and run again.'
exit 1
fi

PASSED=()
FAILED=()
SKIPPED=()

tmp_base_dir='/tmp/clojure.vim/indent'
mkdir -p "$tmp_base_dir"
tmp_dir="$(mktemp --directory "$tmp_base_dir/XXXXXX")"
test_case_dir='tests'

test_pass() { PASSED+=("$1"); }
test_fail() {
FAILED+=("$1")
echo "::error file=clj/indent-test/$test_case_dir/$1/out.clj::Failed indent test case."
}
test_skip() {
SKIPPED+=("$1")
echo "::warning file=clj/indent-test/$test_case_dir/$1/out.clj::Skipped indent test case."
}

run_test_case() {
test_case="$1"
in_file="$test_case_dir/$test_case/in.clj"
expected_file="$test_case_dir/$test_case/out.clj"

echo "::group::$EDITOR -- $test_case"

if [ -f "$test_case_dir/$test_case/SKIP" ]; then
test_skip "$test_case"
else
actual_file="$tmp_dir/$test_case.clj"
cp "$in_file" "$actual_file"

# Override the default test commands with a `test.vim` file.
test_script="$test_case_dir/$test_case/test.vim"
if [ -f "$test_script" ]; then
test_cmd=('-S' "$test_script")
else
test_cmd=('+normal! gg=G')
fi

"$EDITOR" --clean -NXnu test-vimrc.vim "${test_cmd[@]}" '+xall!' -- "$actual_file"

diff --color=always -u "$expected_file" "$actual_file"

[ $? -eq 0 ] && test_pass "$test_case" || test_fail "$test_case"
fi

echo '::endgroup::'
}

for tcase in $test_case_dir/*/; do
run_test_case "$(basename "$tcase")"
done

echo "passed: ${#PASSED[@]}, failed: ${#FAILED[@]}, skipped: ${#SKIPPED[@]}"
exit ${#FAILED[@]}
3 changes: 3 additions & 0 deletions dev/test-vimrc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let &rtp = getcwd() . '/..,' . &rtp
filetype plugin indent on
syntax enable
File renamed without changes.
File renamed without changes.
Empty file added dev/tests/custom_types/SKIP
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added dev/tests/letfn/SKIP
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions dev/tests/multi-line_strings_pretty/test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let g:clojure_indent_multiline_strings = 'pretty'
normal! gg=G
normal! G
exec "normal! o\<CR>test \"hello\<CR>world\""
exec "normal! o\<CR>regex #\"asdf\<CR>bar\""
5 changes: 5 additions & 0 deletions dev/tests/multi-line_strings_standard/test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let g:clojure_indent_multiline_strings = 'standard'
normal! gg=G
normal! G
exec "normal! o\<CR>test \"hello\<CR>world\""
exec "normal! o\<CR>regex #\"asdf\<CR>bar\""
5 changes: 5 additions & 0 deletions dev/tests/multi-line_strings_traditional/test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let g:clojure_indent_multiline_strings = 'traditional'
normal! gg=G
normal! G
exec "normal! o\<CR>test \"hello\<CR>world\""
exec "normal! o\<CR>regex #\"asdf\<CR>bar\""
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions dev/tests/s-expr_traditional/test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let g:clojure_indent_style = 'traditional'
normal! gg=G
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions dev/tests/s-expr_uniform/test.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let g:clojure_indent_style = 'uniform'
normal! gg=G
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e5f86af

Please sign in to comment.