diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 770c990..388a391 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -1,6 +1,7 @@ EXTRA_DIST = \ hold-stdin print-exitstatus \ e2e-test e2e-test-server \ + e2e-test-subrs \ mosh-client mosh-server \ $(displaytests) \ emulation-attributes.test diff --git a/src/tests/e2e-failure.test b/src/tests/e2e-failure.test index 952d1c5..34147e9 100755 --- a/src/tests/e2e-failure.test +++ b/src/tests/e2e-failure.test @@ -1,13 +1,6 @@ #!/bin/sh -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/e2e-success.test b/src/tests/e2e-success.test index 9fda323..3134b62 100755 --- a/src/tests/e2e-success.test +++ b/src/tests/e2e-success.test @@ -1,13 +1,6 @@ #!/bin/sh -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/e2e-test-subrs b/src/tests/e2e-test-subrs new file mode 100644 index 0000000..7e8e320 --- /dev/null +++ b/src/tests/e2e-test-subrs @@ -0,0 +1,71 @@ +#!/bin/sh + +# +# This is a library of subroutines mostly intended for test scripts. +# + +fail() +{ + printf "$@" 2>&1 + exit 99 +} + +sleepf() +{ + (sleep .1 || sleep 1) > /dev/null 2>&1 +} + +seq() +{ + if [ $# -lt 1 -o $# -gt 3 ]; then + echo "bad args" >&2 + fi + first=$1 + incr=1 + last=0 + case $# in + 3) + incr=$2 + last=$3 + ;; + 2) + last=$2 + ;; + 1) + ;; + esac + while :; do + printf '%d\n' $first + first=$(expr $first + $incr) + if [ $first -gt $last ]; then + break + fi + done +} + +chr() +{ + printf "\\$(printf %03o $1)" +} + +utf8cp() +{ + if [ $1 -gt $((0x10ffff)) ]; then + fail "illegal Unicode code point %x\n" $1 + elif [ $1 -lt $((0x80)) ]; then + chr $1 + elif [ $1 -lt $((0x800)) ]; then + chr $(( (($1 >> 6) & 0x1f) | 0xc0 )) + chr $(( ($1 & 0x3f) | 0x80 )) + elif [ $1 -lt $((0x10000)) ]; then + chr $(( (($1 >> 12) & 0x0f) | 0xe0 )) + chr $(( (($1 >> 6) & 0x3f) | 0x80 )) + chr $(( ($1 & 0x3f) | 0x80 )) + elif [ $1 -lt $((0x200000)) ]; then + chr $(( (($1 >> 18) & 0x03) | 0xf0 )) + chr $(( (($1 >> 12) & 0x3f) | 0x80 )) + chr $(( (($1 >> 6) & 0x3f) | 0x80 )) + chr $(( ($1 & 0x3f) | 0x80 )) + fi +} + diff --git a/src/tests/emulation-80th-column.test b/src/tests/emulation-80th-column.test index 39ab1f9..30fc4c9 100755 --- a/src/tests/emulation-80th-column.test +++ b/src/tests/emulation-80th-column.test @@ -8,14 +8,7 @@ # line). # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -28,39 +21,6 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - baseline() { # We need to control CR and LF individually for this test. diff --git a/src/tests/emulation-ascii-iso-8859.test b/src/tests/emulation-ascii-iso-8859.test index ed0c419..08b00ba 100755 --- a/src/tests/emulation-ascii-iso-8859.test +++ b/src/tests/emulation-ascii-iso-8859.test @@ -3,14 +3,8 @@ # # This validates display of ASCII and ISO-8859-1 characters. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -23,65 +17,6 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - -chr() -{ - printf "\\$(printf %03o $1)" -} - -utf8cp() -{ - if [ $1 -gt $((0x10ffff)) ]; then - fail "illegal Unicode code point %x\n" $1 - elif [ $1 -lt $((0x80)) ]; then - chr $1 - elif [ $1 -lt $((0x800)) ]; then - chr $(( (($1 >> 6) & 0x1f) | 0xc0 )) - chr $(( ($1 & 0x3f) | 0x80 )) - elif [ $1 -lt $((0x10000)) ]; then - chr $(( (($1 >> 12) & 0x0f) | 0xe0 )) - chr $(( (($1 >> 6) & 0x3f) | 0x80 )) - chr $(( ($1 & 0x3f) | 0x80 )) - elif [ $1 -lt $((0x200000)) ]; then - chr $(( (($1 >> 18) & 0x03) | 0xf0 )) - chr $(( (($1 >> 12) & 0x3f) | 0x80 )) - chr $(( (($1 >> 6) & 0x3f) | 0x80 )) - chr $(( ($1 & 0x3f) | 0x80 )) - fi -} - baseline() { printf '\033[H\033[J' diff --git a/src/tests/emulation-attributes.test b/src/tests/emulation-attributes.test index c173a14..955029f 100755 --- a/src/tests/emulation-attributes.test +++ b/src/tests/emulation-attributes.test @@ -10,14 +10,7 @@ # compares on these values fail though they are visually identical. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -30,39 +23,6 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - baseline() { # Strip our name to the last dash-separated word before the .test suffix. diff --git a/src/tests/emulation-back-tab.test b/src/tests/emulation-back-tab.test index 7c45901..cf95ed7 100755 --- a/src/tests/emulation-back-tab.test +++ b/src/tests/emulation-back-tab.test @@ -4,14 +4,7 @@ # This test is for issue 539 on github. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/emulation-cursor-motion.test b/src/tests/emulation-cursor-motion.test index 88a0ed6..8f44144 100755 --- a/src/tests/emulation-cursor-motion.test +++ b/src/tests/emulation-cursor-motion.test @@ -4,14 +4,8 @@ # This test exercises a particular optimization involving small cursor # motions in Mosh. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -24,39 +18,6 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - baseline() { printf '\033[H\033[J' diff --git a/src/tests/emulation-multiline-scroll.test b/src/tests/emulation-multiline-scroll.test index a490ab3..ce8186c 100755 --- a/src/tests/emulation-multiline-scroll.test +++ b/src/tests/emulation-multiline-scroll.test @@ -5,14 +5,9 @@ # of performance code for Mosh, involving insert/delete line. # It does insert/delete line from 0 to 2 more than the window height # 24 in this test environment). -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - +# +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -25,39 +20,6 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - baseline() { printf '\033[H\033[J' diff --git a/src/tests/emulation-wrap-across-frames.test b/src/tests/emulation-wrap-across-frames.test index e3d4e74..5c4f758 100755 --- a/src/tests/emulation-wrap-across-frames.test +++ b/src/tests/emulation-wrap-across-frames.test @@ -8,14 +8,8 @@ # between cells. It got moved to the Rows class where it makes more # sense. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -28,65 +22,6 @@ if [ $# -ne 1 ]; then fail "bad arguments %s\n" "$@" fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - -chr() -{ - printf "\\$(printf %03o $1)" -} - -utf8cp() -{ - if [ $1 -gt $((0x10ffff)) ]; then - fail "illegal Unicode code point %x\n" $1 - elif [ $1 -lt $((0x80)) ]; then - chr $1 - elif [ $1 -lt $((0x800)) ]; then - chr $(( (($1 >> 6) & 0x1f) | 0xc0 )) - chr $(( ($1 & 0x3f) | 0x80 )) - elif [ $1 -lt $((0x10000)) ]; then - chr $(( (($1 >> 12) & 0x0f) | 0xe0 )) - chr $(( (($1 >> 6) & 0x3f) | 0x80 )) - chr $(( ($1 & 0x3f) | 0x80 )) - elif [ $1 -lt $((0x200000)) ]; then - chr $(( (($1 >> 18) & 0x03) | 0xf0 )) - chr $(( (($1 >> 12) & 0x3f) | 0x80 )) - chr $(( (($1 >> 6) & 0x3f) | 0x80 )) - chr $(( ($1 & 0x3f) | 0x80 )) - fi -} - baseline() { printf '\033[H\033[J' diff --git a/src/tests/prediction-unicode.test b/src/tests/prediction-unicode.test index 8927331..0cdcdca 100755 --- a/src/tests/prediction-unicode.test +++ b/src/tests/prediction-unicode.test @@ -24,14 +24,8 @@ # would be predicted as ")" before being replaced by the # correct character. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -39,65 +33,6 @@ if [ $# -eq 0 ]; then exit fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - -chr() -{ - printf "\\$(printf %03o $1)" -} - -utf8cp() -{ - if [ $1 -gt $((0x10ffff)) ]; then - fail "illegal Unicode code point %x\n" $1 - elif [ $1 -lt $((0x80)) ]; then - chr $1 - elif [ $1 -lt $((0x800)) ]; then - chr $(( (($1 >> 6) & 0x1f) | 0xc0 )) - chr $(( ($1 & 0x3f) | 0x80 )) - elif [ $1 -lt $((0x10000)) ]; then - chr $(( (($1 >> 12) & 0x0f) | 0xe0 )) - chr $(( (($1 >> 6) & 0x3f) | 0x80 )) - chr $(( ($1 & 0x3f) | 0x80 )) - elif [ $1 -lt $((0x200000)) ]; then - chr $(( (($1 >> 18) & 0x03) | 0xf0 )) - chr $(( (($1 >> 12) & 0x3f) | 0x80 )) - chr $(( (($1 >> 6) & 0x3f) | 0x80 )) - chr $(( ($1 & 0x3f) | 0x80 )) - fi -} - tmux_commands() { for x in $(seq 1 5); do diff --git a/src/tests/pty-deadlock.test b/src/tests/pty-deadlock.test index 72408fd..bb0086c 100755 --- a/src/tests/pty-deadlock.test +++ b/src/tests/pty-deadlock.test @@ -11,15 +11,7 @@ # cleanup with kill -9. # - -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/server-network-timeout.test b/src/tests/server-network-timeout.test index f3d4b9b..60bf222 100755 --- a/src/tests/server-network-timeout.test +++ b/src/tests/server-network-timeout.test @@ -14,14 +14,7 @@ TIMEOUT=10 -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/unicode-combine-fallback-assert.test b/src/tests/unicode-combine-fallback-assert.test index 5ed19c4..2e6336e 100755 --- a/src/tests/unicode-combine-fallback-assert.test +++ b/src/tests/unicode-combine-fallback-assert.test @@ -8,14 +8,7 @@ # # It just sends the offending output to mosh and expects it to not die. -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/unicode-later-combining.test b/src/tests/unicode-later-combining.test index 980b8ed..74898d6 100755 --- a/src/tests/unicode-later-combining.test +++ b/src/tests/unicode-later-combining.test @@ -10,14 +10,7 @@ # that are visually identical. The variant test is not run or validated. # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then diff --git a/src/tests/window-resize.test b/src/tests/window-resize.test index 7ce956e..1130876 100755 --- a/src/tests/window-resize.test +++ b/src/tests/window-resize.test @@ -6,14 +6,7 @@ # resize them. But it works! # -fail() -{ - printf "$@" 2>&1 - exit 99 -} - - - +. $(dirname $0)/e2e-test-subrs PATH=$PATH:.:$srcdir # Top-level wrapper. if [ $# -eq 0 ]; then @@ -21,39 +14,6 @@ if [ $# -eq 0 ]; then exit fi -sleepf() -{ - (sleep .1 || sleep 1) > /dev/null 2>&1 -} - -seq() -{ - if [ $# -lt 1 -o $# -gt 3 ]; then - echo "bad args" >&2 - fi - first=$1 - incr=1 - last=0 - case $# in - 3) - incr=$2 - last=$3 - ;; - 2) - last=$2 - ;; - 1) - ;; - esac - while :; do - printf '%d\n' $first - first=$(expr $first + $incr) - if [ $first -gt $last ]; then - break - fi - done -} - tmux_resize_commands() { hv=$1