2014-05-24 09:38:41 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2014-07-17 16:16:46 -04:00
|
|
|
FAIL="false"
|
2014-07-17 15:12:28 -04:00
|
|
|
|
2014-05-24 09:38:41 -04:00
|
|
|
set_tmux_conf_helper() {
|
2014-05-24 17:18:37 -04:00
|
|
|
> ~/.tmux.conf # empty filename
|
2015-07-31 19:07:04 -04:00
|
|
|
while read line; do
|
|
|
|
echo "$line" >> ~/.tmux.conf
|
2014-05-24 17:18:37 -04:00
|
|
|
done
|
2014-05-24 09:38:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
create_test_plugin_helper() {
|
2014-05-24 17:18:37 -04:00
|
|
|
local plugin_path="$HOME/.tmux/plugins/tmux_test_plugin/"
|
|
|
|
rm -rf $plugin_path
|
|
|
|
mkdir -p $plugin_path
|
2014-05-24 09:38:41 -04:00
|
|
|
|
2014-05-24 17:18:37 -04:00
|
|
|
while read -r line; do
|
|
|
|
echo $line >> "$plugin_path/test_plugin.tmux"
|
|
|
|
done
|
|
|
|
chmod +x "$plugin_path/test_plugin.tmux"
|
2014-05-24 09:38:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown_helper() {
|
2014-05-24 17:18:37 -04:00
|
|
|
rm ~/.tmux.conf
|
|
|
|
rm -rf ~/.tmux/
|
|
|
|
tmux kill-server >/dev/null 2>&1
|
2014-05-24 09:38:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
check_dir_exists_helper() {
|
2014-05-24 17:18:37 -04:00
|
|
|
local dir_path=$1
|
|
|
|
if [ -d "$dir_path" ]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2014-05-24 09:38:41 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 19:46:35 -04:00
|
|
|
# runs the scripts and asserts it has the correct output and exit code
|
|
|
|
script_run_helper() {
|
|
|
|
local script="$1"
|
|
|
|
local expected_output="$2"
|
|
|
|
local expected_exit_code="${3:-0}"
|
|
|
|
"$script" |
|
|
|
|
grep "$expected_output" >/dev/null 2>&1 && # grep -q flag quits the script early
|
|
|
|
[ "${PIPESTATUS[0]}" -eq "$expected_exit_code" ]
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:16:46 -04:00
|
|
|
fail_helper() {
|
|
|
|
local message="$1"
|
2014-07-17 16:51:07 -04:00
|
|
|
echo "$message" >&2
|
2014-07-17 16:16:46 -04:00
|
|
|
FAIL="true"
|
2014-07-17 15:12:28 -04:00
|
|
|
}
|
|
|
|
|
2014-05-24 09:38:41 -04:00
|
|
|
exit_value_helper() {
|
2014-07-17 16:16:46 -04:00
|
|
|
local fail="$1"
|
|
|
|
if [ "$FAIL" == "true" ]; then
|
2014-07-17 16:36:09 -04:00
|
|
|
echo "FAIL!"
|
2014-05-24 17:18:37 -04:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
else
|
2014-07-17 16:36:09 -04:00
|
|
|
echo "SUCCESS"
|
2014-05-24 17:18:37 -04:00
|
|
|
echo
|
|
|
|
exit 0
|
|
|
|
fi
|
2014-05-24 09:38:41 -04:00
|
|
|
}
|
2015-08-01 12:06:19 -04:00
|
|
|
|
|
|
|
run_tests() {
|
|
|
|
# get all the functions starting with 'test_' and invoke them
|
|
|
|
for test in $(compgen -A function | grep "^test_"); do
|
|
|
|
"$test"
|
|
|
|
done
|
|
|
|
exit_value_helper
|
|
|
|
}
|