diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..838db494 --- /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 00000000..cd32f4e3 --- /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 00000000..ab9a8cca --- /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 00000000..d1750cf3 --- /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 <&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 <