From d205a98a8756f24d2eb3274aa9de27c46c3bd8a9 Mon Sep 17 00:00:00 2001 From: John Hood Date: Sat, 6 May 2017 11:09:05 -0400 Subject: [PATCH] Test for SCROLL UP and SCROLL DOWN. --- src/tests/Makefile.am | 1 + src/tests/emulation-scroll.test | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 src/tests/emulation-scroll.test diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 89d5717..f759e28 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -22,6 +22,7 @@ displaytests = \ emulation-back-tab.test \ emulation-cursor-motion.test \ emulation-multiline-scroll.test \ + emulation-scroll.test \ emulation-wrap-across-frames.test \ network-no-diff.test \ prediction-unicode.test \ diff --git a/src/tests/emulation-scroll.test b/src/tests/emulation-scroll.test new file mode 100755 index 0000000..1656cad --- /dev/null +++ b/src/tests/emulation-scroll.test @@ -0,0 +1,76 @@ +#!/bin/sh + +# +# This is a regression test for a bug in Mosh: it would move the +# cursor for the SCROLL UP and SCROLL DOWN commands, though it should +# not. +# + +# shellcheck source=e2e-test-subrs +. "$(dirname "$0")/e2e-test-subrs" +PATH=$PATH:.:$srcdir +# Top-level wrapper. +if [ $# -eq 0 ]; then + e2e-test "$0" baseline post + exit +fi + +# OK, we have arguments, we're one of the test hooks. +if [ $# -ne 1 ]; then + fail "bad arguments %s\n" "$@" +fi + +baseline() +{ + # Clear + printf '\033[H\033[J' + # Fill with sample text + for i in $(seq 1 24); do + printf '\ntext %s' "$i" + done + # Scroll up 4 lines + printf '\033[4S' + # Then down 2 + printf '\033[2T' + + # The cursor should not have moved and this should print on the + # last line, and not overprint 'line 24' + printf '\rBad line' + # Overprint on line 24 + printf '\033[24;1HLast line' + # and line 1 + printf '\033[HFirst line\n' + +} + +post() +{ + local capture + capture="$(basename "$0").d/baseline.capture" + # 'Bad line' should have been overwritten + if grep -q '^Bad line$' "$capture"; then + exit 1 + fi + # The first four lines should have scrolled off + if grep -q '^text [1-4]$' "$capture"; then + exit 1 + fi + # The last line should not have scrolled off or been overwritten + if ! grep -q '^text 24$' "$capture"; then + exit 1 + fi + # 20 lines of the original text should remain + if [ "$(grep -c '^text' "$capture")" -ne 20 ]; then + exit 1 + fi + exit 0 +} + +case $1 in + baseline) + baseline;; + post) + post;; + *) + fail "unknown test argument %s\n" "$1";; +esac