Replicated competition tests to assertion tests

This commit is contained in:
2022-03-28 22:39:40 +02:00
parent 7ae0f2de57
commit aaa796d4b4

View File

@@ -132,10 +132,42 @@ _ta_tmp="${test_dir:-"/tmp"}/tmp_assert"
# [1] input == [2] expected
# [3] input == [4] expected
# ...
assert_canonicalize=( "Canonicalize invalid path"
"///tmp//./b" "/tmp/b"
"//tmp//./b/.." ""
"//tmp//./b/." ""
"//tmp//./b/" "/tmp/b"
"///notthere//...../help/." ""
)
toassert_init() {
{
# Base directory for the test initialization
mkdir -p "${_ta_tmp}"
cd "${_ta_tmp}"
# assert_no_permission
mkdir -p "nopermdir"
chmod 400 "nopermdir"
ln -s "nopermdir" "nopermdirl"
ln -s "/" "lroot"
ln -s "/root" "lroothome"
# assert_links
touch "a"
ln -s "a" "a 2"
ln -s "a 2" "a 3"
mkdir -p "dir_1"
mkdir -p "dir_2/dir_22"
touch "dir_2/dir_22/file"
ln -s "dir_2/dir_22" "dir_3_l"
ln -s "../dir_3_l/file" "dir_1/file"
# assert_relative
ln -s "../nofile" "nofile_l"
ln -s "../nodir/nofile" "nopath_l"
}
# Base directory for the test
@@ -150,6 +182,41 @@ toassert_init() {
"${_ta_tmp}/miss c" "${_ta_tmp}/miss c"
"rel_a" "${_ta_tmp}/rel_a"
"../rel_b" "$(cd ".." && pwd)/rel_b"
"-v" "$PWD/-v" # Not recommended file naming
"../-v" "$(cd "$PWD/.." && pwd)/-v" # Not recommended file naming
"-v/.." "" # Not recommended file naming
)
assert_relative=( "Resolving of relative links"
# Invalid
"nofile_l" "$(cd "$PWD/.." && pwd)/nofile"
"nopath_l" ""
# Valid
"dir_1/file" "$PWD/dir_2/dir_22/file" # Valid relative link to path with relative element
)
assert_no_permission=( "No permission to enter directory (direct and link)"
"nopermdir" "$PWD/nopermdir"
"nopermdirl" "$PWD/nopermdir"
"lroot" "/"
"lroothome" "/root"
"/" "/"
"/root" "/root"
"/root/" "/root"
"/root/." "/root"
"/root/.." "/"
)
assert_links=( "Test - Valid links"
"${_ta_tmp}/a 3" "$PWD/a" # slink chain a3 -> a2 -> a
"${_ta_tmp}/a" "$PWD/a"
"${_ta_tmp}/a 2" "$PWD/a"
"/dev/stdin" "/dev/pts/0"
#"/dev/stdout" "" # skip - Always different ( add for assert )
#"/dev/fd" # Test skip - /dev/fd is different on every call
#"/etc/mtab" # skip - Always different
#"/proc/mounts" # skip - Always different
#"/proc/net/"* # skip - Always different
)
assert_force_fail=( "Force fail"
@@ -158,7 +225,11 @@ toassert_init() {
# Add test arrays to global test array from test_rdlink
toassert+=(
assert_canonicalize
assert_relative
assert_no_permission
assert_invalid_files
assert_links
#assert_force_fail
)
}