Merge change for lengthened and configurable escape key timeout

This commit is contained in:
ridiculousfish
2016-02-04 13:56:06 -08:00
11 changed files with 255 additions and 98 deletions

View File

@@ -1,48 +1,134 @@
# vim: set filetype=expect:
spawn $fish
expect_prompt
# test switching key bindings
# this should leave the mode in the appropriate state
# Fish should start in default-mode (i.e., emacs) bindings. The default escape
# timeout is 300ms.
send_line "set -g fish_key_bindings fish_vi_key_bindings"
# Verify the emacs transpose word (\et) behavior using various delays,
# including none, after the escape character.
# Start by testing with no delay. This should transpose the words.
send "echo abc def"
send "\033t\r"
expect_prompt -re {\r\ndef abc\r\n} {
puts "emacs transpose words, default timeout: no delay"
} unmatched {
puts stderr "emacs transpose words fail, default timeout: no delay"
}
# Now test with a delay > 0 and < the escape timeout. This should transpose
# the words.
send "echo ghi jkl"
send "\033"
sleep 0.200
send "t\r"
expect_prompt -re {\r\njkl ghi\r\n} {
puts "emacs transpose words, default timeout: short delay"
} unmatched {
puts stderr "emacs transpose words fail, default timeout: short delay"
}
# Now test with a delay > the escape timeout. The transposition should not
# occur and the "t" should become part of the text that is echoed.
send "echo mno pqr"
send "\033"
sleep 0.400
send "t\r"
expect_prompt -re {\r\nmno pqrt\r\n} {
puts "emacs transpose words, default timeout: long delay"
} unmatched {
puts stderr "emacs transpose words fail, default timeout: long delay"
}
# Test vi key bindings.
# This should leave vi mode in the insert state.
send "set -g fish_key_bindings fish_vi_key_bindings\r"
expect_prompt
send_line -h "echo fail\033ddiecho success"
expect_prompt -re {\r\nsuccess\r\n} {
puts "success"
} -nounmatched -re {\r\nfail} {
puts stderr "fail"
# These vi tests assume the fish_vi_key_bindings default escape timeout of
# 10ms is in effect; not the 300ms timeout for the default-mode.
#
# This test is only present to make the Travis-CI framework succeed
# consistently. It's not clear why the subsequent tests succeed without this
# test when executed on a local machine but not in the Travis-CI framework.
send "echo success: default escape timeout\r"
expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
puts "prime vi mode, default timeout"
} unmatched {
puts stderr "Couldn't find expected output 'success'"
}
# try again without the human typing
send_line -h "echo fail\033ddiecho success"
expect_prompt -re {\r\nsuccess\r\n} {
puts "success"
} -nounmatched -re {\r\nfail} {
puts stderr "fail"
} unmatched {
puts stderr "Couldn't find expected output 'success'"
puts stderr "prime vi mode, default timeout"
}
# Test lowercase-r replace
send_line -h "\033ddiecho TEXT\033hhrAi"
send "echo fail: default escape timeout"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.020
send "ddi"
send "echo success: default escape timeout\r"
expect_prompt -re {\r\nsuccess: default escape timeout\r\n} {
puts "vi replace line, default timeout: long delay"
} unmatched {
puts stderr "vi replace line, default timeout: long delay"
}
# Verify that a human can transpose words using \et (which is an emacs default
# binding but should be valid while in vi insert or normal mode).
send "echo abc def"
send "\033"
sleep 0.005
send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
puts "vi transpose words, default timeout: short delay"
} unmatched {
puts stderr "vi transpose words, default timeout: short delay"
}
# Test replacing a single character.
send "echo TEXT"
send "\033"
# Delay needed to allow fish to transition to vi "normal" mode.
sleep 0.020
send "hhrAi\r"
expect_prompt -re {\r\nTAXT\r\n} {
puts "replace success"
} -nounmatched -re {\r\nfail} {
puts stderr "replace fail"
puts "vi mode replace char, default timeout: long delay"
} unmatched {
puts stderr "Couldn't find expected output 'TAXT'"
puts stderr "vi mode replace char, default timeout: long delay"
}
# Verify that changing the escape timeout has an effect.
send "set -g fish_escape_delay_ms 100\r"
expect_prompt
send "echo fail: lengthened escape timeout"
send "\033"
sleep 0.150
send "ddi"
send "echo success: lengthened escape timeout\r"
expect_prompt -re {\r\nsuccess: lengthened escape timeout\r\n} {
puts "vi replace line, 100ms timeout: long delay"
} unmatched {
puts stderr "vi replace line, 100ms timeout: long delay"
}
# Verify that we don't switch to vi normal mode if we don't wait long enough
# after sending escape.
send "echo fail: no normal mode"
send "\033"
sleep 0.050
send "ddi"
send "inserted\r"
expect_prompt -re {\r\nfail: no normal modediinserted\r\n} {
puts "vi replace line, 100ms timeout: short delay"
} unmatched {
puts stderr "vi replace line, 100ms timeout: short delay"
}
# Test 't' binding that contains non-zero arity function (forward-jump) followed
# by another function (and) https://github.com/fish-shell/fish-shell/issues/2357
send "\033"
sleep 0.500
sleep 0.510
send "ddiecho TEXT\033"
sleep 0.500
sleep 0.510
send "hhtTrN\r"
expect_prompt -re {\r\nTENT\r\n} {
puts "t-binding success"
@@ -52,17 +138,44 @@ expect_prompt -re {\r\nTENT\r\n} {
puts stderr "Couldn't find expected output 'TENT'"
}
# still in insert mode, switch back to regular key bindings
send_line -h "set -g fish_key_bindings fish_default_key_bindings"
# Switch back to regular (emacs mode) key bindings.
# The custom escape timeout of 100ms set earlier should still be in effect.
send "set -g fish_key_bindings fish_default_key_bindings\r"
expect_prompt
send_line "echo success"
expect_prompt -re {\r\nsuccess\r\n} {
puts "success"
# Verify the emacs transpose word (\et) behavior using various delays,
# including none, after the escape character.
# Start by testing with no delay. This should transpose the words.
send "echo abc def"
send "\033"
send "t\r"
expect_prompt -re {\r\ndef abc\r\n} {
puts "emacs transpose words, 100ms timeout: no delay"
} unmatched {
puts stderr "Couldn't find expected output 'success'"
} timeout {
set msg ""
append msg "Timeout after setting fish_key_bindings to fish_default_key_bindings\n" \
"\$fish_bind_mode is most likely still set to 'insert'"
abort $msg
puts stderr "emacs transpose words fail, 100ms timeout: no delay"
}
# Same test as above but with a slight delay less than the escape timeout.
send "echo ghi jkl"
send "\033"
sleep 0.080
send "t\r"
expect_prompt -re {\r\njkl ghi\r\n} {
puts "emacs transpose words, 100ms timeout: short delay"
} unmatched {
puts stderr "emacs transpose words fail, 100ms timeout: short delay"
}
# Now test with a delay > the escape timeout. The transposition should not
# occur and the "t" should become part of the text that is echoed.
send "echo mno pqr"
send "\033"
sleep 0.120
send "t\r"
expect_prompt -re {\r\nmno pqrt\r\n} {
puts "emacs transpose words, 100ms timeout: long delay"
} unmatched {
puts stderr "emacs transpose words fail, 100ms timeout: long delay"
}

View File

@@ -1,5 +1,13 @@
success
success
replace success
emacs transpose words, default timeout: no delay
emacs transpose words, default timeout: short delay
emacs transpose words, default timeout: long delay
prime vi mode, default timeout
vi replace line, default timeout: long delay
vi transpose words, default timeout: short delay
vi mode replace char, default timeout: long delay
vi replace line, 100ms timeout: long delay
vi replace line, 100ms timeout: short delay
t-binding success
success
emacs transpose words, 100ms timeout: no delay
emacs transpose words, 100ms timeout: short delay
emacs transpose words, 100ms timeout: long delay

View File

@@ -5,7 +5,7 @@ log_file -noappend interactive.tmp.log
set fish ../fish
set timeout 4
set timeout 5
set send_human {.05 .1 5 .02 .2}

14
tests/interactive.fish Normal file → Executable file
View File

@@ -2,7 +2,17 @@
#
# Interactive tests using `expect`
source test_util.fish (status -f); or exit
# Change to directory containing this script
cd (dirname (status -f))
# Test files specified on commandline, or all *.expect files
if set -q argv[1]
set files_to_test $argv.expect
else
set files_to_test *.expect
end
source test_util.fish (status -f) $argv; or exit
say -o cyan "Testing interactive functionality"
if not type -q expect
@@ -65,7 +75,7 @@ function test_file
end
set -l failed
for i in *.expect
for i in $files_to_test
if not test_file $i
set failed $failed $i
end

View File

@@ -6,7 +6,6 @@
cd (dirname (status -f))
# Test files specified on commandline, or all *.in files
set -q argv[1]
if set -q argv[1]
set files_to_test $argv.in
else