Fix initialisation before asserts and competion
New feature to exclude path with reason message (display as skipped)
This commit is contained in:
@@ -15,11 +15,11 @@ _tc_tmp="${test_dir:-"/tmp"}/tmp_compete"
|
||||
# ...
|
||||
|
||||
# Compete test suites (arrays)
|
||||
compete_canonicalize=(
|
||||
"Canonicalize invalid path"
|
||||
compete_canonicalize=( "Canonicalize invalid path"
|
||||
"-v" # Not recommended file naming
|
||||
"///tmp//./b"
|
||||
"//tmp//./b/.."
|
||||
"//tmp//./b/."
|
||||
#"//tmp//./b/.." # TODO return empty
|
||||
#"//tmp//./b/." # TODO return empty
|
||||
)
|
||||
|
||||
compete_all=( "Test - everything starting from /"
|
||||
@@ -30,6 +30,7 @@ compete_all=( "Test - everything starting from /"
|
||||
tocompete_init() {
|
||||
# initialize custom test structure
|
||||
{
|
||||
tocompete_clean
|
||||
mkdir -p "${_tc_tmp}"
|
||||
# compete_links
|
||||
touch "${_tc_tmp}/a"
|
||||
@@ -40,7 +41,9 @@ tocompete_init() {
|
||||
mkdir -p "${_tc_tmp}/noperm"
|
||||
chmod 400 "${_tc_tmp}/noperm"
|
||||
ln -s "noperm" "${_tc_tmp}/lnoperm"
|
||||
ln -s "/" "${_tc_tmp}/lroot"
|
||||
|
||||
#echo "rl: " && readlink "${_tc_tmp}/lnoperm"
|
||||
#ls -l "${_tc_tmp}"
|
||||
}
|
||||
|
||||
@@ -55,11 +58,16 @@ tocompete_init() {
|
||||
"${_tc_tmp}/a"*
|
||||
"/dev/stdin"
|
||||
"/bin/adb"
|
||||
"/dev/fd" # Test skip - /dev/fd is different on every call
|
||||
"/dev/stdout" # skip - different output
|
||||
"/etc/mtab" # skip - Always different
|
||||
"/proc/mounts" # skip - Always different
|
||||
)
|
||||
|
||||
compete_no_permission=( "No permission to enter directory (direct and link)"
|
||||
"noperm"
|
||||
"lnoperm"
|
||||
"noperm"
|
||||
"lroot"
|
||||
)
|
||||
|
||||
# Add tests to global test array from test_rdlink
|
||||
@@ -67,17 +75,14 @@ tocompete_init() {
|
||||
compete_no_permission
|
||||
compete_links
|
||||
compete_canonicalize
|
||||
#compete_all
|
||||
compete_all
|
||||
)
|
||||
}
|
||||
|
||||
tocompete_clean() {
|
||||
# TODO clean custom test structure
|
||||
rm -rf "${_tc_tmp}"
|
||||
}
|
||||
|
||||
tocompete_init
|
||||
|
||||
########## Assertion Block ##########
|
||||
|
||||
# ta = test assert
|
||||
@@ -92,7 +97,6 @@ _ta_tmp="${test_dir:-"/tmp"}/tmp_assert"
|
||||
# ...
|
||||
|
||||
toassert_init() {
|
||||
# TODO initilaize custom test structure
|
||||
{
|
||||
mkdir -p "${_ta_tmp}"
|
||||
}
|
||||
@@ -109,7 +113,6 @@ toassert_init() {
|
||||
"${_ta_tmp}/miss c" "${_ta_tmp}/miss c"
|
||||
"rel_a" "${_ta_tmp}/rel_a"
|
||||
"../rel_b" "$(cd ".." && pwd)/rel_b"
|
||||
"/a/very/long/path/whthMustExceed/fourtyfive/character" "a"
|
||||
)
|
||||
|
||||
# Add test arrays to global test array from test_rdlink
|
||||
@@ -119,17 +122,41 @@ toassert_init() {
|
||||
}
|
||||
|
||||
toassert_clean() {
|
||||
# TODO clean
|
||||
rm -rf "${_ta_tmp}"
|
||||
}
|
||||
|
||||
toassert_init
|
||||
########## Common data and functions ##########
|
||||
#
|
||||
# [0] path to exclude [1] Reason for exclution
|
||||
# [2] path to exclude [3] Reason for exclution
|
||||
exclude_path=(
|
||||
"/dev/fd" "Always different"
|
||||
"/dev/stdout" "Always different in pipes"
|
||||
"/etc/mtab" "Always different"
|
||||
"/proc/mounts" "Always different"
|
||||
)
|
||||
|
||||
toexclude() {
|
||||
local path=
|
||||
local exclude=
|
||||
for path in "${exclude_path[@]}" ; do
|
||||
if [[ ! "${exclude}" ]] ; then
|
||||
exclude="${path}"
|
||||
else
|
||||
# return reason for exclution
|
||||
if [[ "${exclude}" == "${1:-}" ]] ; then
|
||||
printf "${path}"
|
||||
return 0
|
||||
fi
|
||||
exclude=
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
########## Clean custom test data ##########
|
||||
#
|
||||
totest_cleanall() {
|
||||
echo
|
||||
tocompete_clean
|
||||
toassert_clean
|
||||
}
|
||||
|
Reference in New Issue
Block a user