4 # @author MyungJoo Ham <myungjoo.ham@gmail.com>
7 # @brief This is API set for SSAT (Shell Script Automated Tester)
10 if [[ "$nocolor" != "1" ]]
17 LightGreen='\033[1;32m'
21 LightBlue='\033[1;34m'
23 LightPurple='\033[1;35m'
25 LightCyan='\033[1;36m'
26 LightGray='\033[0;37m'
53 if [[ "${SILENT}" == "0" ]]
57 ResultLog="$ResultLog$1\n"
61 # @brief Report results of a test group (a "runTest.sh" in a testee directory)
64 if (( ${_fail} == 0 ))
66 writef "${Green}==================================================${NC}"
67 writef "${LightGreen}[PASSED]${NC} Test Group $_group ${Green}Passed${NC}"
69 if (( ${_criticalFail} > 0 ))
71 writef "${Green}==================================================${NC}"
72 writef "${Red}[FAILED]${NC} Test Group $_group has ${Red}failed cases ($_fail)${NC}"
74 writef "${Green}==================================================${NC}"
75 writef "${LightGreen}[PASSED]${NC} Test Group $_group has ${Red}failed cases ($_fail), but they are not critical.${NC}"
79 if [[ "$INDEPENDENT" -eq "1" ]]
84 writef "${_cases},${_pass},${_fail}"
85 echo "${ResultLog}" > $_filename
89 if (( ${_criticalFail} > 0 ))
103 _group=`basename "$1"`
104 if [[ "${#_group}" -eq "0" ]]
106 _group="(Unspecified)"
109 writef "${Green}==================================================${NC}"
110 writef " Test Group ${Green}$_group${NC} Starts."
114 # @brief Write Test Log
115 # @param $1 1 = success / 0 = fail
116 # @param $2 test case ID (short string)
117 # @param $3 test case description
118 # @param $4 set 1 if this is not critical (don't care if it's pass or fail)_
119 function testResult {
121 if [[ "${1}" == "1" ]]
123 writef "${LightGreen}[PASSED]${NC} ${Green}$2${NC}:$3${NC}"
127 if [[ "${4}" == "1" ]]
129 writef "${Purple}[FAILED][Ignorable] $2${NC}:${Purple}$3${NC}"
131 writef "${Red}[FAILED][Critical] $2${NC}:${Purple}$3${NC}"
132 _criticalFail=$((_criticalFail+1))
138 # @brief Call Test Case (a shell script), expected exit = 0
139 # @param $1 Full path to the executable (e.g., ~/script/a1.sh)
140 # @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
141 # @param $3 test case ID
142 # @param $4 test case description
143 # @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
144 function callTestSuccess {
147 if (( ${retcode} == 0 ))
149 testResult 1 "$3" "$4" $5
151 testResult 0 "$3" "$4 ret($retcode)" $5
156 # @brief Call Test Case (a shell script), expected exit != 0
157 # @param $1 Full path to the executable (e.g., ~/script/a1.sh)
158 # @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
159 # @param $3 test case ID
160 # @param $4 test case description
161 # @param $5 set 1 if this is not critical (don't care if it's pass or fail)_
162 function callTestFail {
165 if (( ${retcode} != 0 ))
167 testResult 1 "$3" "$4 ret($retcode)" $5
169 testResult 0 "$3" "$4" $5
174 # @brief Call Test Case (a shell script), expected exit == $5
175 # @param $1 Full path to the executable (e.g., ~/script/a1.sh)
176 # @param $2 Full string of the arguments to $1 (e.g., "-q -n --dryrun")
177 # @param $3 test case ID
178 # @param $4 test case description
179 # @param $5 Expected exit code.
180 # @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
181 function callTestExitEq {
184 if (( ${retcode} == $5 ))
186 testResult 1 "$3" "$4" $6
188 testResult 0 "$3" "$4 ret($retcode)" $6
193 # @brief Compare two result files expected to be equal
194 # @param $1 Path to result 1 (golden)
195 # @param $2 Path to result 2 (test run)
196 # @param $3 test case ID
197 # @param $4 test case description
198 # @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)
199 # @param $6 set 1 if this is not critical (don't care if it's pass or fail)_
200 function callCompareTest {
208 # use internal logic (slower!)