First version of tests

This commit is contained in:
Bruno Sutic
2014-05-24 15:38:41 +02:00
parent 2e8f2aa0cd
commit 45cd3d40fa
9 changed files with 243 additions and 0 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
}
}

46
test/tests/helpers.sh Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
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
}
exit_value_helper() {
if $FAIL; then
echo
echo "Test failed"
exit 1
else
echo
echo "Test finished successfully"
exit 0
fi
}

View File

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

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/helpers.sh
FAIL=false
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"
# change this
run-shell '~/tmux_plugin_manager/tpm'
HERE
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' ||
(echo "Plugin sourcing fails" >&2; FAIL=true)
teardown_helper
}
main() {
test_plugin_sourcing
exit_value_helper
}
main