Initial main skeleton with a single example
authorMyungJoo Ham <myungjoo.ham@gmail.com>
Sat, 23 Jun 2018 07:53:54 +0000 (16:53 +0900)
committerMyungJoo Ham <myungjoo.ham@gmail.com>
Sat, 23 Jun 2018 07:53:54 +0000 (16:53 +0900)
The first code commit with structure skeleton.

Signed-off-by: MyungJoo Ham <myungjoo.ham@gmail.com>
exampleCase/group1A/runTest.sh [new file with mode: 0755]
ssat-api.sh [new file with mode: 0644]
ssat.sh [new file with mode: 0755]

diff --git a/exampleCase/group1A/runTest.sh b/exampleCase/group1A/runTest.sh
new file mode 100755 (executable)
index 0000000..f9dbb18
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+echo $SSATAPILOADED
+
+if [ "$SSATAPILOADED" == "1" ]
+then
+       echo "Loaded"
+else
+       echo "Not Loaded"
+fi
+
+report ${passed} ${total}
diff --git a/ssat-api.sh b/ssat-api.sh
new file mode 100644 (file)
index 0000000..543519e
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/env bash
+##
+# @file ssat-api.sh
+# @author MyungJoo Ham <myungjoo.ham@gmail.com>
+# @date Jun 22 2018
+# @license Apache-2.0
+# @brief This is API set for SSAT (Shell Script Automated Tester)
+#
+
+Black='\033[0;30m'
+DarkGray='\033[1;30m'
+Red='\033[0;31m'
+LightRed='\033[1;31m'
+Green='\033[0;32m'
+LightGreen='\033[1;32m'
+Orange='\033[0;33m'
+Yellow='\033[1;33m'
+Blue='\033[0;34m'
+LightBlue='\033[1;34m'
+Purple='\033[0;35m'
+LightPurple='\033[1;35m'
+Cyan='\033[0;36m'
+LightCyan='\033[1;36m'
+LightGray='\033[0;37m'
+White='\033[1;37m'
+NC='\033[0m'
+
+##
+# @brief Report results of a test group (a "runTest.sh" in a testee directory)
+# @param $1 # total test cases
+# @param $2 # total success cases
+# @param $3 # test log
+# @param $4 # print outs from test (stdout)
+#
+function report {
+       echo NYI
+}
+
+##
+# @brief Write Test Log
+# @param $1 1 = success / 0 = fail
+# @param $2 test case ID (short string)
+# @param $3 test case description
+function testResult {
+       echo NYI
+}
+
+##
+# @brief Call Test Case (a shell script), expected exit = 0
+# @param $1 Full path to the executable (e.g., ~/script/a1.sh)
+# @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
+# @param $3 test case ID
+# @param $4 test case description
+function callTestSuccess {
+       echo NYI
+}
+
+##
+# @brief Call Test Case (a shell script), expected exit != 0
+# @param $1 Full path to the executable (e.g., ~/script/a1.sh)
+# @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
+# @param $3 test case ID
+# @param $4 test case description
+function callTestFail {
+       echo NYI
+}
+
+##
+# @brief Call Test Case (a shell script), expected exit == $5
+# @param $1 Full path to the executable (e.g., ~/script/a1.sh)
+# @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
+# @param $3 test case ID
+# @param $4 test case description
+# @param $5 Expected exit code.
+function callTestExitEq {
+       echo NYI
+}
+
+##
+# @brief Compare two result files expected to be equal
+# @param $1 Path to result 1 (golden)
+# @param $2 Path to result 2 (test run)
+# @param $3 test case ID
+# @param $4 test case description
+# @param $5 0 if the size is expected to be equal as well. 1 if golden (result 1) might be smaller (will ignore rest of result 2). 2 if the opposite of 1. If $5 > 2, it denotes the max size of compared bytes. (compare the first $5 bytes only)
+function callCompareTest {
+       echo NYI
+}
+
+SSATAPILOADED=1
diff --git a/ssat.sh b/ssat.sh
new file mode 100755 (executable)
index 0000000..dc5c3bd
--- /dev/null
+++ b/ssat.sh
@@ -0,0 +1,78 @@
+#!/usr/bin/env bash
+##
+# @file ssat.sh
+# @author MyungJoo Ham <myungjoo.ham@gmail.com>
+# @date Jun 22 2018
+# @license Apache-2.0
+# @brief This executes test groups and reports aggregated test results.
+# @exit 0 if all PASSED. Positive if some FAILED.
+#
+# If there is no arguments specified, this will search for all "runTest.sh" in
+# the subdirectory of this file and regard them as the test groups.
+#
+# If --help or -h is given, this will show detailed description.
+
+TARGET=$(pwd)
+BASEPATH=`dirname "$0"`
+BASENAME=`basename "$0"`
+TESTCASE="runTest.sh"
+source ${BASEPATH}/ssat-api.sh
+
+#
+DOTEST=1
+SILENT=1
+
+# Handle arguments
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+       key="$1"
+       case $key in
+       -h|--help)
+               printf "usage: ${BASENAME} [--help] [<path>] [--testcase <filename>]\n\n"
+               printf "These are common ${Red}ssat${NC} commands used:\n\n"
+               printf "Test all test-groups in the current ($(pwd)) directory, recursively\n"
+               printf "    (no options specified)\n"
+               printf "    $ ${BASENAME}\n"
+               printf "\n"
+               printf "Test all test-groups in the specified directory, recursively\n"
+               printf "    <path>\n"
+               printf "    $ ${BASENAME} /home/username/test\n"
+               printf "    If there are multiple paths, the last one will be used\n"
+               printf "\n"
+               printf "Search for \"filename\" as the testcase scripts\n"
+               printf "    --testcase or -t\n"
+               printf "    $ ${BASENAME} --testcase cases.sh\n"
+               printf "    Search for cases.sh instead of runTest.sh\n"
+               printf "\n"
+               printf "Shows this message\n"
+               printf "    --help or -h\n"
+               printf "    $ ${BASENAME} --help \n"
+               printf "\n\n"
+               exit 0
+       ;;
+       -t|--testcase)
+       TESTCASE="$2"
+       shift
+       shift
+       ;;
+       *) # Unknown, which is probably target (the path to root-dir of test groups).
+       TARGET="$1"
+       esac
+done
+
+if [[ ${#TARGET} -eq 0 ]]
+then
+       TARGET="."
+fi
+
+find $TARGET -name $TESTCASE -print0 | while read -d $'\0' file
+do
+       CASEBASEPATH=`dirname "$file"`
+       pushd $CASEBASEPATH
+       source $file
+       popd
+done
+               
+
+# gather reports & publish them.