From 8b5fb7c4c3fb0f16e0ea2ae7160c7dcd143538b4 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 18 Apr 2020 09:27:14 +0200 Subject: [PATCH] examples: beware of readline on macOS macOS' version of readline does not repeat stdin on stdout in non-interactive mode, contrary to the current version of GNU readline. * examples/test: Add support for strip_prompt. * examples/c/bistromathic/bistromathic.test (strip_prompt): Set it when needed. Early exit when needed. --- examples/c/bistromathic/bistromathic.test | 17 +++++++++++++++++ examples/test | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/examples/c/bistromathic/bistromathic.test b/examples/c/bistromathic/bistromathic.test index 4f64b1a1..5d9966f3 100755 --- a/examples/c/bistromathic/bistromathic.test +++ b/examples/c/bistromathic/bistromathic.test @@ -15,6 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# macOS' version of readline does not repeat stdin on stdout in +# non-interactive mode. +if ! echo '1-1' | prog | grep '1-1'; then + strip_prompt=true +fi + cat >input < 1 / 0 ## Completion. ## ## ------------ ## +# From now on, the differences between versions of GNU Readline are +# too painful to try to cope with. +if $strip_prompt; then + echo "SKIP: this is not the GNU Readline we expect" + if $exit; then + exit 0 + else + exit 1 + fi +fi + # Check completion after an operator. sed -e 's/\\t/ /g' >input < ...' lines from the expected output. +# See bistromathic.test. +strip_prompt=false + # The exercised program. abs_medir=$cwd/examples/$medir if test -x "$abs_medir/$me"; then @@ -77,14 +81,23 @@ run () # Expected exit status. sta_exp=$1 shift + # Expected output. - out_exp=$1 + if $strip_prompt; then + out_exp=$(echo "$1" | sed -e 's/^> err:/err:/;/^> /d') + else + out_exp=$1 + fi shift + # Effective exit status. sta_eff=0 + prog "$@" - out_eff 2>err_eff || sta_eff=$? + # Combine effective output and error streams. out_eff=$(cat out_eff && $noerr || sed -e 's/^/err: /g' err_eff) + if test $sta_eff -eq $sta_exp; then if test "$out_eff" = "$out_exp"; then echo "$me: PASS: $number"