Add regression test (#157)

This commit is contained in:
Satoshi SAKAO
2025-02-08 03:59:24 +09:00
committed by GitHub
parent 30ce89788a
commit 2fa181dc12
3 changed files with 61 additions and 0 deletions

20
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Run Test
on:
pull_request:
branches:
- '*'
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Run test
run: ./run_test.sh

23
autoindent.vim Normal file
View File

@@ -0,0 +1,23 @@
if empty($OUTPUT_FILE)
echom "Error: Environment variable OUTPUT_FILE is not set."
cquit! 1
endif
set nocompatible
set runtimepath^=$PWD
filetype plugin indent on
syntax on
augroup swiftIndent
autocmd!
autocmd BufRead,BufNewFile *.swift setlocal shiftwidth=4 expandtab
augroup END
" Apply autoindent, save and quit.
function! s:RemoveWhitespaceAndReindent()
silent %s/^\s\+//
normal gg=G
execute 'write ' . fnameescape($OUTPUT_FILE)
quit!
endfunction
autocmd BufReadPost * call s:RemoveWhitespaceAndReindent()

18
run_test.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail
tempdir=$(mktemp -d)
trap cleanup EXIT
cleanup() {
rm -r "$tempdir"
}
for example_file in example/*.swift; do
autoindented_file="$tempdir/${example_file##*/}"
OUTPUT_FILE="$autoindented_file" vim -u autoindent.vim "$example_file"
diff -u --color=auto "$example_file" "$autoindented_file"
done
echo "test passed!"