From 187d177659c8e3d9f1ca79e73a8688c62c87bd37 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 17 Feb 2024 08:29:43 -0800 Subject: [PATCH] Improve and modularize 2012/zeitak/try.sh --- 2012/zeitak/test.sh | 161 +++++++++----------------------------------- 1 file changed, 32 insertions(+), 129 deletions(-) diff --git a/2012/zeitak/test.sh b/2012/zeitak/test.sh index 51e81a92f..81ff65b5d 100755 --- a/2012/zeitak/test.sh +++ b/2012/zeitak/test.sh @@ -18,144 +18,47 @@ clear # assume no error: set ERROR to 0 ERROR=0 -read -r -n 1 -p "Press any key to test zeitak.c for nesting errors: " -echo 1>&2 -./zeitak < zeitak.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 3 ]]; then - echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak() +{ + if [[ "$#" != 2 ]]; then + echo "$0: zeitak() expects two args, got: $#" 1>&2 + return + fi -echo "$ cat anonymous.c" 1>&2 -cat anonymous.c -echo 1>&2 -read -r -n 1 -p "Press any key to test anonymous.c for nesting errors: " -echo 1>&2 -./zeitak < anonymous.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 3 ]]; then - echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 + read -r -n 1 -p "Press any key to run show $1 (space = next page, q = quit): " + echo 1>&2 + less -rEXFK "$1" + read -r -n 1 -p "Press any key to test $1 for nesting errors: " + echo 1>&2 + ./zeitak < "$1" + EXIT_CODE="$?" + if [[ "$EXIT_CODE" -ne "$2" ]]; then + echo "Error: did not get exit code $2: $EXIT_CODE" 1>&2 + ERROR=1 + fi + echo 1>&2 +} -echo "$ cat anonymous.alt.c" 1>&2 -cat anonymous.alt.c -echo 1>&2 -read -r -n 1 -p "Press any key to test anonymous.alt.c for nesting errors: " -echo 1>&2 -./zeitak < anonymous.alt.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 3 ]]; then - echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak zeitak.c 3 -echo "$ cat incorrect.brace.c" 1>&2 -cat incorrect.brace.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.brace.c: " -echo 1>&2 -./zeitak < incorrect.brace.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak anonymous.c 3 -echo "$ cat incorrect.bracket.c" 1>&2 -cat incorrect.bracket.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.bracket.c: " -echo 1>&2 -./zeitak < incorrect.bracket.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak anonymous.alt.c 3 -echo "$ cat incorrect.paren.c" 1>&2 -cat incorrect.paren.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.paren.c: " -echo 1>&2 -./zeitak < incorrect.paren.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak incorrect.brace.c 10 -echo "$ cat incorrect.quote-esc.c" 1>&2 -cat incorrect.quote-esc.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.quote-esc.c: " -echo 1>&2 -./zeitak < incorrect.quote-esc.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak incorrect.bracket.c 10 -echo "$ cat incorrect.3.quotes.c" 1>&2 -cat incorrect.3.quotes.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.3.quotes.c: " -echo 1>&2 -./zeitak < incorrect.3.quotes.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak incorrect.paren.c 10 -echo "$ cat incorrect.single.quote.c" 1>&2 -cat incorrect.single.quote.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.single.quote.c: " -echo 1>&2 -./zeitak < incorrect.single.quote.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak incorrect.quote-esc.c 10 -echo "$ cat incorrect.1.quote.c" 1>&2 -cat incorrect.1.quote.c -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.1.quote.c: " -echo 1>&2 -./zeitak < incorrect.1.quote.c -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak incorrect.3.quotes.c 10 -echo "$ cat incorrect.txt" 1>&2 -cat incorrect.txt -echo 1>&2 -read -r -n 1 -p "Press any key to test incorrect.txt: " -echo 1>&2 -./zeitak < incorrect.txt -EXIT_CODE="$?" -if [[ "$EXIT_CODE" -ne 10 ]]; then - echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 - ERROR=1 -fi -echo 1>&2 +zeitak incorrect.single.quote.c 10 + +zeitak incorrect.1.quote.c 10 + +zeitak incorrect.txt 10 exit "$ERROR"