1 #!/bin/sh 2 ################################################################################ 3 ## ## 4 ## Copyright (c) International Business Machines Corp., 2001 ## 5 ## Author: Manoj Iyer, manjo (at] mail.utexas.edu ## 6 ## Copyright (c) 2016 Cyril Hrubis <chrubis (at] suse.cz> ## 7 ## ## 8 ## This program is free software; you can redistribute it and#or modify ## 9 ## it under the terms of the GNU General Public License as published by ## 10 ## the Free Software Foundation; either version 2 of the License, or ## 11 ## (at your option) any later version. ## 12 ## ## 13 ## This program is distributed in the hope that it will be useful, but ## 14 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 15 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 16 ## for more details. ## 17 ## ## 18 ## You should have received a copy of the GNU General Public License ## 19 ## along with this program; if not, write to the Free Software Foundation, ## 20 ## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 21 ## ## 22 ################################################################################ 23 # 24 # Basic test for ln 25 # 26 TST_CNT=6 27 TST_TESTFUNC=do_test 28 TST_SETUP=setup 29 TST_NEEDS_TMPDIR=1 30 . tst_test.sh 31 32 setup() 33 { 34 ROD mkdir -p dir/subdir 35 ROD echo "LTP" > file 36 ROD touch dir/file 37 } 38 39 check_dir_link() 40 { 41 local dname="$1" 42 local lname="$2" 43 44 ROD ls "$lname" > lname.out 45 ROD ls "$dname" > dname.out 46 47 if diff lname.out dname.out; then 48 tst_res TPASS "Directory and link content is equal" 49 else 50 tst_res TFAIL "Directory and link content differs" 51 cat lname.out 52 echo 53 cat dname.out 54 fi 55 } 56 57 check_file_link() 58 { 59 local fname="$1" 60 local lname="$2" 61 62 if diff $fname $lname; then 63 tst_res TPASS "File and link content is equal" 64 else 65 tst_res TFAIL "File and link content differs" 66 fi 67 } 68 69 ln_test() 70 { 71 local args="$1" 72 local src="$2" 73 local link="$3" 74 75 EXPECT_PASS ln $args $src $link 76 77 if [ -f $src ]; then 78 check_file_link $src $link 79 else 80 check_dir_link $src $link 81 fi 82 83 ROD rm $link 84 } 85 86 do_test() 87 { 88 case $1 in 89 1) ln_test "" "file" "file_link";; 90 2) ln_test "-s" "file" "file_link";; 91 3) ln_test "-s" "dir" "dir_link";; 92 4) ln_test "" "$PWD/file" "file_link";; 93 5) ln_test "-s" "$PWD/file" "file_link";; 94 6) ln_test "-s" "$PWD/dir" "dir_link";; 95 esac 96 } 97 98 tst_run 99