From 339a5a219691cb8e13da1591da6be36e5feb56e1 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 8 Jun 2020 22:52:18 +0200 Subject: [PATCH] Port fkr expect to pexpect --- tests/fkr.expect | 61 ------------------------------------------- tests/fkr.expect.err | 0 tests/fkr.expect.out | 7 ----- tests/pexpects/fkr.py | 50 +++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 68 deletions(-) delete mode 100644 tests/fkr.expect delete mode 100644 tests/fkr.expect.err delete mode 100644 tests/fkr.expect.out create mode 100644 tests/pexpects/fkr.py diff --git a/tests/fkr.expect b/tests/fkr.expect deleted file mode 100644 index 40ce70583..000000000 --- a/tests/fkr.expect +++ /dev/null @@ -1,61 +0,0 @@ -# vim: set filetype=expect: - -set ::env(fish_escape_delay_ms) 10 -spawn $fish_key_reader -c - -# Do we get the expected startup prompt? -expect -ex "Press a key:" { - puts "saw expected startup prompt" -} unmatched { - puts stderr "didn't see expected startup prompt" -} - -# Is a single control char echoed correctly? -send "\x01" -expect -ex "char: \\cA\r\nbind \\cA 'do something'\r\n" { - puts "ctrl-a handled" -} unmatched { - puts stderr "ctrl-a not handled" -} - -# Is a non-ASCII UTF-8 sequence prefaced by an escape char handled correctly? -sleep 0.020 -# send "\x1B\xE1\x88\xB4" -send "\x1B\u1234" -expect -ex "char: \\u1234\r\nbind \\e\\u1234 'do something'\r\n" { - puts "unicode char, handled" -} unmatched { - puts stderr "unicode char, not handled" -} - -# Is a NULL char echoed correctly? -sleep 0.020 -send -null -expect -ex "char: \\c@\r\nbind -k nul 'do something'\r\n" { - puts "\\c@ handled" -} unmatched { - puts stderr "\\c@ not handled" -} - -# Does it keep running if handed control sequences in the wrong order? -send "\x03" -sleep 0.010 -send "\x04" -expect -ex "char: \\cD\r\n" { - puts "invalid terminate sequence handled" -} unmatched { - puts stderr "invalid terminate sequence not handled" -} - -# Now send a second [ctrl-D]. Does that terminate the process like it should? -send "\x04" -expect -ex "char: \\cD\r\n" { - puts "valid terminate sequence handled" -} unmatched { - puts stderr "valid terminate sequence not handled" -} -expect -ex "Exiting at your request.\r\n" { - puts "exited on seeing valid terminate" -} unmatched { - puts stderr "did not exit on seeing valid terminate sequence" -} diff --git a/tests/fkr.expect.err b/tests/fkr.expect.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/fkr.expect.out b/tests/fkr.expect.out deleted file mode 100644 index fde076142..000000000 --- a/tests/fkr.expect.out +++ /dev/null @@ -1,7 +0,0 @@ -saw expected startup prompt -ctrl-a handled -unicode char, handled -\c@ handled -invalid terminate sequence handled -valid terminate sequence handled -exited on seeing valid terminate diff --git a/tests/pexpects/fkr.py b/tests/pexpects/fkr.py new file mode 100644 index 000000000..221797a50 --- /dev/null +++ b/tests/pexpects/fkr.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +from pexpect_helper import SpawnedProc +import subprocess +import sys +from time import sleep +import os + +os.environ["fish_escape_delay_ms"] = "10" +SpawnedProc() +sp = SpawnedProc() +send, sendline, sleep, expect_prompt, expect_re, expect_str = ( + sp.send, + sp.sendline, + sp.sleep, + sp.expect_prompt, + sp.expect_re, + sp.expect_str, +) +expect_prompt() + +sendline("exec fish_key_reader -c") + +# Do we get the expected startup prompt? +expect_str("Press a key:") + +# Is a single control char echoed correctly? +send("\x01") +expect_str("char: \\cA\r\nbind \\cA 'do something'\r\n") + +# Is a non-ASCII UTF-8 sequence prefaced by an escape char handled correctly? +sleep(0.020) +# send "\x1B\xE1\x88\xB4" +send("\x1B\u1234") +expect_str("char: \\u1234\r\nbind \\e\\u1234 'do something'\r\n") + +# Is a NULL char echoed correctly? +sleep(0.020) +send("\x00") +expect_str("char: \\c@\r\nbind -k nul 'do something'\r\n") + +# Does it keep running if handed control sequences in the wrong order? +send("\x03") +sleep(0.010) +send("\x04") +expect_str("char: \\cD\r\n") + +# Now send a second [ctrl-D]. Does that terminate the process like it should? +send("\x04") +expect_str("char: \\cD\r\n") +expect_str("Exiting at your request.\r\n")