Adding title, rdlink version and test date to the report
Report without color when piped
This commit is contained in:
@@ -19,15 +19,17 @@
|
||||
readonly test_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
||||
readonly tool_rdlink="${test_dir}/../rdlink.sh"
|
||||
readonly tool_readlink="$(command -v readlink) -f --"
|
||||
readonly tool_rdlink_version="$(git describe --long --tags --always --dirty)"
|
||||
|
||||
readonly config_path_width=45
|
||||
|
||||
readonly color_red='\033[1;31m'
|
||||
readonly color_yellow='\033[1;33m'
|
||||
readonly color_green='\033[1;32m'
|
||||
readonly color_blue='\033[1;34m'
|
||||
readonly color_less='\033[0m'
|
||||
color_red= ; [ -t 1 ] && color_red='\033[1;31m'
|
||||
color_yellow= ; [ -t 1 ] && color_yellow='\033[1;33m'
|
||||
color_green= ; [ -t 1 ] && color_green='\033[1;32m'
|
||||
color_blue= ; [ -t 1 ] && color_blue='\033[1;34m'
|
||||
color_less= ; [ -t 1 ] && color_less='\033[0m'
|
||||
|
||||
flag_title=0
|
||||
flag_runall=0
|
||||
flag_extendedOutput=0
|
||||
flag_verbose=0
|
||||
@@ -40,6 +42,149 @@ tocompete=()
|
||||
|
||||
. "${test_dir}/totest.sh"
|
||||
|
||||
rl::test() {
|
||||
local i=0
|
||||
local path=
|
||||
local arraywalker=
|
||||
local firstelement=
|
||||
local testend=0
|
||||
local arg=
|
||||
local excludemsg=
|
||||
local tests_success=0
|
||||
local tests_failed=0
|
||||
local tests_skipped=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$1" in
|
||||
--) ## End of options
|
||||
shift && break ;;
|
||||
-a|--run-all) ## Run all even if tests fail
|
||||
flag_runall=1
|
||||
shift ;;
|
||||
-x|--extended-output)
|
||||
flag_extendedOutput=1
|
||||
shift ;;
|
||||
-xd|--verbose)
|
||||
flag_extendedOutput=1
|
||||
flag_verbose=1
|
||||
shift ;;
|
||||
-oa|--only-assert)
|
||||
flag_onlyassert=1
|
||||
shift ;;
|
||||
-oc|--only-compete)
|
||||
flag_onlycompete=1
|
||||
shift ;;
|
||||
-e|--error)
|
||||
flag_printerror=1
|
||||
shift ;;
|
||||
-*|--*)
|
||||
printf "Invalid argument\n"
|
||||
exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if assertion tests need to be performed
|
||||
(( ! flag_onlycompete )) && [[ ! "$@" ]] && toassert_init
|
||||
|
||||
# Compare against expected result
|
||||
if (( ${#toassert[@]} )) ; then
|
||||
rl::printTitle
|
||||
printf "\n## Assertion tests (\"Expected path\" == rdlink)\n"
|
||||
fi
|
||||
for testarray in "${toassert[@]}"; do
|
||||
i=0
|
||||
arraywalker="$testarray"[@]
|
||||
for path in "${!arraywalker}"; do
|
||||
if (( ! i )); then
|
||||
# Print title in array element 0
|
||||
printf "### %b\n" "${color_yellow}${path}${color_less}"
|
||||
(( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "<INPUT>" "<EXPECTED>" "✗ [ACTUAL]"
|
||||
|
||||
elif [ -z "$firstelement" ]; then
|
||||
# Save first element for string compare
|
||||
firstelement="${path}"
|
||||
|
||||
elif excludemsg="$(toexclude "${firstelement}")"; then
|
||||
# Current path is excluded
|
||||
(( tests_skipped++ ))
|
||||
rl::printPath "$(( i/2 ))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
||||
else
|
||||
# Execute test case
|
||||
if ! rl::testcmp "$(( i/2 ))" "${firstelement}" \
|
||||
"${path}" "$($tool_rdlink -- "${firstelement}")"; then
|
||||
(( tests_failed++ ))
|
||||
# Run all tests if option -a is pressend
|
||||
(( ! $flag_runall )) && testend=1 && break
|
||||
else
|
||||
(( tests_success++ ))
|
||||
fi
|
||||
|
||||
firstelement=
|
||||
fi
|
||||
((i++))
|
||||
done
|
||||
(( testend )) && break
|
||||
done
|
||||
(( testend )) && rl::printTestSummary $tests_success $tests_failed $tests_skipped && return 1
|
||||
|
||||
# Initialize competition tests
|
||||
(( ! flag_onlyassert )) && tocompete_init
|
||||
|
||||
# Only run `compete_args` if arguments are available
|
||||
if [[ "$@" ]]; then
|
||||
compete_args=( "Tests from command line" "$@" )
|
||||
tocompete=(compete_args)
|
||||
fi
|
||||
|
||||
# Compare output of rdlink and readlink -f
|
||||
if (( ${#tocompete[@]} )) ; then
|
||||
rl::printTitle
|
||||
printf "\n## Competition tests (readlink -f == rdlink)\n"
|
||||
fi
|
||||
for testarray in "${tocompete[@]}"; do
|
||||
i=0
|
||||
arraywalker="$testarray"[@]
|
||||
for path in "${!arraywalker}"; do
|
||||
|
||||
if (( ! i )); then
|
||||
# Print title in array element 0
|
||||
printf "### %b\n" "${color_yellow}${path}${color_less}"
|
||||
(( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "<INPUT>" "<EXPECTED>" "✗ [ACTUAL]"
|
||||
|
||||
else
|
||||
if excludemsg="$(toexclude "${path}")" ; then
|
||||
# Current path is excluded
|
||||
(( tests_skipped++ ))
|
||||
rl::printPath "${i}" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
||||
elif ! rl::testcmp "${i}" "${path}" \
|
||||
"$(${tool_readlink} "$path")" "$(${tool_rdlink} -- "$path")"; then
|
||||
# Test case failed
|
||||
(( tests_failed++ ))
|
||||
# Run all tests if option -a is pressend
|
||||
(( ! $flag_runall )) && testend=1 && break
|
||||
else
|
||||
(( tests_success++ ))
|
||||
fi
|
||||
fi
|
||||
|
||||
((i++))
|
||||
done
|
||||
(( testend )) && break
|
||||
done
|
||||
|
||||
rl::printTestSummary $tests_success $tests_failed $tests_skipped
|
||||
(( testend )) && return 1 || return 0
|
||||
}
|
||||
|
||||
rl::printTitle() {
|
||||
(( flag_title )) && return 0
|
||||
flag_title=1
|
||||
|
||||
# See if some tests will be performed
|
||||
printf "# Testing rdlink version %s\n" "${tool_rdlink_version}"
|
||||
printf " Testdate: %s\n" "$(date -u +"%Y-%m-%d %H:%M:%S UTC")"
|
||||
}
|
||||
|
||||
rl::printPath() {
|
||||
local testnum="${1:-0}"
|
||||
local input="${2:-"-"}"
|
||||
@@ -126,137 +271,5 @@ rl::testcmp() {
|
||||
return 0
|
||||
}
|
||||
|
||||
rl::test() {
|
||||
local i=0
|
||||
local path=
|
||||
local arraywalker=
|
||||
local firstelement=
|
||||
local testend=0
|
||||
local arg=
|
||||
local excludemsg=
|
||||
local tests_success=0
|
||||
local tests_failed=0
|
||||
local tests_skipped=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$1" in
|
||||
--) ## End of options
|
||||
shift && break ;;
|
||||
-a|--run-all) ## Run all even if tests fail
|
||||
flag_runall=1
|
||||
shift ;;
|
||||
-x|--extended-output)
|
||||
flag_extendedOutput=1
|
||||
shift ;;
|
||||
-xd|--verbose)
|
||||
flag_extendedOutput=1
|
||||
flag_verbose=1
|
||||
shift ;;
|
||||
-oa|--only-assert)
|
||||
flag_onlyassert=1
|
||||
shift ;;
|
||||
-oc|--only-compete)
|
||||
flag_onlycompete=1
|
||||
shift ;;
|
||||
-e|--error)
|
||||
flag_printerror=1
|
||||
shift ;;
|
||||
-*|--*)
|
||||
printf "Invalid argument\n"
|
||||
exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Cmd line arguments
|
||||
(( ! flag_onlycompete )) && [[ ! "$@" ]] && toassert_init
|
||||
|
||||
# Compare against expected result
|
||||
if (( ${#toassert[@]} )) ; then
|
||||
printf "\n# Assertion tests (\"Expected path\" == rdlink)\n"
|
||||
fi
|
||||
for testarray in "${toassert[@]}"; do
|
||||
i=0
|
||||
arraywalker="$testarray"[@]
|
||||
for path in "${!arraywalker}"; do
|
||||
if (( ! i )); then
|
||||
# Print title in array element 0
|
||||
printf " ### %b ###\n" "${color_yellow}${path}${color_less}"
|
||||
(( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "<INPUT>" "<EXPECTED>" "✗ [ACTUAL]"
|
||||
|
||||
elif [ -z "$firstelement" ]; then
|
||||
# Save first element for string compare
|
||||
firstelement="${path}"
|
||||
|
||||
elif excludemsg="$(toexclude "${firstelement}")"; then
|
||||
# Current path is excluded
|
||||
(( tests_skipped++ ))
|
||||
rl::printPath "$(( i/2 ))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
||||
else
|
||||
# Execute test case
|
||||
if ! rl::testcmp "$(( i/2 ))" "${firstelement}" \
|
||||
"${path}" "$($tool_rdlink -- "${firstelement}")"; then
|
||||
(( tests_failed++ ))
|
||||
# Run all tests if option -a is pressend
|
||||
(( ! $flag_runall )) && testend=1 && break
|
||||
else
|
||||
(( tests_success++ ))
|
||||
fi
|
||||
|
||||
firstelement=
|
||||
fi
|
||||
((i++))
|
||||
done
|
||||
(( testend )) && break
|
||||
done
|
||||
(( testend )) && rl::printTestSummary $tests_success $tests_failed $tests_skipped && return 1
|
||||
|
||||
# Initialize competition tests
|
||||
(( ! flag_onlyassert )) && tocompete_init
|
||||
|
||||
# Only run `compete_args` if arguments are available
|
||||
if [[ "$@" ]]; then
|
||||
compete_args=( "Tests from command line" "$@" )
|
||||
tocompete=(compete_args)
|
||||
fi
|
||||
|
||||
# Compare output of rdlink and readlink -f
|
||||
if (( ${#tocompete[@]} )) ; then
|
||||
printf "\n# Competition tests (readlink -f == rdlink)\n"
|
||||
fi
|
||||
for testarray in "${tocompete[@]}"; do
|
||||
i=0
|
||||
arraywalker="$testarray"[@]
|
||||
for path in "${!arraywalker}"; do
|
||||
|
||||
if (( ! i )); then
|
||||
# Print title in array element 0
|
||||
printf " ### %b ###\n" "${color_yellow}${path}${color_less}"
|
||||
(( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "<INPUT>" "<EXPECTED>" "✗ [ACTUAL]"
|
||||
|
||||
else
|
||||
if excludemsg="$(toexclude "${path}")" ; then
|
||||
# Current path is excluded
|
||||
(( tests_skipped++ ))
|
||||
rl::printPath "${i}" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
||||
elif ! rl::testcmp "${i}" "${path}" \
|
||||
"$(${tool_readlink} "$path")" "$(${tool_rdlink} -- "$path")"; then
|
||||
# Test case failed
|
||||
(( tests_failed++ ))
|
||||
# Run all tests if option -a is pressend
|
||||
(( ! $flag_runall )) && testend=1 && break
|
||||
else
|
||||
(( tests_success++ ))
|
||||
fi
|
||||
fi
|
||||
|
||||
((i++))
|
||||
done
|
||||
(( testend )) && break
|
||||
done
|
||||
|
||||
rl::printTestSummary $tests_success $tests_failed $tests_skipped
|
||||
(( testend )) && return 1 || return 0
|
||||
}
|
||||
|
||||
#time rl::test "$@"
|
||||
rl::test "$@"
|
||||
|
@@ -53,9 +53,9 @@ tocompete_init() {
|
||||
ln -s "../dir_3_l/file" "dir_1/file"
|
||||
|
||||
# compete_no_permission
|
||||
mkdir -p "${_tc_tmp}/noperm"
|
||||
chmod 400 "${_tc_tmp}/noperm"
|
||||
ln -s "noperm" "${_tc_tmp}/noperml"
|
||||
mkdir -p "${_tc_tmp}/nopermdir"
|
||||
chmod 400 "${_tc_tmp}/nopermdir"
|
||||
ln -s "nopermdir" "${_tc_tmp}/nopermdirl"
|
||||
ln -s "/" "${_tc_tmp}/lroot"
|
||||
ln -s "/root" "${_tc_tmp}/lroothome"
|
||||
|
||||
@@ -95,14 +95,14 @@ tocompete_init() {
|
||||
)
|
||||
|
||||
compete_no_permission=( "No permission to enter directory (direct and link)"
|
||||
"noperm"*
|
||||
"nopermdir"*
|
||||
"lroot"*
|
||||
"/"
|
||||
"/root"
|
||||
"/root/"
|
||||
"/root/."
|
||||
"/root/.."
|
||||
"/proc/"**/cwd # special - no permission for links
|
||||
#"/proc/"**/cwd # special - no permission for links
|
||||
)
|
||||
|
||||
# Add tests to global test array from test_rdlink
|
||||
@@ -112,7 +112,7 @@ tocompete_init() {
|
||||
compete_relative
|
||||
compete_no_permission
|
||||
compete_links
|
||||
compete_all
|
||||
#compete_all
|
||||
)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user