From f66edfdec283b06a983d8f2afa60b90ce520ce97 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 8 Jun 2020 22:57:46 +0200 Subject: [PATCH] Port generic.expect to pexpect Removes a dumb workaround. Huzzah! --- tests/generic.expect | 63 --------------------------------------- tests/generic.expect.err | 0 tests/generic.expect.out | 0 tests/pexpects/generic.py | 55 ++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 63 deletions(-) delete mode 100644 tests/generic.expect delete mode 100644 tests/generic.expect.err delete mode 100644 tests/generic.expect.out create mode 100644 tests/pexpects/generic.py diff --git a/tests/generic.expect b/tests/generic.expect deleted file mode 100644 index 6dad0a937..000000000 --- a/tests/generic.expect +++ /dev/null @@ -1,63 +0,0 @@ -# vim: set filetype=expect: -# -# General tests that don't belong elsewhere - -spawn $fish - -expect_prompt - -# ensure the Apple key () is typeable -send_line "echo " -expect_prompt "" {} unmatched { - puts stderr "Couldn't type apple key ()" -} - -# check that history is returned in the right order (#2028) -# this hist_command nonsense is the cleanest way to send the $ char -set hist_command "echo \$history\[1\]" - -# first send 'echo stuff' -send_line "echo stuff" -expect_prompt "stuff" {} unmatched { - puts stderr "Couldn't find expected output 'stuff'" -} - -# last history item should be 'echo stuff' -send_line $hist_command -expect_prompt "echo stuff" {} unmatched { - puts stderr "Couldn't find expected output 'echo stuff'" -} - -# last history command should be the one that printed the history -send_line $hist_command -expect_prompt -re {echo .history.*} {} unmatched { - puts stderr "Couldn't find expected output $hist_command" -} - -# Backslashes at end of comments (#1255) -# This backslash should NOT cause the line to continue -send_line "echo -n #comment\\" -expect_prompt - -# a pipe at the end of the line (#1285) -send_line "echo hoge |\n cat" -expect_prompt "hoge" {} unmatched { - puts stderr "Error with a pipe at the end of the line" -} -send_line "echo hoge | \n cat" -expect_prompt "hoge" {} unmatched { - puts stderr "Error with a pipe at the end of the line with whitespaces" -} -send_line "echo hoge 2>| \n cat" -expect_prompt "hoge" {} unmatched { - puts stderr "Error with a pipe with redirection at the end of the line" -} -send_line "echo hoge >| \n cat" -expect_prompt "hoge" {} unmatched { - puts stderr "Error with a pipe with redirection at the end of the line" -} - -send_line "source; or echo failed" -expect_prompt "failed" {} unmatched { - puts stderr "Error with sourcing from the terminal" -} diff --git a/tests/generic.expect.err b/tests/generic.expect.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/generic.expect.out b/tests/generic.expect.out deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/pexpects/generic.py b/tests/pexpects/generic.py new file mode 100644 index 000000000..28d1ce8cc --- /dev/null +++ b/tests/pexpects/generic.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +from pexpect_helper import SpawnedProc +import subprocess +import sys +from time import sleep +import os + +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() + +# ensure the Apple key () is typeable +sendline("echo ") +expect_prompt("") + +# check that history is returned in the right order (#2028) +# first send 'echo stuff' +sendline("echo stuff") +expect_prompt("stuff") + +# last history item should be 'echo stuff' +sendline("echo $history[1]") +expect_prompt("echo stuff") + +# last history command should be the one that printed the history +sendline("echo $history[1]") +expect_prompt("echo .history.*") + +# Backslashes at end of comments (#1255) +# This backslash should NOT cause the line to continue +sendline("echo -n #comment\\") +expect_prompt() + +# a pipe at the end of the line (#1285) +sendline("echo hoge |\n cat") +expect_prompt("hoge") + +sendline("echo hoge | \n cat") +expect_prompt("hoge") + +sendline("echo hoge 2>| \n cat") +expect_prompt("hoge") +sendline("echo hoge >| \n cat") +expect_prompt("hoge") + +sendline("source; or echo failed") +expect_prompt("failed")