aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-04 13:56:06 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-04 13:56:49 -0800
commit25ad8866c97b242911b1e52298c8cfeed4530097 (patch)
tree8043d99a119ecef9bef288d9c77be9324898af80 /tests
parent1d446b74ffb563ee18c298417b802458aad9ca84 (diff)
parent2646d51a0bb2551e1d53d164cea2a6a15be44b6e (diff)
Merge change for lengthened and configurable escape key timeout
Diffstat (limited to 'tests')
-rw-r--r--tests/bind.expect187
-rw-r--r--tests/bind.expect.out16
-rw-r--r--tests/interactive.expect.rc2
-rwxr-xr-x[-rw-r--r--]tests/interactive.fish14
-rwxr-xr-xtests/test.fish1
5 files changed, 175 insertions, 45 deletions
diff --git a/tests/bind.expect b/tests/bind.expect
index 8af3ddab..5ad4fc9c 100644
--- a/tests/bind.expect
+++ b/tests/bind.expect
@@ -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.
+
+# 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"
+}
-send_line "set -g fish_key_bindings fish_vi_key_bindings"
+# 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'"
+ puts stderr "prime vi mode, default timeout"
}
-# 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"
+
+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 "Couldn't find expected output 'success'"
+ puts stderr "vi transpose words, default timeout: short delay"
}
-# Test lowercase-r replace
-send_line -h "\033ddiecho TEXT\033hhrAi"
+# 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 "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 "Couldn't find expected output 'TAXT'"
+ 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 "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 "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: long delay"
}
diff --git a/tests/bind.expect.out b/tests/bind.expect.out
index 5777546d..17437121 100644
--- a/tests/bind.expect.out
+++ b/tests/bind.expect.out
@@ -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
diff --git a/tests/interactive.expect.rc b/tests/interactive.expect.rc
index c148b562..1949d328 100644
--- a/tests/interactive.expect.rc
+++ b/tests/interactive.expect.rc
@@ -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}
diff --git a/tests/interactive.fish b/tests/interactive.fish
index ad53e262..9f5e979c 100644..100755
--- a/tests/interactive.fish
+++ b/tests/interactive.fish
@@ -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
diff --git a/tests/test.fish b/tests/test.fish
index 994e7a76..588a8f35 100755
--- a/tests/test.fish
+++ b/tests/test.fish
@@ -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