rewrite specs in bash
This commit is contained in:
parent
695bbc7b3e
commit
665be3ad58
|
@ -1,4 +1,3 @@
|
|||
set -g prefix C-a
|
||||
set -g @fingers-compact-hints '0'
|
||||
set-option -g default-shell "/usr/bin/fish"
|
||||
run /home/vagrant/shared/tmux-fingers.tmux
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
set -g prefix F12
|
||||
set -g status off
|
||||
set-window-option -g force-width 80
|
||||
set-window-option -g force-height 24
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# this assumes tmuxomatic has been already sourced
|
||||
TMUX_PREFIX=C-a
|
||||
|
||||
function test_clean_up() {
|
||||
tmuxomatic__exec "tmux kill-session -t test"
|
||||
}
|
||||
|
||||
function tmux_send() {
|
||||
local key=$1
|
||||
sleep 0.5
|
||||
tmuxomatic send-keys "$TMUX_PREFIX"
|
||||
sleep 0.5
|
||||
tmuxomatic send-keys "$key"
|
||||
sleep 0.5
|
||||
}
|
||||
|
||||
function tmux_paste() {
|
||||
tmux_send "]"
|
||||
}
|
||||
|
||||
function init_pane() {
|
||||
tmux_send "c"
|
||||
tmuxomatic__exec "export PS1='# '; clear"
|
||||
}
|
||||
|
||||
function init_pane_fish() {
|
||||
tmux_send "c"
|
||||
tmuxomatic__exec "function fish_prompt; echo '# '; end"
|
||||
tmuxomatic__exec "clear"
|
||||
}
|
||||
|
||||
function invoke_fingers() {
|
||||
tmux_send "F"
|
||||
sleep 1.0
|
||||
}
|
||||
|
||||
function echo_yanked() {
|
||||
sleep 0.5
|
||||
tmuxomatic__exec "clear"
|
||||
tmuxomatic send-keys "echo yanked text is "
|
||||
tmux_paste
|
||||
tmuxomatic send-keys Enter
|
||||
}
|
||||
|
||||
function begin_with_conf() {
|
||||
tmuxomatic__exec "tmux -f ./test/conf/$1.conf new -s test"
|
||||
}
|
||||
|
||||
function begin_hook() {
|
||||
tmuxomatic set-window-option force-width 80
|
||||
tmuxomatic set-window-option force-height 24
|
||||
tmuxomatic__exec "tmux kill-session -t test"
|
||||
}
|
||||
|
||||
function end_hook() {
|
||||
tmuxomatic__exec "tmux kill-session -t test"
|
||||
}
|
|
@ -3,5 +3,6 @@
|
|||
pkg install -y bash tmux expect fish gawk
|
||||
chsh -s bash vagrant
|
||||
|
||||
#TODO fuck /usr/bin/fish in ubuntu, /usr/local/bin/fish in BSD
|
||||
echo "fishman" | pw user add -n fishman -h 0 -s "/usr/local/bin/fish"
|
||||
echo "run /home/vagrant/shared/tmux-fingers.tmux" > .tmux.conf
|
||||
|
|
|
@ -12,7 +12,7 @@ if [[ "$target" == "within-vm" ]]; then
|
|||
stty cols 80
|
||||
stty rows 24
|
||||
fail_count=0
|
||||
for test_file in $(ls $CURRENT_DIR/specs/*_spec.exp); do
|
||||
for test_file in $(ls $CURRENT_DIR/specs/*_spec.sh); do
|
||||
result="* $test_file ..."
|
||||
sleep 1
|
||||
echo "Running $test_file" >> $SPEC_OUTPUT_LOG
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 1;
|
||||
set tmux_prefix "";
|
||||
|
||||
source "./test/helpers.exp"
|
||||
|
||||
exec "tmux kill-session -t test";
|
||||
spawn tmux -f ./test/conf/basic.conf new -s test;
|
||||
sleep 0.5;
|
||||
|
||||
init_pane
|
||||
exec "cat ./test/fixtures/grep-output";
|
||||
invoke_fingers;
|
||||
send "i";
|
||||
echo_yanked;
|
||||
|
||||
expect {
|
||||
"yanked text is scripts/hints.sh" { exit_ok }
|
||||
timeout { exit_fail }
|
||||
}
|
||||
|
||||
exit $exit_code;
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
#set -x
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "basic"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "i"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 1;
|
||||
set tmux_prefix "";
|
||||
|
||||
source "./test/helpers.exp"
|
||||
|
||||
exec "tmux kill-session -t test";
|
||||
spawn sudo -u fishman SHELL=/usr/bin/fish tmux -f /home/vagrant/shared/test/conf/fish.conf new -s test;
|
||||
|
||||
init_pane_fish
|
||||
exec "cat ./test/fixtures/grep-output";
|
||||
invoke_fingers;
|
||||
sleep 30
|
||||
send "i";
|
||||
echo_yanked;
|
||||
|
||||
expect {
|
||||
"yanked text is scripts/hints.sh" { exit_ok }
|
||||
timeout { exit_fail }
|
||||
}
|
||||
|
||||
exit $exit_code;
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
tmuxomatic__exec "sudo su fishman"
|
||||
tmuxomatic__exec "tmux -f /home/vagrant/shared/test/conf/basic.conf new -s test"
|
||||
init_pane_fish
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "i"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 1;
|
||||
set tmux_prefix "";
|
||||
|
||||
source "./test/helpers.exp"
|
||||
|
||||
exec "tmux kill-session -t test";
|
||||
spawn tmux -f ./test/conf/custom-patterns.conf new -s test;
|
||||
sleep 0.5;
|
||||
|
||||
init_pane
|
||||
exec "cat ./test/fixtures/custom-patterns";
|
||||
|
||||
send "echo yanked text is "
|
||||
invoke_fingers;
|
||||
send "i";
|
||||
tmux_paste;
|
||||
|
||||
invoke_fingers;
|
||||
send "o";
|
||||
tmux_paste;
|
||||
|
||||
send "\r";
|
||||
sleep 0.5;
|
||||
|
||||
expect {
|
||||
"yanked text is W00TW00TW00TYOLOYOLOYOLO" { exit_ok }
|
||||
timeout { exit_fail }
|
||||
}
|
||||
|
||||
exit $exit_code;
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "custom-patterns"
|
||||
init_pane
|
||||
tmuxomatic__exec "cat ./test/fixtures/custom-patterns"
|
||||
|
||||
tmuxomatic send-keys "echo yanked text is "
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "i"
|
||||
tmux_paste
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "o"
|
||||
tmux_paste
|
||||
|
||||
tmuxomatic send-keys Enter
|
||||
|
||||
tmuxomatic__expect "yanked text is W00TW00TW00TYOLOYOLOYOLO"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 1;
|
||||
set tmux_prefix "";
|
||||
|
||||
source "./test/helpers.exp"
|
||||
|
||||
exec "tmux kill-session -t test";
|
||||
spawn tmux -f ./test/conf/basic.conf new -s test;
|
||||
sleep 0.5;
|
||||
|
||||
init_pane
|
||||
exec "cat ./test/fixtures/ip-output";
|
||||
invoke_fingers;
|
||||
send "t";
|
||||
echo_yanked;
|
||||
|
||||
expect {
|
||||
"yanked text is 10.0.3.1" { exit_ok }
|
||||
timeout { exit_fail }
|
||||
}
|
||||
|
||||
exit $exit_code;
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "basic"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/ip-output"
|
||||
sleep 1.0
|
||||
invoke_fingers
|
||||
|
||||
tmuxomatic send-keys "t"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is 10.0.3.1"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 1;
|
||||
set tmux_prefix "";
|
||||
|
||||
source "./test/helpers.exp"
|
||||
|
||||
exec "tmux kill-session -t test";
|
||||
exec "rm -rf /tmp/tmux-yank-result"
|
||||
|
||||
spawn tmux -f ./test/conf/basic.conf new -s test;
|
||||
sleep 0.5;
|
||||
|
||||
init_pane
|
||||
tmux_send "%"
|
||||
tmux_send "%"
|
||||
tmux_send "%"
|
||||
tmux_send "z"
|
||||
|
||||
exec "cat ./test/fixtures/grep-output";
|
||||
invoke_fingers;
|
||||
|
||||
send ""
|
||||
|
||||
exec "echo \"current pane is \$(tmux list-panes -F '#{?window_zoomed_flag,zoomed,not_zoomed}' | head -1)\""
|
||||
|
||||
expect {
|
||||
"current pane is zoomed" { exit_ok }
|
||||
timeout { exit_fail }
|
||||
}
|
||||
|
||||
exit $exit_code;
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "basic"
|
||||
init_pane
|
||||
|
||||
tmux_send "%"
|
||||
tmux_send "%"
|
||||
tmux_send "%"
|
||||
tmux_send "z"
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys C-c
|
||||
|
||||
tmuxomatic__exec "echo \"current pane is \$(tmux list-panes -F '#{?window_zoomed_flag,zoomed,not_zoomed}' | head -1)\""
|
||||
tmuxomatic__expect "current pane is zoomed"
|
||||
tmuxomatic__end end_hook
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env expect
|
||||
|
||||
set timeout 1;
|
||||
set tmux_prefix "";
|
||||
|
||||
source "./test/helpers.exp"
|
||||
|
||||
exec "tmux kill-session -t test";
|
||||
exec "rm -rf /tmp/tmux-yank-result"
|
||||
|
||||
spawn tmux -f ./test/conf/tmux-yank.conf new -s test;
|
||||
sleep 0.5;
|
||||
|
||||
init_pane
|
||||
exec "cat ./test/fixtures/grep-output";
|
||||
invoke_fingers;
|
||||
send "i";
|
||||
|
||||
sleep 0.5;
|
||||
exec "cat /tmp/tmux-yank-result";
|
||||
|
||||
expect {
|
||||
"tmux-yank yolo" { exit_ok }
|
||||
timeout { exit_fail }
|
||||
}
|
||||
|
||||
exit $exit_code;
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "tmux-yank"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "i"
|
||||
|
||||
sleep 10
|
||||
tmuxomatic__exec "cat /tmp/tmux-yank-result"
|
||||
|
||||
tmuxomatic__expect "tmux-yank yolo"
|
||||
tmuxomatic__end end_hook
|
Binary file not shown.
|
@ -0,0 +1,21 @@
|
|||
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/../tmuxomatic.sh
|
||||
source $CURRENT_DIR/../helpers.sh
|
||||
|
||||
TMUX_PREFIX=C-space
|
||||
|
||||
tmuxomatic__begin begin_hook
|
||||
|
||||
begin_with_conf "custom-bindings"
|
||||
init_pane
|
||||
|
||||
tmuxomatic__exec "cat ./test/fixtures/grep-output"
|
||||
invoke_fingers
|
||||
tmuxomatic send-keys "i"
|
||||
echo_yanked
|
||||
|
||||
tmuxomatic__expect "yanked text is scripts/hints.sh"
|
||||
tmuxomatic__end end_hook
|
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
TMUXOMATIC_CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
TMUXOMATIC_SOCKET=tmuxomatic
|
||||
TMUXOMATIC_TIMEOUT="10"
|
||||
TMUXOMATIC_EXIT_CODE=''
|
||||
|
||||
function tmuxomatic() {
|
||||
TMUX='' tmux -L "$TMUXOMATIC_SOCKET" "$@"
|
||||
}
|
||||
|
||||
function tmuxomatic__exec() {
|
||||
tmuxomatic send-keys "$1"
|
||||
tmuxomatic send-keys Enter
|
||||
}
|
||||
|
||||
function tmuxomatic__begin() {
|
||||
tmuxomatic list-sessions &> /dev/null
|
||||
|
||||
if [[ $? -eq 1 ]]; then
|
||||
tmuxomatic -f "$TMUXOMATIC_CURRENT_DIR/conf/tmuxomatic.conf" new-session -d -s tmuxomatic
|
||||
wait
|
||||
tmuxomatic__exec "export TMUX=''"
|
||||
tmuxomatic__exec "clear"
|
||||
fi
|
||||
|
||||
call_hook "$1"
|
||||
}
|
||||
|
||||
function tmuxomatic__end() {
|
||||
call_hook "$1"
|
||||
tmuxomatic kill-server
|
||||
exit $TMUXOMATIC_EXIT_CODE
|
||||
}
|
||||
|
||||
function call_hook() {
|
||||
local fn_hook="$1"
|
||||
|
||||
if [[ $(__fn_exists "$fn_hook") = "1" ]]; then
|
||||
$fn_hook
|
||||
fi
|
||||
}
|
||||
|
||||
function tmuxomatic__expect() {
|
||||
local pattern=$1
|
||||
local n_matches
|
||||
local expect_output
|
||||
|
||||
TMUXOMATIC_FIRST_TS=$(__now)
|
||||
|
||||
while [[ $(($(__now) - TMUXOMATIC_FIRST_TS)) -lt $TMUXOMATIC_TIMEOUT ]]; do
|
||||
echo "Trying to match '$pattern' ..."
|
||||
n_matches=$(tmuxomatic capture-pane -p | grep -E "$pattern" | wc -l)
|
||||
|
||||
if [[ $n_matches -gt 0 ]]; then
|
||||
# TODO echo when specified loglevel
|
||||
echo "Matched '$pattern'! :)"
|
||||
TMUXOMATIC_EXIT_CODE=0
|
||||
break
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
if [[ $n_matches -le 0 ]]; then
|
||||
# TODO echo when specified loglevel
|
||||
# TODO dump pane and buffers
|
||||
log_output_path=$(mktemp "$PWD/tmuxomatic.XXXXXXX")
|
||||
mv "$log_output_path" "$log_output_path.log"
|
||||
log_output_path="${log_output_path}.log"
|
||||
|
||||
|
||||
tmuxomatic capture-pane -p > "$log_output_path"
|
||||
echo "Timeout :( See log at $log_output_path"
|
||||
TMUXOMATIC_EXIT_CODE=1
|
||||
fi
|
||||
}
|
||||
|
||||
# TODO not working in BSD, therefore end hook not being called and :skull:
|
||||
function __fn_exists() {
|
||||
local fn_type=$(type "$1" 2> /dev/null)
|
||||
|
||||
echo "$fn_type" | head -n 1 | grep -c "^$1 is a function$"
|
||||
}
|
||||
|
||||
function __now() {
|
||||
echo $(date +%s)
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
source test/tmuxomatic.sh
|
||||
source test/helpers.sh
|
||||
|
||||
tmuxomatic__begin begin_hook
|
Loading…
Reference in New Issue