From 9cabda7c719f5445a46572e8e6408195d9842def Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Sun, 22 Feb 2015 21:53:33 +0100 Subject: [PATCH] Resurrect restore test and updates --- tests/fixtures/restore_file.txt | 21 ++++++++++++ tests/helpers/expect_helpers.exp | 10 ++++++ ...restore_and_save_tmux_test_environment.exp | 18 +++++++++++ tests/helpers/resurrect_helpers.sh | 8 ++++- tests/test_resurrect_restore.sh | 32 +++++++++++++++++++ tests/test_resurrect_save.sh | 14 +++----- 6 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 tests/fixtures/restore_file.txt create mode 100755 tests/helpers/restore_and_save_tmux_test_environment.exp create mode 100755 tests/test_resurrect_restore.sh diff --git a/tests/fixtures/restore_file.txt b/tests/fixtures/restore_file.txt new file mode 100644 index 0000000..74bd240 --- /dev/null +++ b/tests/fixtures/restore_file.txt @@ -0,0 +1,21 @@ +pane 0 0 :bash 1 :* 0 :/tmp 1 bash : +pane blue 0 :vim 0 : 0 :/tmp 1 vim :vim foo.txt +pane blue 1 :man 0 :- 0 :/tmp 0 bash : +pane blue 1 :man 0 :- 1 :/usr/share/man 1 man :man echo +pane blue 2 :bash 1 :* 0 :/tmp 1 bash : +pane red 0 :bash 0 : 0 :/tmp 1 bash : +pane red 1 :bash 0 :- 0 :/tmp 0 bash : +pane red 1 :bash 0 :- 1 :/tmp 0 bash : +pane red 1 :bash 0 :- 2 :/tmp 1 bash : +pane red 2 :bash 1 :* 0 :/tmp 0 bash : +pane red 2 :bash 1 :* 1 :/tmp 1 bash : +pane yellow 0 :bash 1 :* 0 :/tmp/bar 1 bash : +window 0 0 1 :* ce9e,200x49,0,0,1 +window blue 0 0 : ce9f,200x49,0,0,2 +window blue 1 0 :- 178b,200x49,0,0{100x49,0,0,3,99x49,101,0,4} +window blue 2 1 :* cea2,200x49,0,0,5 +window red 0 0 : cea3,200x49,0,0,6 +window red 1 0 :- 135b,200x49,0,0[200x24,0,0,7,200x24,0,25{100x24,0,25,8,99x24,101,25,9}] +window red 2 1 :* db81,200x49,0,0[200x24,0,0,10,200x24,0,25,11] +window yellow 0 1 :* 6781,200x49,0,0,12 +state yellow blue diff --git a/tests/helpers/expect_helpers.exp b/tests/helpers/expect_helpers.exp index 65692ec..6980428 100644 --- a/tests/helpers/expect_helpers.exp +++ b/tests/helpers/expect_helpers.exp @@ -53,3 +53,13 @@ proc start_resurrect_save {} { send "" sleep 5 } + +proc start_resurrect_restore {} { + send "" + sleep 10 +} + +proc clear_screen_for_window {target} { + send "tmux send-keys -t $target C-l\r" + sleep 0.2 +} diff --git a/tests/helpers/restore_and_save_tmux_test_environment.exp b/tests/helpers/restore_and_save_tmux_test_environment.exp new file mode 100755 index 0000000..82da37f --- /dev/null +++ b/tests/helpers/restore_and_save_tmux_test_environment.exp @@ -0,0 +1,18 @@ +#!/usr/bin/env expect + +source "./tests/helpers/expect_helpers.exp" + +expect_setup + +spawn tmux +# delay with sleep to compensate for tmux starting time +sleep 1 + +start_resurrect_restore + +# delete all existing resurrect save files +run_shell_command "rm ~/.tmux/resurrect/*" + +start_resurrect_save + +run_shell_command "tmux kill-server" diff --git a/tests/helpers/resurrect_helpers.sh b/tests/helpers/resurrect_helpers.sh index bd46116..fba4642 100644 --- a/tests/helpers/resurrect_helpers.sh +++ b/tests/helpers/resurrect_helpers.sh @@ -6,7 +6,13 @@ install_tmux_resurrect_helper() { } # we want "fixed" dimensions no matter the size of real display -set_screen_dimensions() { +set_screen_dimensions_helper() { stty cols 200 stty rows 50 } + +last_save_file_differs_helper() { + local original_file="$1" + diff "$original_file" "${HOME}/.tmux/resurrect/last" + [ $? -ne 0 ] +} diff --git a/tests/test_resurrect_restore.sh b/tests/test_resurrect_restore.sh new file mode 100755 index 0000000..8a1dad2 --- /dev/null +++ b/tests/test_resurrect_restore.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source $CURRENT_DIR/helpers/helpers.sh +source $CURRENT_DIR/helpers/resurrect_helpers.sh + +setup_file_for_restore() { + mkdir -p ~/.tmux/resurrect/ + cp tests/fixtures/restore_file.txt "${HOME}/.tmux/resurrect/restore_file.txt" + ln -sf restore_file.txt "${HOME}/.tmux/resurrect/last" +} + +restore_tmux_environment_and_save_again() { + set_tmux_conf_helper<<-HERE + run-shell '~/.tmux/plugins/tmux-resurrect/resurrect.tmux' + HERE + set_screen_dimensions_helper + $CURRENT_DIR/helpers/restore_and_save_tmux_test_environment.exp +} + +main() { + install_tmux_resurrect_helper + setup_file_for_restore + restore_tmux_environment_and_save_again + + if last_save_file_differs_helper "tests/fixtures/restore_file.txt"; then + fail_helper "Saved file not correct after restore" + fi + exit_helper +} +main diff --git a/tests/test_resurrect_save.sh b/tests/test_resurrect_save.sh index 5c7e697..dad344e 100755 --- a/tests/test_resurrect_save.sh +++ b/tests/test_resurrect_save.sh @@ -9,22 +9,16 @@ create_tmux_test_environment_and_save() { set_tmux_conf_helper<<-HERE run-shell '~/.tmux/plugins/tmux-resurrect/resurrect.tmux' HERE - - set_screen_dimensions + set_screen_dimensions_helper $CURRENT_DIR/helpers/create_and_save_tmux_test_environment.exp } -last_save_file_incorrect() { - diff tests/fixtures/save_file.txt "${HOME}/.tmux/resurrect/last" - [ $? -ne 0 ] -} - main() { install_tmux_resurrect_helper create_tmux_test_environment_and_save - if last_save_file_incorrect; then - fail_helper "Saved file not correct" - exit_helper + + if last_save_file_differs_helper "tests/fixtures/save_file.txt"; then + fail_helper "Saved file not correct (initial save)" fi exit_helper }