Adding more tests and excludes to be able to traverse through /**/* wihtout error
Added test summary to stdout
This commit is contained in:
@@ -53,6 +53,25 @@ rl::printPath() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rl::printTestSummary() {
|
||||||
|
local success=${1:-0}
|
||||||
|
local failed=${2:-0}
|
||||||
|
local skipped=${3:-0}
|
||||||
|
local total=$(( success + failed + skipped ))
|
||||||
|
local separator="--------------------"
|
||||||
|
|
||||||
|
cat <<TEST_SUMMARY_EOF
|
||||||
|
|
||||||
|
# Test summary:
|
||||||
|
successful: ${success}
|
||||||
|
failed: ${failed}
|
||||||
|
skipped: ${skipped}
|
||||||
|
TEST_SUMMARY_EOF
|
||||||
|
|
||||||
|
printf "%15s-%s\n" "------" "${separator:0:${#total}}"
|
||||||
|
printf "%15s %d\n" "total:" ${total}
|
||||||
|
}
|
||||||
|
|
||||||
# rl::testcmp <TEST NUMBER> <TEST INPUT> <EXPECTED RESULT> <ACTUAL RESULT>
|
# rl::testcmp <TEST NUMBER> <TEST INPUT> <EXPECTED RESULT> <ACTUAL RESULT>
|
||||||
# Compare results and print summary
|
# Compare results and print summary
|
||||||
rl::testcmp() {
|
rl::testcmp() {
|
||||||
@@ -111,6 +130,9 @@ rl::test() {
|
|||||||
local testend=0
|
local testend=0
|
||||||
local arg=
|
local arg=
|
||||||
local excludemsg=
|
local excludemsg=
|
||||||
|
local tests_success=0
|
||||||
|
local tests_failed=0
|
||||||
|
local tests_skipped=0
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@@ -163,22 +185,27 @@ rl::test() {
|
|||||||
|
|
||||||
# Check for excludes
|
# Check for excludes
|
||||||
elif excludemsg="$(toexclude "${firstelement}")"; then
|
elif excludemsg="$(toexclude "${firstelement}")"; then
|
||||||
rl::printPath "$((i-1))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
(( tests_skipped++ ))
|
||||||
|
rl::printPath "$(( i/2 ))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
||||||
# Execute tests
|
# Execute tests
|
||||||
else
|
else
|
||||||
# Do the compare between two following elements
|
# Do the compare between two following elements
|
||||||
if ! rl::testcmp "$((i-1))" "${firstelement}" \
|
if ! rl::testcmp "$(( i/2 ))" "${firstelement}" \
|
||||||
"${path}" "$($tool_rdlink -- "${firstelement}")"; then
|
"${path}" "$($tool_rdlink -- "${firstelement}")"; then
|
||||||
|
(( 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
|
||||||
|
else
|
||||||
|
(( tests_success++ ))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
firstelement=
|
firstelement=
|
||||||
fi
|
fi
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
(( testend )) && return 1
|
(( testend )) && break
|
||||||
done
|
done
|
||||||
|
(( 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
|
||||||
@@ -206,19 +233,26 @@ rl::test() {
|
|||||||
else
|
else
|
||||||
# Check for excludes
|
# Check for excludes
|
||||||
if excludemsg="$(toexclude "${path}")" ; then
|
if excludemsg="$(toexclude "${path}")" ; then
|
||||||
rl::printPath "" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
(( tests_skipped++ ))
|
||||||
|
rl::printPath "${i}" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
|
||||||
# Execute tests
|
# 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
|
||||||
|
(( 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
|
||||||
|
else
|
||||||
|
(( tests_success++ ))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
((i++))
|
((i++))
|
||||||
done
|
done
|
||||||
(( testend )) && return 1
|
(( testend )) && break
|
||||||
done
|
done
|
||||||
|
|
||||||
|
rl::printTestSummary $tests_success $tests_failed $tests_skipped
|
||||||
|
(( testend )) && return 1 || return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#time rl::test "$@"
|
#time rl::test "$@"
|
||||||
|
@@ -40,8 +40,9 @@ tocompete_init() {
|
|||||||
# 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"
|
||||||
ln -s "noperm" "${_tc_tmp}/lnoperm"
|
ln -s "noperm" "${_tc_tmp}/noperml"
|
||||||
ln -s "/" "${_tc_tmp}/lroot"
|
ln -s "/" "${_tc_tmp}/lroot"
|
||||||
|
ln -s "/root" "${_tc_tmp}/lroothome"
|
||||||
|
|
||||||
#echo "rl: " && readlink "${_tc_tmp}/lnoperm"
|
#echo "rl: " && readlink "${_tc_tmp}/lnoperm"
|
||||||
#ls -l "${_tc_tmp}"
|
#ls -l "${_tc_tmp}"
|
||||||
@@ -53,6 +54,12 @@ tocompete_init() {
|
|||||||
# Compete test arrays with "dynamic" cases need to be inside the init function
|
# Compete test arrays with "dynamic" cases need to be inside the init function
|
||||||
# e.g. "$(cd ../test && pwd)/file" - base directory must be set first
|
# e.g. "$(cd ../test && pwd)/file" - base directory must be set first
|
||||||
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
|
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
|
||||||
|
compete_invalid=( "Invalid files with and without valid path"
|
||||||
|
"${_tc_tmp}/invalid_file"
|
||||||
|
"/invalid_file"
|
||||||
|
"/invalid_direcotry/invalidfile"
|
||||||
|
)
|
||||||
|
|
||||||
compete_links=( "Test - Valid links"
|
compete_links=( "Test - Valid links"
|
||||||
"${_tc_tmp}/a 3" # slink chain a3 -> a2 -> a
|
"${_tc_tmp}/a 3" # slink chain a3 -> a2 -> a
|
||||||
"${_tc_tmp}/a"*
|
"${_tc_tmp}/a"*
|
||||||
@@ -62,18 +69,21 @@ tocompete_init() {
|
|||||||
"/dev/stdout" # skip - different output
|
"/dev/stdout" # skip - different output
|
||||||
"/etc/mtab" # skip - Always different
|
"/etc/mtab" # skip - Always different
|
||||||
"/proc/mounts" # skip - Always different
|
"/proc/mounts" # skip - Always different
|
||||||
|
"/proc/net/"* # skip - Always different
|
||||||
)
|
)
|
||||||
|
|
||||||
compete_no_permission=( "No permission to enter directory (direct and link)"
|
compete_no_permission=( "No permission to enter directory (direct and link)"
|
||||||
"lnoperm"
|
"/proc/"**/cwd # special - no permission for links
|
||||||
"noperm"
|
"noperm"*
|
||||||
"lroot"
|
"lroot"*
|
||||||
|
"/"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add tests to global test array from test_rdlink
|
# Add tests to global test array from test_rdlink
|
||||||
tocompete+=(
|
tocompete+=(
|
||||||
compete_no_permission
|
compete_invalid
|
||||||
compete_links
|
compete_links
|
||||||
|
compete_no_permission
|
||||||
compete_canonicalize
|
compete_canonicalize
|
||||||
compete_all
|
compete_all
|
||||||
)
|
)
|
||||||
@@ -109,7 +119,7 @@ toassert_init() {
|
|||||||
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
|
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
|
||||||
assert_invalid_files=( "Assert - invalid files"
|
assert_invalid_files=( "Assert - invalid files"
|
||||||
"${_ta_tmp}/missing_file" "${_ta_tmp}/missing_file"
|
"${_ta_tmp}/missing_file" "${_ta_tmp}/missing_file"
|
||||||
"${_ta_tmp}/missd/missf" "${_ta_tmp}/missd/missf"
|
"${_ta_tmp}/missd/missf" ""
|
||||||
"${_ta_tmp}/miss c" "${_ta_tmp}/miss c"
|
"${_ta_tmp}/miss c" "${_ta_tmp}/miss c"
|
||||||
"rel_a" "${_ta_tmp}/rel_a"
|
"rel_a" "${_ta_tmp}/rel_a"
|
||||||
"../rel_b" "$(cd ".." && pwd)/rel_b"
|
"../rel_b" "$(cd ".." && pwd)/rel_b"
|
||||||
@@ -127,13 +137,19 @@ toassert_clean() {
|
|||||||
|
|
||||||
########## Common data and functions ##########
|
########## Common data and functions ##########
|
||||||
#
|
#
|
||||||
# [0] path to exclude [1] Reason for exclution
|
# [0] exclude regex [1] Reason for exclution
|
||||||
# [2] path to exclude [3] Reason for exclution
|
# [2] exclude regex [3] Reason for exclution
|
||||||
exclude_path=(
|
exclude_path=(
|
||||||
"/dev/fd" "Always different"
|
"/dev/fd$" "Different on every call"
|
||||||
"/dev/stdout" "Always different in pipes"
|
"/dev/stdout$" "Always different in pipes"
|
||||||
"/etc/mtab" "Always different"
|
"/etc/mtab$" "Different on every call"
|
||||||
"/proc/mounts" "Always different"
|
"/proc/mounts$" "Different on every call"
|
||||||
|
"/proc/net$" "Different on every call"
|
||||||
|
"/proc/net/.*" "Different on every call"
|
||||||
|
"/proc/self/fd/(1|3|255)" "Different on every call"
|
||||||
|
"/proc/self$" "Different on every call"
|
||||||
|
"/proc/self/(attr|fdinfo|map_files|net|ns|task)/.*" "Different on every call"
|
||||||
|
"/proc/thread-self$" "Different on every call"
|
||||||
)
|
)
|
||||||
|
|
||||||
toexclude() {
|
toexclude() {
|
||||||
@@ -144,7 +160,7 @@ toexclude() {
|
|||||||
exclude="${path}"
|
exclude="${path}"
|
||||||
else
|
else
|
||||||
# return reason for exclution
|
# return reason for exclution
|
||||||
if [[ "${exclude}" == "${1:-}" ]] ; then
|
if [[ "${1:-}" =~ ${exclude} ]] ; then
|
||||||
printf "${path}"
|
printf "${path}"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user