Use released rdlink for testing and build it if missing

This commit is contained in:
2022-03-22 10:54:22 +01:00
parent 24cd62e720
commit 3fcfe89c19
2 changed files with 16 additions and 14 deletions

View File

@@ -17,8 +17,9 @@
# Internal tests will be executed if no arguments are found # Internal tests will be executed if no arguments are found
readonly test_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" readonly test_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
readonly tool_rdlink="${test_dir}/../rdlink.sh" readonly tool_rdlink="${test_dir}/../release/rdlink.sh"
readonly tool_readlink="$(command -v readlink) -f --" readonly tool_readlink="$(command -v readlink) -f --"
readonly build_cmd="${test_dir}/../build.sh"
readonly config_path_width=45 readonly config_path_width=45
@@ -163,6 +164,8 @@ rl::test() {
esac esac
done done
[[ ! -e "${tool_rdlink}" ]] && "${build_cmd}"
# Cmd line arguments # Cmd line arguments
(( ! flag_onlycompete )) && [[ ! "$@" ]] && toassert_init (( ! flag_onlycompete )) && [[ ! "$@" ]] && toassert_init
@@ -183,13 +186,12 @@ rl::test() {
# Save first element for string compare # Save first element for string compare
firstelement="${path}" firstelement="${path}"
# Check for excludes
elif excludemsg="$(toexclude "${firstelement}")"; then elif excludemsg="$(toexclude "${firstelement}")"; then
# Current path is excluded
(( tests_skipped++ )) (( tests_skipped++ ))
rl::printPath "$(( i/2 ))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}" rl::printPath "$(( i/2 ))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
# Execute tests
else else
# Do the compare between two following elements # Execute test case
if ! rl::testcmp "$(( i/2 ))" "${firstelement}" \ if ! rl::testcmp "$(( i/2 ))" "${firstelement}" \
"${path}" "$($tool_rdlink -- "${firstelement}")"; then "${path}" "$($tool_rdlink -- "${firstelement}")"; then
(( tests_failed++ )) (( tests_failed++ ))
@@ -206,16 +208,16 @@ rl::test() {
(( testend )) && break (( testend )) && break
done done
(( testend )) && rl::printTestSummary $tests_success $tests_failed $tests_skipped && return 1 (( testend )) && rl::printTestSummary $tests_success $tests_failed $tests_skipped && return 1
# Initialize competition tests # Initialize competition tests
(( ! flag_onlyassert )) && tocompete_init (( ! flag_onlyassert )) && tocompete_init
# Only run `compete_args` if arguments are available # Only run `compete_args` if arguments are available
if [[ "$@" ]]; then if [[ "$@" ]]; then
compete_args=( "Tests from command line" "$@" ) compete_args=( "Tests from command line" "$@" )
tocompete=(compete_args) tocompete=(compete_args)
fi fi
# Compare output of rdlink and readlink -f # Compare output of rdlink and readlink -f
if (( ${#tocompete[@]} )) ; then if (( ${#tocompete[@]} )) ; then
printf "\n# Competition tests (readlink -f == rdlink)\n" printf "\n# Competition tests (readlink -f == rdlink)\n"
@@ -231,13 +233,13 @@ rl::test() {
(( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "<INPUT>" "<EXPECTED>" "✗ [ACTUAL]" (( ! flag_extendedOutput )) && printf "%${config_path_width}s %s %s\n" "<INPUT>" "<EXPECTED>" "✗ [ACTUAL]"
else else
# Check for excludes
if excludemsg="$(toexclude "${path}")" ; then if excludemsg="$(toexclude "${path}")" ; then
# Current path is excluded
(( tests_skipped++ )) (( tests_skipped++ ))
rl::printPath "${i}" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}" rl::printPath "${i}" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
# Execute tests
elif ! rl::testcmp "${i}" "${path}" \ elif ! rl::testcmp "${i}" "${path}" \
"$(${tool_readlink} "$path")" "$(${tool_rdlink} -- "$path")"; then "$(${tool_readlink} "$path")" "$(${tool_rdlink} -- "$path")"; then
# Test case failed
(( tests_failed++ )) (( tests_failed++ ))
# Run all tests if option -a is pressend # Run all tests if option -a is pressend
(( ! $flag_runall )) && testend=1 && break (( ! $flag_runall )) && testend=1 && break
@@ -250,7 +252,7 @@ rl::test() {
done done
(( testend )) && break (( testend )) && break
done done
rl::printTestSummary $tests_success $tests_failed $tests_skipped rl::printTestSummary $tests_success $tests_failed $tests_skipped
(( testend )) && return 1 || return 0 (( testend )) && return 1 || return 0
} }

View File

@@ -30,7 +30,7 @@ compete_relative=( "Resolving of relative links"
# Valid # Valid
"dir_1/file" # Valid relative link to path with relative element "dir_1/file" # Valid relative link to path with relative element
) )
compete_all=( "Test - everything starting from /" compete_all=( "Test - everything starting from /"
/**/* /**/*
) )
@@ -51,7 +51,7 @@ tocompete_init() {
touch "dir_2/dir_22/file" touch "dir_2/dir_22/file"
ln -s "dir_2/dir_22" "dir_3_l" ln -s "dir_2/dir_22" "dir_3_l"
ln -s "../dir_3_l/file" "dir_1/file" ln -s "../dir_3_l/file" "dir_1/file"
# compete_no_permission # compete_no_permission
mkdir -p "${_tc_tmp}/noperm" mkdir -p "${_tc_tmp}/noperm"
chmod 400 "${_tc_tmp}/noperm" chmod 400 "${_tc_tmp}/noperm"
@@ -62,11 +62,11 @@ tocompete_init() {
# compete_relative # compete_relative
ln -s "../nofile" "${_tc_tmp}/nofile_l" ln -s "../nofile" "${_tc_tmp}/nofile_l"
ln -s "../nodir/nofile" "${_tc_tmp}/nopath_l" ln -s "../nodir/nofile" "${_tc_tmp}/nopath_l"
#echo "rl: " && readlink "${_tc_tmp}/lnoperm" #echo "rl: " && readlink "${_tc_tmp}/lnoperm"
#ls -l "${_tc_tmp}" #ls -l "${_tc_tmp}"
} }
# Base directory for the test # Base directory for the test
cd "${_tc_tmp}" cd "${_tc_tmp}"