From 3531d1b12f843606a7d7096c2a843c07b36f02a6 Mon Sep 17 00:00:00 2001 From: Zouhair AMAZZAL Date: Wed, 7 Dec 2022 14:41:48 +0100 Subject: [PATCH] test(json-researcher): check if the submitted file name is correct --- sh/tests/json-researcher_test.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sh/tests/json-researcher_test.sh b/sh/tests/json-researcher_test.sh index c83d80943..20957d1c6 100755 --- a/sh/tests/json-researcher_test.sh +++ b/sh/tests/json-researcher_test.sh @@ -5,12 +5,20 @@ set -euo pipefail IFS=' ' -echo insecure >> ~/.curlrc -caddy start &>/dev/null +FILENAME="student/json-researcher.sh" -submitted=$(bash student/json-researcher.sh) -expected=$(bash solutions/json-researcher.sh) - -caddy stop &>/dev/null - -diff <(echo "$submitted") <(echo "$expected") +# True if FILE exists and is a regular file +if [ -f ${FILENAME} ]; then + # FILE exists and it's not empty + if [ -s ${FILENAME} ]; then + submitted=$(bash $FILENAME) + expected=$(bash solutions/json-researcher.sh) + diff <(echo "$submitted") <(echo "$expected") + else + echo "The file exist but is empty" + exit 1 + fi +else + echo "File does not exist" + exit 1 +fi \ No newline at end of file