#!/bin/bash tool_a="/opt/rdlink/rdlink.sh" tool_b="$(command -v readlink) -f" test_links=( "Valid links" "/dev/stdin" "$HOME/tmp/a"* "$HOME/tmp/a 3" "/bin/adb" ) test_all=( "Test everything starting from /" /**/* ) test_args=( "Tests from command line" "$@" ) totest=( test_links ) [[ "$@" ]] && totest=(test_args) rl::test() { local i=0 local ra= local rb= local path= local testarray= local testend=0 for testarray in "${totest[@]}"; do i=0 testarray="$testarray"[@] for path in "${!testarray}"; do if (( ! i )); then # Print title in array element 0 printf " ### %s ###\n" "$path" else # Execute tests printf -- "%-3d --- %-30s ---" $i "$path" ra="$(${tool_a} "$path")" rb="$(${tool_b} "$path")" if [[ "$ra" = "$rb" ]]; then # Test successful printf " OK\n" else # Test failed printf " FAIL\n" printf "\n Result:\n%s\n%s\n" "$ra" "$rb" printf "\n Subject:\n" ls -al "$path" # Print debug output of tool_a printf "\n Debug:\n" ( "${tool_a}" -d "${path}" ) testend=1 && break fi fi ((i++)) done (( testend )) && break done } time rl::test