This repository has been archived by the owner on Oct 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathecunit
executable file
·104 lines (83 loc) · 2.51 KB
/
ecunit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# ecunit: Editorconfig Vimscript core unit-testing script
# editorconfig: CLI
# Copyright (c) 2018 Chris White. CC-BY-SA 3.0+.
# Use a manually-specified Vim, if any
if [[ $VIM_EXE ]]; then
V="$VIM_EXE"
else
V="vim"
fi
# Get the directory of this script. From
# https://stackoverflow.com/a/246128/2877364 by
# https://stackoverflow.com/users/407731 et al.
DIR=
function get_dir()
{
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )"
}
get_dir
###
globpat=
initest=
extra_info=
while getopts 'f:g:i:x:' opt ; do
case "$opt" in
# TODO support -b[, -h?]
# Not in EditorConfig Core
(g) globpat="$OPTARG"
;;
(i) initest="$OPTARG"
;;
(x) extra_info="$OPTARG"
;;
esac
done
shift $(( $OPTIND - 1 ))
if (( "$#" < 2 )); then # Need dir and file
exit 1
fi
fn="$(mktemp)" # Output file
mesgfn="$(mktemp)" # for Vim messages
vim_args=()
if [[ $globpat ]]; then
vim_args+=(
-c "execute 'redir! > ${mesgfn//\'/\'\'}'"
-c "let g:editorconfig_core_vimscript_debug=1"
-c "echom 'Before call'"
-c "if editorconfig_core#fnmatch#fnmatch('${1//\'/\'\'}/${2//\'/\'\'}', '${1//\'/\'\'}/', '${globpat//\'/\'\'}') | quit! | else | cquit | endif"
-c "echom 'After call (should not get here)'"
-c 'q!'
)
[[ $extra_info ]] && echo "--- $extra_info ---" 1>&2
echo "Matching -${globpat}- against -${1}/${2}- in -${1}-" 1>&2
else
echo "not yet implemented" 1>&2
exit 1
fi
# Some extra debugging output to stderr - use ctest --output-on-failure
# to see it for failing tests.
echo Vim args: "${vim_args[@]}" 1>&2
# Run editorconfig. Thanks for options to
# http://vim.wikia.com/wiki/Vim_as_a_system_interpreter_for_vimscript .
# Add -V1 to the below for debugging output.
"$V" -nNes -i NONE -u NONE -U NONE \
-c "set runtimepath+=$DIR" \
"${vim_args[@]}" \
</dev/null
vimstatus="$?"
echo "Vim returned $vimstatus" 1>&2
if [[ $vimstatus -eq 0 ]]; then
cat "$fn"
fi
echo "Vim messages:" 1>&2
cat "$mesgfn" 1>&2
rm -f "$fn" "$mesgfn"
exit "$vimstatus"
# vi: set ft=sh: