tests/: bash -> sh

This commit is contained in:
Javier Lopez 2015-05-18 15:41:04 -05:00
parent 9251451554
commit 0aa5163545
5 changed files with 111 additions and 33 deletions

View File

@ -1,21 +1,50 @@
#!/usr/bin/env bash
#!/bin/sh
FAIL="false"
mkdir_p()
{ #portable mkdir -p function
local dir subdir
for dir; do
mkdir_p__IFS="$IFS"
IFS="/"
set -- $dir
IFS="$mkdir_p__IFS"
(
case "$dir" in
/*) cd /; shift ;;
esac
for subdir; do
[ -z "${subdir}" ] && continue
if [ -d "${subdir}" ] || mkdir "${subdir}"; then
if cd "${subdir}"; then
:
else
printf "%s\\n" "mkdir_p: Can't enter ${subdir} while creating ${dir}"
exit 1
fi
else
exit 1
fi
done
)
done
}
set_tmux_conf_helper() {
> ~/.tmux.conf # empty filename
while read -r line; do
echo $line >> ~/.tmux.conf
printf "%s\\n" "${line}" >> ~/.tmux.conf
done
}
create_test_plugin_helper() {
local plugin_path="$HOME/.tmux/plugins/tmux_test_plugin/"
rm -rf $plugin_path
mkdir -p $plugin_path
rm -rf "$plugin_path"
mkdir_p "$plugin_path"
while read -r line; do
echo $line >> "$plugin_path/test_plugin.tmux"
printf "%s\\n" "$line" >> "$plugin_path/test_plugin.tmux"
done
chmod +x "$plugin_path/test_plugin.tmux"
}
@ -37,19 +66,19 @@ check_dir_exists_helper() {
fail_helper() {
local message="$1"
echo "$message" >&2
printf "%s\\n" "$message" >&2
FAIL="true"
}
exit_value_helper() {
local fail="$1"
if [ "$FAIL" == "true" ]; then
echo "FAIL!"
echo
if [ "$FAIL" = "true" ]; then
printf "%s\\n" "FAIL!"
printf "\\n"
exit 1
else
echo "SUCCESS"
echo
printf "%s\\n" "SUCCESS"
printf "\\n"
exit 0
fi
}

View File

@ -1,34 +1,47 @@
#!/usr/bin/env bash
#!/bin/sh
# A test runner file.
# Intended to be run from `./run-tests` script *within* a virtual machine.
# DO NOT run it locally as it might overwrite your `.tmux.conf` (that's what it
# does during the tests).
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_dirname()
{ #portable dirname
[ -z "${1}" ] && return 1
#http://www.linuxselfhelp.com/gnu/autoconf/html_chapter/autoconf_10.html
case "${1}" in
/*|*/*) local dir; dir=$(expr "x${1}" : 'x\(.*\)/[^/]*' \| '.' : '.')
printf "%s\\n" "${dir}" ;;
*) printf "%s\\n" ".";;
esac
}
CURRENT_DIR="$( cd "$( _dirname "$0" )" && pwd )"
# running test suite is successful by default
tests_exit_value=0
tests_exit_value="0"
set_global_exit_val_to_false() {
tests_exit_value=1
tests_exit_value="1"
}
test_files() {
ls -1 "$CURRENT_DIR" | # test files are in the current dir
ls -1 "$CURRENT_DIR" | # test files are in the current dir
grep -i '^test' | # test file names start with 'test'
xargs # file names in one line
}
run_tests() {
local test_file
for test_file in $(test_files); do
echo "Running test: $test_file"
$CURRENT_DIR/$test_file
for test_file in "$CURRENT_DIR"/test*; do
[ -f "${test_file}" ] || continue
printf "%s\\n" "Running test: ${test_file##*/}"
"$test_file"
# handling exit value
local exit_value="$?"
if [ "$exit_value" != 0 ]; then
if [ "$exit_value" != "0" ]; then
set_global_exit_val_to_false
fi
done

View File

@ -1,8 +1,20 @@
#!/usr/bin/env bash
#!/bin/sh
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_dirname()
{ #portable dirname
[ -z "${1}" ] && return 1
source $CURRENT_DIR/helpers.sh
#http://www.linuxselfhelp.com/gnu/autoconf/html_chapter/autoconf_10.html
case "${1}" in
/*|*/*) local dir; dir=$(expr "x${1}" : 'x\(.*\)/[^/]*' \| '.' : '.')
printf "%s\\n" "${dir}" ;;
*) printf "%s\\n" ".";;
esac
}
CURRENT_DIR="$( cd "$( _dirname "$0" )" && pwd )"
. "$CURRENT_DIR"/helpers.sh
test_plugin_installation() {
set_tmux_conf_helper <<- HERE
@ -11,7 +23,7 @@ test_plugin_installation() {
HERE
# opens tmux and test it with `expect`
$CURRENT_DIR/expect_successful_plugin_download ||
"$CURRENT_DIR"/expect_successful_plugin_download ||
fail_helper "Tmux plugin installation fails"
# check plugin dir exists after download

View File

@ -1,8 +1,20 @@
#!/usr/bin/env bash
#!/bin/sh
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_dirname()
{ #portable dirname
[ -z "${1}" ] && return 1
source $CURRENT_DIR/helpers.sh
#http://www.linuxselfhelp.com/gnu/autoconf/html_chapter/autoconf_10.html
case "${1}" in
/*|*/*) local dir; dir=$(expr "x${1}" : 'x\(.*\)/[^/]*' \| '.' : '.')
printf "%s\\n" "${dir}" ;;
*) printf "%s\\n" ".";;
esac
}
CURRENT_DIR="$( cd "$( _dirname "$0" )" && pwd )"
. "$CURRENT_DIR"/helpers.sh
check_binding_defined() {
local binding="$1"

View File

@ -1,11 +1,23 @@
#!/usr/bin/env bash
#!/bin/sh
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
_dirname()
{ #portable dirname
[ -z "${1}" ] && return 1
source $CURRENT_DIR/helpers.sh
#http://www.linuxselfhelp.com/gnu/autoconf/html_chapter/autoconf_10.html
case "${1}" in
/*|*/*) local dir; dir=$(expr "x${1}" : 'x\(.*\)/[^/]*' \| '.' : '.')
printf "%s\\n" "${dir}" ;;
*) printf "%s\\n" ".";;
esac
}
CURRENT_DIR="$( cd "$( _dirname "$0" )" && pwd )"
. "$CURRENT_DIR"/helpers.sh
manually_install_the_plugin() {
mkdir -p ~/.tmux/plugins/
mkdir_p ~/.tmux/plugins/
cd ~/.tmux/plugins/
git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin
}
@ -19,10 +31,10 @@ test_plugin_installation() {
manually_install_the_plugin
# opens tmux and test it with `expect`
$CURRENT_DIR/expect_successful_update_of_all_plugins ||
"$CURRENT_DIR"/expect_successful_update_of_all_plugins ||
fail_helper "Tmux 'update all plugins' fails"
$CURRENT_DIR/expect_successful_update_of_a_single_plugin ||
"$CURRENT_DIR"/expect_successful_update_of_a_single_plugin ||
fail_helper "Tmux 'update single plugin' fails"
teardown_helper