Change testing directory structure

This commit is contained in:
Bruno Sutic
2014-07-17 22:51:07 +02:00
parent 9887bbe411
commit b92d086853
8 changed files with 3 additions and 20 deletions

View File

@ -0,0 +1,35 @@
#!/usr/bin/env expect
# disables script output
log_user 0
spawn tmux
# Waiting for tmux to attach. If this is not done, next command, `send` will
# not work properly.
sleep 1
# this is tmux prefix + I
send "I"
# cloning might take a while
set timeout 15
expect {
"Downloading bruno-/tmux_example_plugin" {
expect {
"bruno-/tmux_example_plugin download success" {
expect { "Done, press ENTER to continue" { exit } }
}
}
}
timeout {
puts "Plugin update timeout";
exit 1
}
}

55
tests/helpers.sh Normal file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env bash
FAIL="false"
set_tmux_conf_helper() {
> ~/.tmux.conf # empty filename
while read -r line; do
echo $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
while read -r line; do
echo $line >> "$plugin_path/test_plugin.tmux"
done
chmod +x "$plugin_path/test_plugin.tmux"
}
teardown_helper() {
rm ~/.tmux.conf
rm -rf ~/.tmux/
tmux kill-server >/dev/null 2>&1
}
check_dir_exists_helper() {
local dir_path=$1
if [ -d "$dir_path" ]; then
return 0
else
return 1
fi
}
fail_helper() {
local message="$1"
echo "$message" >&2
FAIL="true"
}
exit_value_helper() {
local fail="$1"
if [ "$FAIL" == "true" ]; then
echo "FAIL!"
echo
exit 1
else
echo "SUCCESS"
echo
exit 0
fi
}

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/helpers.sh
test_plugin_installation() {
set_tmux_conf_helper <<- HERE
set -g @tpm_plugins "bruno-/tmux_example_plugin"
run-shell "~/tpm/tpm"
HERE
# opens tmux and test it with `expect`
$CURRENT_DIR/expect_successful_plugin_download ||
fail_helper "Tmux plugin installation fails"
# check plugin dir exists after download
check_dir_exists_helper "$HOME/.tmux/plugins/tmux_example_plugin/" ||
fail_helper "Plugin download fails"
teardown_helper
}
main() {
test_plugin_installation
exit_value_helper
}
main

34
tests/test_plugin_sourcing.sh Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/helpers.sh
check_binding_defined() {
local binding="$1"
tmux list-keys | grep -q "$binding"
}
test_plugin_sourcing() {
set_tmux_conf_helper <<- HERE
set -g @tpm_plugins "doesnt_matter/tmux_test_plugin"
run-shell "~/tpm/tpm"
HERE
# manually creates a local tmux plugin
create_test_plugin_helper <<- HERE
tmux bind-key R run-shell foo_command
HERE
tmux new-session -d # tmux starts detached
check_binding_defined "R run-shell foo_command" ||
fail_helper "Plugin sourcing fails"
teardown_helper
}
main() {
test_plugin_sourcing
exit_value_helper
}
main