From 0562e599a65708aa1e1d1c0788737ff683caa503 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 24 Sep 2021 08:07:17 -0700 Subject: [PATCH] isolated-tmux to more reliably initialize and other fixes Prior to this change, tmux based tests would call 'isolated-tmux' which would initialize tmux on first call, an admitted "evil hack." Switch to requiring an explicit call to 'isolated-tmux-start' which then defines 'isolated-tmux' and other functions. Add some loop-until-prompt logic into 'isolated-tmux-start'. This improves reliability of the tmux tests on systems under load; at least it makes the tests pass in the background on my Mac. Remove the '$sleep' variable, to be replaced with 'tmux-sleep'. --- tests/checks/tmux-bind.fish | 4 +++- tests/checks/tmux-complete.fish | 8 +++---- tests/checks/tmux-prompt.fish | 11 ++------- ...ted-tmux.fish => isolated-tmux-start.fish} | 24 ++++++++++--------- 4 files changed, 22 insertions(+), 25 deletions(-) rename tests/test_functions/{isolated-tmux.fish => isolated-tmux-start.fish} (72%) diff --git a/tests/checks/tmux-bind.fish b/tests/checks/tmux-bind.fish index a25e8d635..e10a82681 100644 --- a/tests/checks/tmux-bind.fish +++ b/tests/checks/tmux-bind.fish @@ -1,9 +1,11 @@ #RUN: %fish %s #REQUIRES: command -v tmux +isolated-tmux-start + # Test moving around with up-or-search on a multi-line commandline. isolated-tmux send-keys 'echo 12' M-Enter 'echo ab' C-p 345 C-n cde -$sleep +tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 0> echo 12345 # CHECK: echo abcde diff --git a/tests/checks/tmux-complete.fish b/tests/checks/tmux-complete.fish index 91dfd0a37..bad378881 100644 --- a/tests/checks/tmux-complete.fish +++ b/tests/checks/tmux-complete.fish @@ -1,13 +1,13 @@ #RUN: %fish %s #REQUIRES: command -v tmux -isolated-tmux +isolated-tmux-start # Don't escape existing token (#7526). echo >file-1 echo >file-2 isolated-tmux send-keys 'HOME=$PWD ls ~/' Tab -$sleep +tmux-sleep isolated-tmux capture-pane -p # Note the contents may or may not have the autosuggestion appended - it is a race. # CHECK: prompt 0> HOME=$PWD ls ~/file-{{1?}} @@ -16,14 +16,14 @@ isolated-tmux capture-pane -p # No pager on single smartcase completion (#7738). isolated-tmux send-keys C-u C-l 'mkdir cmake CMakeFiles' Enter C-l \ 'cat cmake' Tab -$sleep +tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 1> cat cmake/ # Correct case in pager when prefixes differ in case (#7743). isolated-tmux send-keys C-u C-l 'complete -c foo2 -a "aabc aaBd" -f' Enter C-l \ 'foo2 A' Tab -$sleep +tmux-sleep isolated-tmux capture-pane -p # The "bc" part is the autosuggestion - we could use "capture-pane -e" to check colors. # CHECK: prompt 2> foo2 aabc diff --git a/tests/checks/tmux-prompt.fish b/tests/checks/tmux-prompt.fish index a5c06aadf..e1f129e56 100644 --- a/tests/checks/tmux-prompt.fish +++ b/tests/checks/tmux-prompt.fish @@ -8,20 +8,13 @@ set -g isolated_tmux_fish_extra_args -C ' end ' -# Start it up and loop a bit, until we get an initial prompt. -isolated-tmux -for i in seq 10 - if string match -q '*prompt*' (isolated-tmux capture-pane -p) - break - end - sleep .5 -end +isolated-tmux-start isolated-tmux capture-pane -p # CHECK: prompt 0> <> set -q CI && set sleep sleep 10 set -U prompt_var changed -$sleep +tmux-sleep isolated-tmux capture-pane -p # CHECK: prompt 0> diff --git a/tests/test_functions/isolated-tmux.fish b/tests/test_functions/isolated-tmux-start.fish similarity index 72% rename from tests/test_functions/isolated-tmux.fish rename to tests/test_functions/isolated-tmux-start.fish index 3412b839e..1d3a22127 100644 --- a/tests/test_functions/isolated-tmux.fish +++ b/tests/test_functions/isolated-tmux-start.fish @@ -1,14 +1,7 @@ -function isolated-tmux --inherit-variable tmpdir +function isolated-tmux-start set -l tmpdir (mktemp -d) cd $tmpdir - set -g sleep sleep .1 - set -q CI && set sleep sleep 1 - - # Evil hack - override ourselves, so we only run initialization once. - # We could do this outside the function, but then initialization is done too early for a - # command that wants to set $isolated_tmux_fish_extra_args first, like - # fish -C 'source tests/test_functions/isolated-tmux.fish' tests/checks/tmux-prompt.fish function isolated-tmux --inherit-variable tmpdir # tmux can't handle session sockets in paths that are too long, and macOS has a very long # $TMPDIR, so use a relative path - except macOS doesn't have `realpath --relative-to`... @@ -26,6 +19,12 @@ function isolated-tmux --inherit-variable tmpdir rm -r $tmpdir end + function tmux-sleep + set -q CI + and sleep 1 + or sleep .1 + end + set -l fish (status fish-path) isolated-tmux new-session -x 80 -y 10 -d $fish -C ' # This is similar to "tests/interactive.config". @@ -37,9 +36,12 @@ function isolated-tmux --inherit-variable tmpdir # Set the correct permissions for the newly created socket to allow future connections. # This is required at least under WSL or else each invocation will return a permissions error. chmod 777 .tmux-socket - $sleep # Let fish draw a prompt. - if set -q argv[1] - isolated-tmux $argv + # Loop a bit, until we get an initial prompt. + for i in seq 25 + if string match -q '*prompt*' (isolated-tmux capture-pane -p) + break + end + sleep .2 end end