billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=826606e0c3fd18e51b537a2ba51fd0df844e0334

commit 826606e0c3fd18e51b537a2ba51fd0df844e0334
Author: Boris Faure <[email protected]>
Date:   Thu Nov 22 23:41:48 2018 +0100

    tests: add first tests + test framework
---
 tests/README.md                    |  42 +++++++++
 tests/decfra-no-restrict-cursor.sh |  32 +++++++
 tests/decfra-restrict-cursor.sh    |  34 ++++++++
 tests/run_tests.sh                 | 169 +++++++++++++++++++++++++++++++++++++
 tests/tests.results                |   2 +
 5 files changed, 279 insertions(+)

diff --git a/tests/README.md b/tests/README.md
new file mode 100644
index 0000000..838db49
--- /dev/null
+++ b/tests/README.md
@@ -0,0 +1,42 @@
+Very small test framework for Terminology
+
+Goal
+----
+
+Avoid regressions in Terminology's code that parse and interprets escape
+codes.
+
+Dependencies
+------------
+
+- `tytest`, compiled with `-D tests=true` when running `meson`
+- a posix shell
+
+
+Tytest
+------
+
+`tytest` is a simple binary that takes escape codes in input and output an md5
+sum. This checksum is computed on the state of terminology after parsing and
+interpreting those escape codes.
+
+
+Test cases
+----------
+
+Test cases are simple shell scripts that output escape codes.
+
+How to run the tests
+--------------------
+
+A shell script called `run_tests.sh` is provided to run all the tests given in
+a test results file.
+See `run_tests.sh --help` for more information.
+
+Test results file
+-----------------
+
+When running a test through `tytest`, an md5 sum is computed. This checksum is
+stored with the name of the test in a file called `tests.results`.
+If terminology's behaviour changed, then the checksum will change. This will
+be noticed by `run_tests.sh` and will show those tests as failed.
diff --git a/tests/decfra-no-restrict-cursor.sh 
b/tests/decfra-no-restrict-cursor.sh
new file mode 100755
index 0000000..cd32f4e
--- /dev/null
+++ b/tests/decfra-no-restrict-cursor.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# fill space with E
+printf '\033#8'
+#set color
+printf '\033[46;31;3m'
+# set top/bottom margins:
+printf '\033[10;20r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;15s'
+# fill larger rect with @
+printf '\033[64;2;3;23;20$x'
+# change color
+printf '\033[0m\033[45;32;1m'
+# top left corner with [
+printf '\033[91;3;5;12;7$x'
+# top right corner with ]
+printf '\033[93;8;12;13;17$x'
+# bottom left corner with (
+printf '\033[40;18;3;22;8$x'
+# top right corner with )
+printf '\033[41;17;14;23;18$x'
+# change color
+printf '\033[0m\033[44;33;4m'
+# one in center with #
+printf '\033[35;12;12;12;12$x'
+
+# cursor to 0,0
+printf '\033[H'
+echo '--------------------------------------------------'
diff --git a/tests/decfra-restrict-cursor.sh b/tests/decfra-restrict-cursor.sh
new file mode 100755
index 0000000..ab9a8cc
--- /dev/null
+++ b/tests/decfra-restrict-cursor.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# fill space with E
+printf '\033#8'
+#set color
+printf '\033[46;31;3m'
+# restrict cursor
+printf '\033[?6h'
+# set top/bottom margins:
+printf '\033[10;20r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;15s'
+# fill larger rect with @
+printf '\033[64;2;3;23;20$x'
+# change color
+printf '\033[0m\033[45;32;1m'
+# top left corner with [
+printf '\033[91;3;5;12;7$x'
+# top right corner with ]
+printf '\033[93;8;12;13;17$x'
+# bottom left corner with (
+printf '\033[40;18;3;22;8$x'
+# top right corner with )
+printf '\033[41;17;14;23;18$x'
+# change color
+printf '\033[0m\033[44;33;4m'
+# one in center with #
+printf '\033[35;12;12;12;12$x'
+
+# cursor to 0,0
+printf '\033[H'
+echo '--------------------------------------------------'
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..d1750cf
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,169 @@
+#!/bin/sh
+set -e
+set -u
+
+TYTEST="../build/src/bin/tytest"
+RESULTS="tests.results"
+TESTDIR="."
+VERBOSE=0
+DEBUG=0
+EXIT_ON_FAILURE=0
+NB_TESTS=0
+OK_TESTS=0
+FAILED_TESTS=0
+
+die()
+{
+    echo "$*" 1>&2
+    exit 1
+}
+ESC="\033"
+GREEN="${ESC}[32m"
+BOLD_RED="${ESC}[31;1m"
+RESET_COLOR="${ESC}[0m"
+
+ok()
+{
+    TEST=$1
+    OK_TESTS=$((OK_TESTS + 1))
+    if [ $VERBOSE -ne 0 ]; then
+        printf "${GREEN}✔${RESET_COLOR}\n"
+    fi
+}
+
+failed()
+{
+    TEST=$1
+    FAILED_TESTS=$((FAILED_TESTS + 1))
+    if [ $VERBOSE -ne 0 ]; then
+        printf "${BOLD_RED}✘${RESET_COLOR}\n"
+    fi
+    if [ $EXIT_ON_FAILURE -ne 0 ]; then
+        exit 1
+    fi
+}
+
+summary()
+{
+    if [ $VERBOSE -ne 0 ]; then
+        if [ $FAILED_TESTS -ne 0 ]; then
+            printf "$BOLD_RED=== $OK_TESTS/$NB_TESTS tests passed, 
$FAILED_TESTS tests failed ===$RESET_COLOR\n"
+        else
+            printf "$GREEN=== $OK_TESTS/$NB_TESTS tests passed 
===$RESET_COLOR\n"
+        fi
+    fi
+
+    if [ $FAILED_TESTS -ne 0 ]; then
+        exit 1
+    fi
+}
+
+show_help()
+{
+    cat <<HELP_EOF
+Usage:
+
+   $0 [options]
+
+where options are:
+
+  -t, --tytest=PATH        Path to the tytest binary
+  -r, --results=PATH       Path to the result file
+  -d, --testdir=PATH       Path to the test files
+  -e, --exitonfailure      Exit as soon as a test fails
+
+Misc options:
+  -v, --verbose            Be verbose about what is being done.
+  --debug                  Debug tests
+  -h, --help               Show this help.
+HELP_EOF
+}
+
+while [ $# -gt 0 ]; do
+    arg=$1
+    shift
+    option=$(echo "'$arg'" | cut -d'=' -f1 | tr -d "'")
+    value=$(echo "'$arg'" | cut -d'=' -f2- | tr -d "'")
+    if [ x"$value" = x"$option" ]; then
+        value=""
+    fi
+
+    case $option in
+        -h|-help|--help)
+            show_help
+            exit 0
+            ;;
+        -v|-verbose|--verbose)
+            VERBOSE=1
+            ;;
+        -debug|--debug)
+            DEBUG=1
+            ;;
+        -t|-tytest|--tytest)
+            if [ -z "$value" ]; then
+                value=$1
+                shift
+            fi
+            TYTEST=$value
+            ;;
+        -r|-results|--results)
+            if [ -z "$value" ]; then
+                value=$1
+                shift
+            fi
+            RESULTS=$value
+            ;;
+        -d|-testdir|--testdir)
+            if [ -z "$value" ]; then
+                value=$1
+                shift
+            fi
+            TESTDIR=$value
+            ;;
+        -e|-exitonfailure|--exitonfailure)
+            EXIT_ON_FAILURE=1
+            ;;
+        *)
+            echo "Unknown option: $option" 1>&2
+            ;;
+    esac
+done
+
+if [ ! -x "$TYTEST" ]; then
+    die "Invalid tytest binary file: $TYTEST"
+fi
+if [ ! -r "$RESULTS" ]; then
+    die "Invalid results file: $RESULTS"
+fi
+if [ ! -d "$TESTDIR" ]; then
+    die "Invalid test directory: $TESTDIR"
+fi
+
+if [ $DEBUG -ne 0 ]; then
+    cat <<EOF
+Using:
+
+   TYTEST=$TYTEST
+   RESULTS=$RESULTS
+   TESTDIR=$TESTDIR
+   EXIT_ON_FAILURE=$EXIT_ON_FAILURE
+
+EOF
+fi
+
+while read -r TEST EXPECTED_CHECKSUM; do
+    NB_TESTS=$((NB_TESTS + 1))
+    if [ $VERBOSE -ne 0 ]; then
+        printf "%s... " "$TEST"
+    fi
+    TEST_CHECKSUM=$("$TESTDIR"/"$TEST" | "$TYTEST")
+    if [ $DEBUG -ne 0 ]; then
+        printf "(got %s, expected %s) " "$TEST_CHECKSUM" "$EXPECTED_CHECKSUM"
+    fi
+    if [ "$TEST_CHECKSUM" = "$EXPECTED_CHECKSUM" ]; then
+        ok "$TEST"
+    else
+        failed "$TEST"
+    fi
+done < "$RESULTS"
+summary
diff --git a/tests/tests.results b/tests/tests.results
new file mode 100644
index 0000000..2428284
--- /dev/null
+++ b/tests/tests.results
@@ -0,0 +1,2 @@
+decfra-no-restrict-cursor.sh 433641ae9b98af9dac2b8da49e1ae321
+decfra-restrict-cursor.sh ebc4be442e89e6e70d1783063429c004

-- 


Reply via email to