From bfdbfa46b9ae39894fe32a88bcc8609b019d9d5d Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 5 Aug 2014 21:44:25 +0200 Subject: [PATCH] Add tests for updating plugins --- CHANGELOG.md | 1 + ...xpect_successful_update_of_a_single_plugin | 61 +++++++++++++++++ tests/expect_successful_update_of_all_plugins | 67 +++++++++++++++++++ tests/test_plugin_update.sh | 35 ++++++++++ 4 files changed, 164 insertions(+) create mode 100755 tests/expect_successful_update_of_a_single_plugin create mode 100755 tests/expect_successful_update_of_all_plugins create mode 100755 tests/test_plugin_update.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index d216607..230381c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - installing plugins installs just new plugins. Already installed plugins aren't updated. - add 'update plugin' binding and functionality +- add test for updating a plugin ### v0.0.2, 2014-07-17 - run all *.tmux plugin files as executables diff --git a/tests/expect_successful_update_of_a_single_plugin b/tests/expect_successful_update_of_a_single_plugin new file mode 100755 index 0000000..cfff332 --- /dev/null +++ b/tests/expect_successful_update_of_a_single_plugin @@ -0,0 +1,61 @@ +#!/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 + U +send "U" + +set timeout 5 + +expect { + "Installed plugins" { + + expect { + "\"tmux-example-plugin\"" { + + expect { + "\"all\" - updates all plugins" { + + expect { "ENTER - cancels" } + + } + } + + } + } + + } + + timeout { + puts "Plugin update prompt timeout"; + exit 1 + } +} + +send "tmux-example-plugin\r" + +expect { + "Updating \"tmux-example-plugin\"" { + + expect { + "\"tmux-example-plugin\" update success" { + + expect { "Done, press ENTER to continue." { exit 0 } } + + } + } + + } + + timeout { + puts "Update all plugins timeout"; + exit 1 + } +} diff --git a/tests/expect_successful_update_of_all_plugins b/tests/expect_successful_update_of_all_plugins new file mode 100755 index 0000000..4705edd --- /dev/null +++ b/tests/expect_successful_update_of_all_plugins @@ -0,0 +1,67 @@ +#!/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 + U +send "U" + +set timeout 5 + +expect { + "Installed plugins" { + + expect { + "\"tmux-example-plugin\"" { + + expect { + "\"all\" - updates all plugins" { + + expect { "ENTER - cancels" } + + } + } + + } + } + + } + + timeout { + puts "Plugin update prompt timeout"; + exit 1 + } +} + +send "all\r" + +expect { + "Updating all plugins!" { + + expect { + "Updating \"tmux-example-plugin\"" { + + expect { + "\"tmux-example-plugin\" update success" { + + expect { "Done, press ENTER to continue." { exit 0 } } + + } + } + + } + } + + } + + timeout { + puts "Update all plugins timeout"; + exit 1 + } +} diff --git a/tests/test_plugin_update.sh b/tests/test_plugin_update.sh new file mode 100755 index 0000000..c6eba96 --- /dev/null +++ b/tests/test_plugin_update.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source $CURRENT_DIR/helpers.sh + +manually_install_the_plugin() { + mkdir -p ~/.tmux/plugins/ + cd ~/.tmux/plugins/ + git clone --quiet https://github.com/tmux-plugins/tmux-example-plugin +} + +test_plugin_installation() { + set_tmux_conf_helper <<- HERE + set -g @tpm_plugins "tmux-plugins/tmux-example-plugin" + run-shell "~/tpm/tpm" + HERE + + manually_install_the_plugin + + # opens tmux and test it with `expect` + $CURRENT_DIR/expect_successful_update_of_all_plugins || + fail_helper "Tmux 'update all plugins' fails" + + $CURRENT_DIR/expect_successful_update_of_a_single_plugin || + fail_helper "Tmux 'update single plugin' fails" + + teardown_helper +} + +main() { + test_plugin_installation + exit_value_helper +} +main