diff --git a/test/test_rdlink.sh b/test/test_rdlink.sh index 120c92e..62d3d98 100755 --- a/test/test_rdlink.sh +++ b/test/test_rdlink.sh @@ -7,8 +7,9 @@ # test_rdlink.sh [OPTIONS] [PATH TO COMPETE] # [OPTIONS] -# -a, --run-all : Run all tests (failed and successful) -# -o, --only-result : Show only result (input <> expected) +# -a, --run-all : Run all tests (failed and successful) +# -x, --extended-output : Show more information for each test +# -xd : set -x and also show rdlink debug run for failed tests # # Internal tests will be executed if no arguments are found @@ -24,7 +25,7 @@ readonly color_green='\033[1;32m' readonly color_less='\033[0m' flag_runall=0 -flag_onlyresult=0 +flag_extendedOutput=0 flag_verbose=0 toassert=() @@ -41,38 +42,39 @@ rl::testcmp() { local actual="${4:-"-"}" local testresult=0 #failed local testresult_graphic="${color_red}✗${color_less}" # alt. symbol ≠ + local truncate_graphic= [[ "${expect}" == "${actual}" ]] && testresult=1 && testresult_graphic="${color_green}✔${color_less}" # alt. symbol ✓ # Show only reslult as quick overview - if (( flag_onlyresult )); then - # Change result graphic if test failed - (( ! testresult )) && testresult_graphic="→" # "${color_green}→${color_less}" - # Truncate input string on the left if longer than $config_path_width - (( ${#input} > ${config_path_width} )) && input="<-${input:$(( ${#input} - ${config_path_width} + 2 ))}" - # Print input and expected - printf "%${config_path_width}s %b %s\n" "${input}" "${testresult_graphic}" "${expect}" - # Print actual result if test failed + if (( flag_extendedOutput )); then + printf -- "%-3d Inp: %-${config_path_width}s ---" ${testnum} "${input}" + printf " %b\n" "${testresult_graphic}" if (( ! testresult )); then - printf "%$((config_path_width))s %b %s\n" " " "${color_red}✗${color_less}" "${actual}" + # Test failed + printf " Result: %s\n Exp: %s\n" "${actual}" "${expect}" + + if (( flag_verbose )); then + [ -e "${input}" ] && printf "\n Subject:\n" && ls -al "${input}" + + # Print debug output of tool_a + printf "\n Debug:\n" + ( "${tool_rdlink}" -d "${input}" ) + fi return 1 fi return 0 fi - printf -- "%-3d Inp: %-${config_path_width}s ---" ${testnum} "${input}" - printf " %b\n" "${testresult_graphic}" + # Change result graphic if test failed + (( ! testresult )) && testresult_graphic="→" # "${color_green}→${color_less}" + # Truncate input string on the left if longer than $config_path_width + (( ${#input} > ${config_path_width} )) && input="${input:$(( ${#input} - ${config_path_width} + 1 ))}" && truncate_graphic="✀" + # Print input and expected + printf "%b%${config_path_width}s %b %s\n" "${truncate_graphic}" "${input}" "${testresult_graphic}" "${expect}" + # Print actual result if test failed if (( ! testresult )); then - # Test failed - printf " Result: %s\n Exp: %s\n" "${actual}" "${expect}" - - if (( flag_verbose )); then - [ -e "${input}" ] && printf "\n Subject:\n" && ls -al "${input}" - - # Print debug output of tool_a - printf "\n Debug:\n" - ( "${tool_rdlink}" -d "${input}" ) - fi + printf "%$((config_path_width))s %b %s\n" " " "${color_red}✗${color_less}" "${actual}" return 1 fi return 0 @@ -93,10 +95,11 @@ rl::test() { -a|--run-all) ## Run all even if tests fail flag_runall=1 shift ;; - -o|--only-result) - flag_onlyresult=1 + -x|--extended-output) + flag_extendedOutput=1 shift ;; - -v|--verbose) + -xd|--verbose) + flag_extendedOutput=1 flag_verbose=1 shift ;; esac @@ -118,7 +121,7 @@ rl::test() { if (( ! i )); then # Print title in array element 0 printf " ### %b ###\n" "${color_yellow}${path}${color_less}" - (( flag_onlyresult )) && printf "%${config_path_width}s %s %s\n" "" "" "✗ [ACTUAL]" + (( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "" "" "✗ [ACTUAL]" elif [ -z "$firstelement" ]; then # Save first element for string compare @@ -149,7 +152,7 @@ rl::test() { if (( ! i )); then # Print title in array element 0 printf " ### %b ###\n" "${color_yellow}${path}${color_less}" - (( flag_onlyresult )) && printf "%${config_path_width}s %s %s\n" "" "" "✗ [ACTUAL]" + (( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "" "" "✗ [ACTUAL]" else # Execute tests