Resurrect restore test and updates

This commit is contained in:
Bruno Sutic 2015-02-22 21:53:33 +01:00
parent 66916085d9
commit 9cabda7c71
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
6 changed files with 92 additions and 11 deletions

21
tests/fixtures/restore_file.txt vendored Normal file
View File

@ -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

View File

@ -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
}

View File

@ -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"

View File

@ -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 ]
}

32
tests/test_resurrect_restore.sh Executable file
View File

@ -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

View File

@ -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
}