Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# vim: ft=sh | ||
|
||
# Set up tmpdir | ||
tmpdir=$(mktemp -d -p "${TMPDIR:-/tmp}" testing.vim.XXXXXXX) | ||
mkdir -p "$tmpdir" | ||
trap 'rm -r "$tmpdir"' EXIT | ||
|
||
# Find files. | ||
find_files() { | ||
local target=$1 | ||
local pattern=$2 | ||
|
||
# Find files to test. | ||
if echo "$target" | grep -q '/\.\.\.$'; then | ||
find_path="${target%...}" | ||
find_args="-name $pattern" | ||
elif [ -e "$target" ]; then | ||
find_path="${target}" | ||
find_args="-maxdepth 1 -name $pattern" | ||
else | ||
>&2 echo "no such file or directory: $target" | ||
exit 1 | ||
fi | ||
|
||
set -f | ||
# shellcheck disable=SC2086 | ||
files=$(find "$find_path" $find_args) | ||
set +f | ||
|
||
if [ "$files" = "" ]; then | ||
>&2 echo "no $pattern files in $target" | ||
exit 3 | ||
fi | ||
|
||
if [ $(link_pack $files) -gt 0 ]; then | ||
>&2 echo "could not locate the plugin directory for $files" | ||
exit 2 | ||
fi | ||
|
||
echo $files | ||
} | ||
|
||
# Set up package; find the plugin's root directory and make sure that the plugin | ||
# we're testing is available as a package in $tmpdir. | ||
link_pack() { | ||
mkdir -p "$tmpdir/pack/t/start" | ||
|
||
IFS=" | ||
" | ||
for f in "$@"; do | ||
local f="${f#./}" | ||
local dir=$(dirname "$f") | ||
|
||
local pack="$(cd "$dir" && pwd)" | ||
while :; do | ||
if [ "$pack" = "/" ]; then | ||
printf 1 | ||
return | ||
fi | ||
|
||
if [ -d "$pack/autoload" ] || [ -d "$pack/plugin" ] || [ -d "$pack/ftplugin" ]; then | ||
ln -s "$pack" "$tmpdir/pack/t/start" | ||
printf 0 | ||
return | ||
fi | ||
|
||
pack="$(dirname "$pack")" | ||
done | ||
done | ||
|
||
printf 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
fun! ListAllSyntax() | ||
let l:out = [] | ||
|
||
for l:line in range(1, line('$')) | ||
let l:outline = [] | ||
let l:prevgroup = '' | ||
let l:linelen = len(getline(l:line)) | ||
for l:col in range(1, l:linelen) | ||
let l:group = synIDattr(synID(l:line, l:col, 1), 'name') | ||
|
||
if l:prevgroup is# '' && l:group isnot# '' | ||
call add(l:outline, [l:group, l:col, -1]) | ||
elseif l:group isnot# l:prevgroup || (l:col is l:linelen && l:prevgroup isnot# '') | ||
let l:outline[len(l:outline) - 1][2] = l:col | ||
endif | ||
|
||
let l:prevgroup = l:group | ||
endfor | ||
|
||
call add(l:out, l:outline) | ||
endfor | ||
|
||
return l:out | ||
endfun | ||
|
||
fun! TestSyntax(file, want) abort | ||
syntax on | ||
exe 'e ' . fnameescape(a:file) | ||
|
||
let l:want = a:want | ||
let l:out = ListAllSyntax() | ||
|
||
if len(l:out) != len(l:want) | ||
call Errorf("out has different line length (%d, want %d)\nout: %s", | ||
\ len(l:out), len(l:want), l:out) | ||
return | ||
endif | ||
|
||
for l:i in range(0, len(l:out) - 1) | ||
if l:out[l:i] != l:want[l:i] | ||
call Errorf("line %d wrong\nwant: %s\nout: %s", l:i, l:want[l:i], l:out[l:i]) | ||
endif | ||
endfor | ||
endfun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
" vint: -ProhibitSetNoCompatible | ||
set nocompatible nomore shellslash encoding=utf-8 shortmess+=WIF | ||
lang mess C | ||
|
||
filetype plugin indent on | ||
syntax on | ||
|
||
let s:path = fnamemodify(bufname(''), ':.') | ||
let s:fname = fnamemodify(bufname(''), ':t:r') | ||
let s:lines = ListAllSyntax() | ||
|
||
silent! exe printf('split %s/syntax.tmp', fnameescape(g:test_tmpdir)) | ||
call append('$', [ | ||
\ '', | ||
\ printf('fun! Test_%s() abort', s:fname), | ||
\ printf(' call TestSyntax(g:test_packdir . "/%s",', s:path), | ||
\ ' \ [', | ||
\ ]) | ||
|
||
for s:line in s:lines | ||
call append('$', printf(' \ %s,', s:line)) | ||
endfor | ||
call append('$', [' \ ])', 'endfun']) | ||
|
||
silent! write | ||
qa! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/sh | ||
|
||
set -euC | ||
testingdir=$(cd -P "$(dirname "$0")" >/dev/null && pwd) | ||
|
||
. "$testingdir/shared" | ||
|
||
if [ -z "${1:-}" ]; then | ||
>&2 echo "Must give at least one test file" | ||
exit 1 | ||
fi | ||
|
||
if [ $(link_pack "$@") -gt 0 ]; then | ||
>&2 echo "could not locate the plugin directory for $files" | ||
exit 2 | ||
fi | ||
|
||
for f in "$@"; do | ||
vim --noplugin -u NONE -N -e \ | ||
+"set shm+=WAFI rtp^=$testingdir packpath=$tmpdir" \ | ||
+'filetype plugin indent on' \ | ||
+'packloadall!' \ | ||
+"silent e $f" \ | ||
+"let g:test_tmpdir='$tmpdir'" \ | ||
-S "$testingdir/syntax.vim" \ | ||
-S "$testingdir/syntaxtest.vim" >/dev/null </dev/null | ||
done | ||
|
||
printf '" This file is automatically generated by test-syntax from testing.vim' | ||
|
||
cat "$tmpdir/syntax.tmp" |