1174657Sdds#!/bin/sh 2174657Sdds# $FreeBSD: releng/10.2/bin/mv/tests/legacy_test.sh 259210 2013-12-11 04:09:17Z jmmv $ 3174657Sdds 4174657Sdds# A directory in a device different from that where the tests are run 5174657SddsTMPDIR=/tmp/regress.$$ 6174657SddsCOUNT=0 7174657Sdds 8174657Sdds# Begin an individual test 9174657Sddsbegin() 10174657Sdds{ 11174657Sdds COUNT=`expr $COUNT + 1` 12174657Sdds OK=1 13174657Sdds if [ -z "$FS" ] 14174657Sdds then 15174657Sdds NAME="$1" 16174657Sdds else 17174657Sdds NAME="$1 (cross device)" 18174657Sdds fi 19174657Sdds rm -rf testdir $TMPDIR/testdir 20174657Sdds mkdir -p testdir $TMPDIR/testdir 21174657Sdds cd testdir 22174657Sdds} 23174657Sdds 24174657Sdds# End an individual test 25174657Sddsend() 26174657Sdds{ 27174657Sdds if [ $OK = 1 ] 28174657Sdds then 29174748Sdds printf 'ok ' 30174657Sdds else 31174748Sdds printf 'not ok ' 32174657Sdds fi 33174657Sdds echo "$COUNT - $NAME" 34174657Sdds cd .. 35174657Sdds rm -rf testdir $TMPDIR/testdir 36174657Sdds} 37174657Sdds 38174657Sdds# Make a file that can later be verified 39174657Sddsmkf() 40174657Sdds{ 41174657Sdds CN=`basename $1` 42174657Sdds echo "$CN-$CN" >$1 43174657Sdds} 44174657Sdds 45174657Sdds# Verify that the file specified is correct 46174657Sddsckf() 47174657Sdds{ 48174748Sdds if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null 49174657Sdds then 50174657Sdds ok 51174657Sdds else 52174657Sdds notok 53174657Sdds fi 54174657Sdds} 55174657Sdds 56174657Sdds# Make a fifo that can later be verified 57174657Sddsmkp() 58174657Sdds{ 59174657Sdds mkfifo $1 60174657Sdds} 61174657Sdds 62174657Sdds# Verify that the file specified is correct 63174657Sddsckp() 64174657Sdds{ 65174657Sdds if [ -p $2 ] 66174657Sdds then 67174657Sdds ok 68174657Sdds else 69174657Sdds notok 70174657Sdds fi 71174657Sdds} 72174657Sdds 73174657Sdds# Make a directory that can later be verified 74174657Sddsmkd() 75174657Sdds{ 76174657Sdds CN=`basename $1` 77174657Sdds mkdir -p $1/"$CN-$CN" 78174657Sdds} 79174657Sdds 80174657Sdds# Verify that the directory specified is correct 81174657Sddsckd() 82174657Sdds{ 83174657Sdds if [ -d $2/$1-$1 ] 84174657Sdds then 85174657Sdds ok 86174657Sdds else 87174657Sdds notok 88174657Sdds fi 89174657Sdds} 90174657Sdds 91174658Sdds# Verify that the specified file does not exist 92174658Sdds# (is not there) 93174658Sddscknt() 94174658Sdds{ 95174748Sdds if [ -r $1 ] 96174658Sdds then 97174658Sdds notok 98174658Sdds else 99174658Sdds ok 100174658Sdds fi 101174658Sdds} 102174658Sdds 103174657Sdds# A part of a test succeeds 104174657Sddsok() 105174657Sdds{ 106174657Sdds : 107174657Sdds} 108174657Sdds 109174657Sdds# A part of a test fails 110174657Sddsnotok() 111174657Sdds{ 112174657Sdds OK=0 113174657Sdds} 114174657Sdds 115174747Sdds# Verify that the exit code passed is for unsuccessful termination 116174747Sddsckfail() 117174747Sdds{ 118174747Sdds if [ $1 -gt 0 ] 119174747Sdds then 120174747Sdds ok 121174747Sdds else 122174747Sdds notok 123174747Sdds fi 124174747Sdds} 125174747Sdds 126174747Sdds# Verify that the exit code passed is for successful termination 127174747Sddsckok() 128174747Sdds{ 129174747Sdds if [ $1 -eq 0 ] 130174747Sdds then 131174747Sdds ok 132174747Sdds else 133174747Sdds notok 134174747Sdds fi 135174747Sdds} 136174747Sdds 137174657Sdds# Run all tests locally and across devices 138174773Sddsecho 1..32 139174657Sddsfor FS in '' $TMPDIR/testdir/ 140174657Sddsdo 141174657Sdds begin 'Rename file' 142174657Sdds mkf fa 143174657Sdds mv fa ${FS}fb 144174747Sdds ckok $? 145174657Sdds ckf fa ${FS}fb 146174658Sdds cknt fa 147174657Sdds end 148174657Sdds 149174657Sdds begin 'Move files into directory' 150174657Sdds mkf fa 151174657Sdds mkf fb 152174657Sdds mkdir -p ${FS}1/2/3 153174657Sdds mv fa fb ${FS}1/2/3 154174747Sdds ckok $? 155174657Sdds ckf fa ${FS}1/2/3/fa 156174657Sdds ckf fb ${FS}1/2/3/fb 157174658Sdds cknt fa 158174658Sdds cknt fb 159174657Sdds end 160174657Sdds 161174657Sdds begin 'Move file from directory to file' 162174657Sdds mkdir -p 1/2/3 163174657Sdds mkf 1/2/3/fa 164174657Sdds mv 1/2/3/fa ${FS}fb 165174747Sdds ckok $? 166174657Sdds ckf fa ${FS}fb 167174658Sdds cknt 1/2/3/fa 168174657Sdds end 169174657Sdds 170174747Sdds begin 'Move file from directory to existing file' 171174747Sdds mkdir -p 1/2/3 172174747Sdds mkf 1/2/3/fa 173174747Sdds :> ${FS}fb 174174747Sdds mv 1/2/3/fa ${FS}fb 175174747Sdds ckok $? 176174747Sdds ckf fa ${FS}fb 177174747Sdds cknt 1/2/3/fa 178174747Sdds end 179174747Sdds 180174747Sdds begin 'Move file from directory to existing directory' 181174747Sdds mkdir -p 1/2/3 182174747Sdds mkf 1/2/3/fa 183174772Sdds mkdir -p ${FS}db/fa 184174747Sdds # Should fail per POSIX step 3a: 185174747Sdds # Destination path is a file of type directory and 186174747Sdds # source_file is not a file of type directory 187201422Sobrien mv 1/2/3/fa ${FS}db 2>/dev/null 188174747Sdds ckfail $? 189174747Sdds ckf fa 1/2/3/fa 190174747Sdds end 191174747Sdds 192174657Sdds begin 'Move file from directory to directory' 193174657Sdds mkdir -p da1/da2/da3 194174657Sdds mkdir -p ${FS}db1/db2/db3 195174657Sdds mkf da1/da2/da3/fa 196174657Sdds mv da1/da2/da3/fa ${FS}db1/db2/db3/fb 197174747Sdds ckok $? 198174657Sdds ckf fa ${FS}db1/db2/db3/fb 199174658Sdds cknt da1/da2/da3/fa 200174657Sdds end 201174657Sdds 202174657Sdds begin 'Rename directory' 203174657Sdds mkd da 204174657Sdds mv da ${FS}db 205174747Sdds ckok $? 206174657Sdds ckd da ${FS}db 207174658Sdds cknt da 208174657Sdds end 209174657Sdds 210174657Sdds begin 'Move directory to directory name' 211174657Sdds mkd da1/da2/da3/da 212174657Sdds mkdir -p ${FS}db1/db2/db3 213174657Sdds mv da1/da2/da3/da ${FS}db1/db2/db3/db 214174747Sdds ckok $? 215174657Sdds ckd da ${FS}db1/db2/db3/db 216174658Sdds cknt da1/da2/da3/da 217174657Sdds end 218174657Sdds 219174657Sdds begin 'Move directory to directory' 220174657Sdds mkd da1/da2/da3/da 221174657Sdds mkdir -p ${FS}db1/db2/db3 222174657Sdds mv da1/da2/da3/da ${FS}db1/db2/db3 223174747Sdds ckok $? 224174657Sdds ckd da ${FS}db1/db2/db3/da 225174658Sdds cknt da1/da2/da3/da 226174657Sdds end 227174657Sdds 228174747Sdds begin 'Move directory to existing empty directory' 229174657Sdds mkd da1/da2/da3/da 230174657Sdds mkdir -p ${FS}db1/db2/db3/da 231174657Sdds mv da1/da2/da3/da ${FS}db1/db2/db3 232174747Sdds ckok $? 233174657Sdds ckd da ${FS}db1/db2/db3/da 234174658Sdds cknt da1/da2/da3/da 235174657Sdds end 236174657Sdds 237174747Sdds begin 'Move directory to existing non-empty directory' 238174747Sdds mkd da1/da2/da3/da 239174747Sdds mkdir -p ${FS}db1/db2/db3/da/full 240174747Sdds # Should fail (per the semantics of rename(2)) 241201422Sobrien mv da1/da2/da3/da ${FS}db1/db2/db3 2>/dev/null 242174747Sdds ckfail $? 243174747Sdds ckd da da1/da2/da3/da 244174747Sdds end 245174747Sdds 246174747Sdds begin 'Move directory to existing file' 247174747Sdds mkd da1/da2/da3/da 248174747Sdds mkdir -p ${FS}db1/db2/db3 249174747Sdds :> ${FS}db1/db2/db3/da 250174747Sdds # Should fail per POSIX step 3b: 251174747Sdds # Destination path is a file not of type directory 252174747Sdds # and source_file is a file of type directory 253201422Sobrien mv da1/da2/da3/da ${FS}db1/db2/db3/da 2>/dev/null 254174747Sdds ckfail $? 255174747Sdds ckd da da1/da2/da3/da 256174747Sdds end 257174747Sdds 258174657Sdds begin 'Rename fifo' 259174657Sdds mkp fa 260174657Sdds mv fa ${FS}fb 261174747Sdds ckok $? 262174657Sdds ckp fa ${FS}fb 263174658Sdds cknt fa 264174657Sdds end 265174657Sdds 266174657Sdds begin 'Move fifos into directory' 267174657Sdds mkp fa 268174657Sdds mkp fb 269174657Sdds mkdir -p ${FS}1/2/3 270174657Sdds mv fa fb ${FS}1/2/3 271174747Sdds ckok $? 272174657Sdds ckp fa ${FS}1/2/3/fa 273174657Sdds ckp fb ${FS}1/2/3/fb 274174658Sdds cknt fa 275174658Sdds cknt fb 276174657Sdds end 277174657Sdds 278174657Sdds begin 'Move fifo from directory to fifo' 279174657Sdds mkdir -p 1/2/3 280174657Sdds mkp 1/2/3/fa 281174657Sdds mv 1/2/3/fa ${FS}fb 282174747Sdds ckok $? 283174657Sdds ckp fa ${FS}fb 284174658Sdds cknt 1/2/3/fa 285174657Sdds end 286174657Sdds 287174657Sdds begin 'Move fifo from directory to directory' 288174657Sdds mkdir -p da1/da2/da3 289174657Sdds mkdir -p ${FS}db1/db2/db3 290174657Sdds mkp da1/da2/da3/fa 291174657Sdds mv da1/da2/da3/fa ${FS}db1/db2/db3/fb 292174747Sdds ckok $? 293174657Sdds ckp fa ${FS}db1/db2/db3/fb 294174658Sdds cknt da1/da2/da3/fa 295174657Sdds end 296174657Sddsdone 297