]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/script/run-vader-tests

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / script / run-vader-tests
1 #!/usr/bin/env bash
2
3 set -e
4 set -u
5
6 docker_flags=(--rm -v "$PWD:/testplugin" -v "$PWD/test:/home" -w /testplugin "$DOCKER_RUN_IMAGE")
7 red='\033[0;31m'
8 green='\033[0;32m'
9 nc='\033[0m'
10 verbose=0
11 quiet=0
12
13 while [ $# -ne 0 ]; do
14     case $1 in
15     -v)
16         verbose=1
17         shift
18     ;;
19     -q)
20         quiet=1
21         shift
22     ;;
23     --)
24         shift
25         break
26     ;;
27     -?*)
28         echo "Invalid argument: $1" 1>&2
29         exit 1
30     ;;
31     *)
32         break
33     ;;
34     esac
35 done
36
37 vim="$1"
38 tests="$2"
39
40 echo "$vim"
41
42 case $vim in
43     # Neovim 0.6+ requires headless argument to load Vader tests.
44     neovim*)
45         headless='--headless'
46     ;;
47     *)
48         headless=''
49     ;;
50 esac
51
52 # This file will be used to track if tests ran or not.
53 # We can't use a variable, because we need to set a value in a sub-shell.
54 run_file="$(mktemp -t tests_ran.XXXXXXXX)"
55
56 function filter-vader-output() {
57     local hit_first_vader_line=0
58     # When verbose mode is off, suppress output until Vader starts.
59     local start_output="$verbose"
60     local filtered_data=''
61
62     while read -r; do
63         # Search for the first Vader output line.
64         # We can try starting tests again if they don't start.
65         if ((!hit_first_vader_line)); then
66             if [[ "$REPLY" = *'Starting Vader:'* ]]; then
67                 hit_first_vader_line=1
68             fi
69         fi
70
71         if ((!start_output)); then
72             if ((hit_first_vader_line)); then
73                 start_output=1
74             else
75                 continue
76             fi
77         fi
78
79         if ((quiet)); then
80             if [[ "$REPLY" = *'Starting Vader:'* ]]; then
81                 filtered_data="$REPLY"
82             elif [[ "$REPLY" = *'Success/Total'* ]]; then
83                 success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
84                 total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"
85
86                 if [ "$success" -lt "$total" ]; then
87                     echo "$filtered_data"
88                     echo "$REPLY"
89                 fi
90
91                 filtered_data=''
92             else
93                 filtered_data="$filtered_data"$'\n'"$REPLY"
94             fi
95         else
96             echo "$REPLY"
97         fi
98     done
99
100     # Note that we managed to get the Vader tests started if we did.
101     if ((hit_first_vader_line)); then
102         echo 1 > "$run_file"
103     fi
104 }
105
106 function color-vader-output() {
107     while read -r; do
108         if [[ "$REPLY" = *'[EXECUTE] (X)'* ]]; then
109             echo -en "$red"
110         elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[  GIVEN]'* ]]; then
111             echo -en "$nc"
112         fi
113
114         if [[ "$REPLY" = *'Success/Total'* ]]; then
115             success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)"
116             total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)"
117
118             if [ "$success" -lt "$total" ]; then
119                 echo -en "$red"
120             else
121                 echo -en "$green"
122             fi
123
124             echo "$REPLY"
125             echo -en "$nc"
126         else
127             echo "$REPLY"
128         fi
129     done
130
131     echo -en "$nc"
132 }
133
134 echo
135 echo '========================================'
136 echo "Running tests for $vim"
137 echo '========================================'
138 echo
139
140 tries=0
141
142 while [ "$tries" -lt 5 ]; do
143     tries=$((tries + 1))
144
145     exit_code=0
146     set -o pipefail
147     # shellcheck disable=SC2086
148     "$DOCKER" run -a stderr -e VADER_OUTPUT_FILE=/dev/stderr "${docker_flags[@]}" \
149         "/vim-build/bin/$vim" -u test/vimrc ${headless} \
150         "+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || exit_code=$?
151     set +o pipefail
152
153     if [ -s "$run_file" ]; then
154         break
155     fi
156 done
157
158 if [ "$tries" -gt 1 ]; then
159     echo
160     echo "Tried to run tests $tries times"
161 fi
162
163 rm "$run_file"
164
165 exit "$exit_code"