-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial version of automated testing
- Loading branch information
Showing
6 changed files
with
275 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
sudo: required | ||
services: | ||
- docker | ||
language: generic | ||
script: | | ||
./run-tests |
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,14 @@ | ||
FROM tweekmonster/vim-testbed:latest | ||
|
||
RUN install_vim -tag v8.1.0519 -build | ||
|
||
ENV PACKAGES="bash git python py-pip" | ||
|
||
RUN apk --update add $PACKAGES \ | ||
&& rm -rf /var/cache/apk/* /tmp/* /var/tmp/* | ||
|
||
RUN pip install vim-vint==0.3.15 | ||
|
||
RUN git clone https://github.com/junegunn/vader.vim vader \ | ||
&& cd vader \ | ||
&& git checkout de8a976f1eae2c2b680604205c3e8b5c8882493c |
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,84 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker_image=kkoomen/doge | ||
current_docker_image_id=fb461f02e779 | ||
|
||
DOGE_DOCKER_IMAGE="$docker_image" | ||
export DOGE_DOCKER_IMAGE | ||
|
||
# Allow tests to be passed as arguments. | ||
if [ $# -ne 0 ]; then | ||
tests="$*" | ||
else | ||
tests='test/*.vader' | ||
fi | ||
|
||
# Delete .swp files in the test directory, which cause Vim 8 to hang. | ||
find test -name '*.swp' -delete | ||
|
||
docker images -q $DOGE_DOCKER_IMAGE | grep "^$current_docker_image_id" > /dev/null \ | ||
|| docker pull "$image" | ||
|
||
output_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir') | ||
|
||
# Used for killing tests when you kill the script. | ||
cancel_tests() { | ||
set +e | ||
|
||
if [ -n "$pid_list" ]; then | ||
for pid in $pid_list; do | ||
kill "$pid" | ||
wait "$pid" | ||
done | ||
fi | ||
|
||
docker kill $(docker ps -a -q --filter ancestor="$image" --format='{{.ID}}') &> /dev/null | ||
|
||
if [ -d "$output_dir" ]; then | ||
rm -rf "$output_dir" | ||
fi | ||
|
||
echo | ||
exit 1 | ||
} | ||
|
||
trap cancel_tests INT TERM | ||
|
||
file_number=0 | ||
pid_list='' | ||
for vim in $(docker run --rm "$DOGE_DOCKER_IMAGE" ls /vim-build/bin | grep '^vim'); do | ||
if [[ $vim =~ ^vim-v8.1 ]]; then | ||
echo "Starting Vim: $vim..." | ||
file_number=$((file_number+1)) | ||
echo "Dumping output in $output_dir/$file_number" | ||
scripts/run-vader-tests "$vim" "$tests" > "$output_dir/$file_number" 2>&1 & | ||
pid_list="$pid_list $!" | ||
fi | ||
done | ||
|
||
echo | ||
|
||
failed=0 | ||
index=0 | ||
|
||
for pid in $pid_list; do | ||
this_failed=0 | ||
index=$((index+1)) | ||
|
||
if ! wait "$pid"; then | ||
failed=1 | ||
this_failed=1 | ||
fi | ||
|
||
if [[ -f "$output_dir/$index" ]] || ((this_failed)); then | ||
cat "$output_dir/$index" | ||
fi | ||
done | ||
|
||
if ((failed)); then | ||
echo 'Something went wrong!' | ||
else | ||
echo 'All tests passed!' | ||
fi | ||
|
||
exit $failed |
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,107 @@ | ||
#!/usr/bin/env bash | ||
|
||
vim="$1" | ||
tests="$2" | ||
|
||
red='\033[0;31m' | ||
green='\033[0;32m' | ||
nc='\033[0m' | ||
|
||
run_file="$(mktemp -t tests_ran.XXXXXXXX)" | ||
|
||
function filter-vader-output() { | ||
local hit_first_vader_line=0 | ||
# When verbose mode is off, suppress output until Vader starts. | ||
local start_output="$verbose" | ||
local filtered_data='' | ||
|
||
while read -r; do | ||
# Search for the first Vader output line. | ||
# We can try starting tests again if they don't start. | ||
if ((!hit_first_vader_line)); then | ||
if [[ "$REPLY" = *'Starting Vader:'* ]]; then | ||
hit_first_vader_line=1 | ||
fi | ||
fi | ||
|
||
if ((!start_output)); then | ||
if ((hit_first_vader_line)); then | ||
start_output=1 | ||
else | ||
continue | ||
fi | ||
fi | ||
|
||
echo "$REPLY" | ||
done | ||
|
||
# Note that we managed to get the Vader tests started if we did. | ||
if ((hit_first_vader_line)); then | ||
echo 1 > "$run_file" | ||
fi | ||
} | ||
|
||
function color-vader-output() { | ||
while read -r; do | ||
if [[ "$REPLY" = *'[EXECUTE] (X)'* ]]; then | ||
echo -en "$red" | ||
elif [[ "$REPLY" = *'[EXECUTE]'* ]] || [[ "$REPLY" = *'[ GIVEN]'* ]]; then | ||
echo -en "$nc" | ||
fi | ||
|
||
if [[ "$REPLY" = *'Success/Total'* ]]; then | ||
success="$(echo -n "$REPLY" | grep -o '[0-9]\+/' | head -n1 | cut -d/ -f1)" | ||
total="$(echo -n "$REPLY" | grep -o '/[0-9]\+' | head -n1 | cut -d/ -f2)" | ||
|
||
if [ "$success" -lt "$total" ]; then | ||
echo -en "$red" | ||
else | ||
echo -en "$green" | ||
fi | ||
|
||
echo "$REPLY" | ||
echo -en "$nc" | ||
else | ||
echo "$REPLY" | ||
fi | ||
done | ||
|
||
echo -en "$nc" | ||
} | ||
|
||
echo | ||
echo '========================================' | ||
echo "Running tests for $vim" | ||
echo '========================================' | ||
echo | ||
|
||
tries=0 | ||
|
||
while [ "$tries" -lt 5 ]; do | ||
tries=$((tries + 1)) | ||
|
||
exit_code=0 | ||
set -o pipefail | ||
docker run \ | ||
-a stderr \ | ||
-e VADER_OUTPUT_FILE=/dev/stderr \ | ||
--rm \ | ||
-v "$PWD:/testplugin" \ | ||
-v "$PWD/test:/home" \ | ||
-w /testplugin "$DOGE_DOCKER_IMAGE" "/vim-build/bin/$vim" \ | ||
-u test/vimrc "+Vader! $tests" 2>&1 | filter-vader-output | color-vader-output || exit_code=$? | ||
set +o pipefail | ||
|
||
if [ -s "$run_file" ]; then | ||
break | ||
fi | ||
done | ||
|
||
if [ "$tries" -gt 1 ]; then | ||
echo | ||
echo "Tried to run tests $tries times" | ||
fi | ||
|
||
rm "$run_file" | ||
|
||
exit "$exit_code" |
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,34 @@ | ||
################# | ||
# Typical comment | ||
################# | ||
|
||
Given (fixture): | ||
================ | ||
Hello | ||
|
||
Do (modification): | ||
------------------ | ||
* change inner word | ||
ciw | ||
* to | ||
World | ||
|
||
Expect (result): | ||
~~~~~~~~~~~~~~~~ | ||
World | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Do (another modification): | ||
-------------------------- | ||
^ change inner word | ||
ciw | ||
^ to | ||
Goodbye | ||
|
||
Expect (invalid result): | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Goodbye | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Remove Given block | ||
Given: |
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,29 @@ | ||
" vint: -ProhibitSetNoCompatible | ||
|
||
" Load builtin plugins | ||
" We need this because run_vim.sh sets -i NONE | ||
if has('win32') | ||
set runtimepath=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,C:\vader,C:\testplugin | ||
else | ||
set runtimepath=/home/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,/testplugin,/vader | ||
endif | ||
|
||
" The following is just an example | ||
filetype plugin indent on | ||
syntax on | ||
|
||
if !has('win32') | ||
set shell=/bin/sh | ||
set shellcmdflag=-c | ||
endif | ||
|
||
set nocompatible | ||
set tabstop=4 | ||
set softtabstop=4 | ||
set shiftwidth=4 | ||
set expandtab | ||
set backspace=2 | ||
set ttimeoutlen=0 | ||
|
||
" The encoding must be explicitly set for tests for Windows. | ||
execute 'set encoding=utf-8' |