#!/bin/sh # $FreeBSD$ # A directory in a device different from that where the tests are run TMPDIR=/tmp/regress.$$ COUNT=0 # Begin an individual test begin() { COUNT=`expr $COUNT + 1` OK=1 if [ -z "$FS" ] then NAME="$1" else NAME="$1 (cross device)" fi rm -rf testdir $TMPDIR/testdir mkdir -p testdir $TMPDIR/testdir cd testdir } # End an individual test end() { if [ $OK = 1 ] then printf 'ok ' else printf 'not ok ' fi echo "$COUNT - $NAME" cd .. rm -rf testdir $TMPDIR/testdir } # Make a file that can later be verified mkf() { CN=`basename $1` echo "$CN-$CN" >$1 } mklink() { ln -sf $1 $2 } # Verify that the file specified is correct ckf() { if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null then ok else notok fi } # Make a fifo that can later be verified mkp() { mkfifo $1 } # Verify that the file specified is correct ckp() { if [ -p $2 ] then ok else notok fi } # Make a directory that can later be verified mkd() { CN=`basename $1` mkdir -p $1/"$CN-$CN" } # Verify that the directory specified is correct ckd() { if [ -d $2/$1-$1 ] then ok else notok fi } # Verify that the specified file does not exist # (is not there) cknt() { if [ -r $1 ] then notok else ok fi } # Verify that the specified symlink points to the specified file. cklink() { if [ -L $1 -a "$(readlink $1)" = $2 ]; then ok else notok fi } # A part of a test succeeds ok() { : } # A part of a test fails notok() { OK=0 } # Verify that the exit code passed is for unsuccessful termination ckfail() { if [ $1 -gt 0 ] then ok else notok fi } # Verify that the exit code passed is for successful termination ckok() { if [ $1 -eq 0 ] then ok else notok fi } echo 1..5 # Test 1 begin 'Copy regular file to dangling symlink' mkf f1 mklink f2 l1 cp f1 l1 ckok $? ckf f1 f2 cklink l1 f2 end # Test 2 begin 'Force copy regular file to dangling symlink' mkf f1 mklink f2 l1 cp -f f1 l1 ckok $? ckf f1 f2 cklink l1 f2 end # Test 3 begin 'Copy regular file to dangling symlink (-R)' mkf f1 mklink f2 l1 cp -R f1 l1 ckok $? ckf f1 f2 cklink l1 f2 end # Test 4 begin 'Force copy regular file to dangling symlink (-R)' mkf f1 mklink f2 l1 cp -Rf f1 l1 ckok $? ckf f1 f2 cklink l1 f2 end # Test 5 begin 'Copy symlink to dangling symlink' mkf f1 mklink f1 l1 mklink f2 l2 cp l1 l2 ckf f1 f1 ckf f1 f2 end # Test 6 begin 'Copy symlink to dangling symlink (-a)' mkf f1 mklink f1 l1 mklink f2 l2 cp -a l1 l2 ckf f1 f1 cknt f2 cklink l1 f1 cklink l2 f1 end # Test 7 begin 'Copy symlink to dangling symlink (-an)' mkf f1 mklink f1 l1 mklink f2 l2 cp -an l1 l2 ckf f1 f1 cknt f2 cklink l1 f1 cklink l2 f2 end # Test 8 begin 'Force copy regular file to symlink' mkf f1 mkf f2 mklink f2 l1 cp -f f1 l1 ckf f1 f1 ckf f1 f2 cklink l1 f2 end # Test 9 begin 'Copy symlink to non-existant file (-an)' mkf f1 mklink f1 l1 cp -an l1 l2 ckf f1 f1 cklink l1 f1 cklink l2 f1 end