1 #!/bin/sh 2 # 3 # Test the _abspath function, utilized as part of abspath.sh 4 # 5 # Copyright (C) 2010, Cisco Systems Inc. 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License along 18 # with this program; if not, write to the Free Software Foundation, Inc., 19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Garrett Cooper, January 2010 22 # 23 24 SCRIPTS_DIR="$(readlink -f ${0%/*}/..)" 25 TEST_PATH=$("$SCRIPTS_DIR/realpath.sh" "$SCRIPTS_DIR/lib") 26 27 pushd "$TEST_PATH" >/dev/null 28 29 set -- \ 30 :$PWD \ 31 .:$PWD \ 32 foo/bar:$PWD/foo/bar \ 33 /foo/bar:/foo/bar \ 34 /foo/../bar:/bar \ 35 /foo/bar/../baz:/foo/baz \ 36 /foo/bar/../baz/:/foo/baz \ 37 /foo/../bar/:/bar \ 38 /foo/../bar/..:/ \ 39 /foo/../bar/../:/ \ 40 /foo/bar/../baz:/foo/baz \ 41 /foo/./bar:/foo/bar \ 42 /./foo/./bar:/foo/bar \ 43 /foo//bar:/foo/bar \ 44 //foo/bar:/foo/bar \ 45 //////foo/bar:/foo/bar \ 46 /foo/////bar:/foo/bar \ 47 /a/b/c/.././:/a/b \ 48 /.foo:/.foo \ 49 ./.foo:$PWD/.foo \ 50 /.foo/.bar:/.foo/.bar \ 51 ./.foo/.bar:$PWD/.foo/.bar \ 52 /scratch/ltp/testcases/realtime/../..:/scratch/ltp \ 53 ..:$(dirname "$TEST_PATH") \ 54 ../..:$(dirname "$(dirname "$TEST_PATH")") \ 55 testcases/kernel/controllers/libcontrollers/../../../..:$PWD 56 57 export TCID=test_abspath 58 export TST_TOTAL=$# 59 export TST_COUNT=1 60 61 . "$SCRIPTS_DIR/lib/file_functions.sh" 62 63 for i in "$@"; do 64 65 test_string=${i%:*} 66 expected_string=${i#*:} 67 68 result=$(_abspath "$test_string") 69 70 if [ "$result" = "$expected_string" ] ; then 71 result_s="matches expected string _abspath(${test_string}) => $result == $expected_string)" 72 result_v=TPASS 73 else 74 result_s="doesn't match expected string _abspath(${test_string}) => $result != $expected_string)" 75 result_v=TFAIL 76 FAILED=1 77 fi 78 79 tst_resm $result_v "Test string $result_s" 80 81 : $(( TST_COUNT += 1 )) 82 83 done 84 85 popd >/dev/null 86 87 expected_string="$PWD" 88 test_string='""' 89 result=$("$SCRIPTS_DIR/abspath.sh" "") 90 91 if [ "$result" = "$expected_string" ] ; then 92 result_s="matches expected string abspath.sh ${test_string} => $result == $expected_string)" 93 result_v=TPASS 94 else 95 result_s="doesn't match expected string abspath.sh ${test_string} => $result != $expected_string)" 96 result_v=TFAIL 97 FAILED=1 98 fi 99 100 tst_resm $result_v "Test string $result_s" 101 102 : $(( TST_COUNT += 1 )) 103 104 expected_string="$PWD $PWD" 105 test_string="\"\" ." 106 result=$("$SCRIPTS_DIR/abspath.sh" "" .) 107 108 if [ "$result" = "$expected_string" ] ; then 109 result_s="matches expected string abspath.sh ${test_string} => $result == $expected_string)" 110 result_v=TPASS 111 else 112 result_s="doesn't match expected string abspath.sh ${test_string} => $result != $expected_string)" 113 result_v=TFAIL 114 FAILED=1 115 fi 116 117 tst_resm $result_v "Test string $result_s" 118 119 : $(( TST_COUNT += 1 )) 120 121 exit ${FAILED:=0} 122