| # ---- TEST RESULTS ---- |
| |
| RESULT=0 |
| |
| result() { # test [error_message] |
| local result=$? |
| local outcome="FAIL" |
| if [ $result -eq 0 ] ; then |
| echo "PASSED - $1 test" |
| outcome="PASS" |
| else |
| echo "*** FAILED *** - $1 test" |
| RESULT=$result |
| [ $# -gt 1 ] && echo "$2" |
| fi |
| } |
| |
| # actual output must match expected to pass |
| result_out() { # test expected actual |
| local disp=$(echo "Expected Output:" ;\ |
| echo " $2" ;\ |
| echo "Actual Output:" ;\ |
| echo " $3") |
| |
| [ "$2" = "$3" ] |
| result "$1" "$disp" |
| } |
| |
| result_sortize_json() { # json |
| local json=$(echo "$1" | jq --indent 3 --sort-keys 2> /dev/null) |
| [ $? -ne 0 ] && json=$1 |
| echo "$json" |
| } |
| |
| result_out_json() { # test expected_json actual_json |
| local expected=$(result_sortize_json "$2") actual=$(result_sortize_json "$3") |
| result_out "$1" "$expected" "$actual" "Sorted JSON" |
| } |