summaryrefslogtreecommitdiffstats
path: root/bin/mv
diff options
context:
space:
mode:
authorjmmv <jmmv@FreeBSD.org>2014-03-09 17:04:31 +0000
committerjmmv <jmmv@FreeBSD.org>2014-03-09 17:04:31 +0000
commit80efbcbbcda6a5c59a21cb9628b2fd0573697dfe (patch)
tree2eed051c6d4bc448ea3f0f646cd5dbe45f87974c /bin/mv
parentf3010cfb7d9dbb4553d0cfa508ec09190a32fc7a (diff)
downloadFreeBSD-src-80efbcbbcda6a5c59a21cb9628b2fd0573697dfe.zip
FreeBSD-src-80efbcbbcda6a5c59a21cb9628b2fd0573697dfe.tar.gz
Sync sh(1) in stable/10 to head.
This is a MFC of all the commits listed below. My original goal of this change was to only merge the move of the tests from tools/regression/bin/ into the new layout (which include tests for sh(1) and other tools as well). However, doing so is tricky due to the ongoing work in sh(1) and, especially, the many changes to its tests since stable/10 was first branched. Merging everything is the simplest way to achieve this goal and, as a bonus point, we get various fixes and miscellaneous improvements into the branch. Per jilles' suggestion, I'm avoiding the merge of a couple of changes (r256850 and r257506) that required depending kernel changes. I'm also avoiding very recent changes that have not had a long enough time to be validated in current. This is "make tinderbox" clean. r256735 sh: Remove one syscall when waiting for a foreground job. r257399 sh: Allow trapping SIGINT/SIGQUIT after ignore because of '&'. r257504 sh: Reorder union node to reduce its size on 64-bit platforms. r257920 sh: Add a test case for would-be assignments that are not due to quoting. r257929 sh: Properly quote alias output from command -v. r258489 sh: Add tests for the </dev/null implicit in a background command. r258533 sh: Add more tests for the </dev/null implicit in a background command. r258535 sh: Make <&0 disable the </dev/null implicit in a background command. r258776 sh: Prefer memcpy() to strcpy() in most cases. Remove the scopy macro. r259047 sh: Split set -x output into a separate function. r259210 Migrate tools/regression/bin/ tests to the new layout. r259844 sh: Remove an unused variable. r259846 sh: Initialize OPTIND=1 even if it came from the environment. r259874 sh: Simplify code related to PPID variable. r259946 sh: Don't check input for non-whitespace if history is disabled. r260246 sh(1): Discourage use of -e. r260506 Run the sh(1) and test(1) tests as unprivileged. r260586 Mark the bin/pax tests as requiring perl. r260634 Use TAP_TESTS_PERL to register the legacy_test in bin/pax. r260635 Replace hand-crafted Kyuafiles with automatic generation. r260654 sh: Remove SIGWINCH handler and just check for resize before every read. r261121 sh: Add test for nested alias. r261125 sh: Solve the alias recursion problem in a less hackish way. r261141 sh: Do not depend on parse/execute split in new alias test. r261160 sh: Add tests for alias names after another alias. r261192 sh: Allow aliases to force alias substitution on the following word. r262533 sh: Make expari() static. r262565 sh: Do not corrupt internal representation if LINENO inner expansion fails. r262697 sh: Simplify expari(). Reviewed by: jilles
Diffstat (limited to 'bin/mv')
-rw-r--r--bin/mv/Makefile6
-rw-r--r--bin/mv/tests/Makefile9
-rw-r--r--bin/mv/tests/legacy_test.sh296
3 files changed, 311 insertions, 0 deletions
diff --git a/bin/mv/Makefile b/bin/mv/Makefile
index 8405782..ad8cc4f 100644
--- a/bin/mv/Makefile
+++ b/bin/mv/Makefile
@@ -1,6 +1,12 @@
# @(#)Makefile 8.2 (Berkeley) 4/2/94
# $FreeBSD$
+.include <bsd.own.mk>
+
PROG= mv
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
diff --git a/bin/mv/tests/Makefile b/bin/mv/tests/Makefile
new file mode 100644
index 0000000..051a3b6
--- /dev/null
+++ b/bin/mv/tests/Makefile
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/bin/mv
+
+TAP_TESTS_SH= legacy_test
+
+.include <tap.test.mk>
diff --git a/bin/mv/tests/legacy_test.sh b/bin/mv/tests/legacy_test.sh
new file mode 100644
index 0000000..d0a5e83
--- /dev/null
+++ b/bin/mv/tests/legacy_test.sh
@@ -0,0 +1,296 @@
+#!/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
+}
+
+# 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
+}
+
+# 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
+}
+
+# Run all tests locally and across devices
+echo 1..32
+for FS in '' $TMPDIR/testdir/
+do
+ begin 'Rename file'
+ mkf fa
+ mv fa ${FS}fb
+ ckok $?
+ ckf fa ${FS}fb
+ cknt fa
+ end
+
+ begin 'Move files into directory'
+ mkf fa
+ mkf fb
+ mkdir -p ${FS}1/2/3
+ mv fa fb ${FS}1/2/3
+ ckok $?
+ ckf fa ${FS}1/2/3/fa
+ ckf fb ${FS}1/2/3/fb
+ cknt fa
+ cknt fb
+ end
+
+ begin 'Move file from directory to file'
+ mkdir -p 1/2/3
+ mkf 1/2/3/fa
+ mv 1/2/3/fa ${FS}fb
+ ckok $?
+ ckf fa ${FS}fb
+ cknt 1/2/3/fa
+ end
+
+ begin 'Move file from directory to existing file'
+ mkdir -p 1/2/3
+ mkf 1/2/3/fa
+ :> ${FS}fb
+ mv 1/2/3/fa ${FS}fb
+ ckok $?
+ ckf fa ${FS}fb
+ cknt 1/2/3/fa
+ end
+
+ begin 'Move file from directory to existing directory'
+ mkdir -p 1/2/3
+ mkf 1/2/3/fa
+ mkdir -p ${FS}db/fa
+ # Should fail per POSIX step 3a:
+ # Destination path is a file of type directory and
+ # source_file is not a file of type directory
+ mv 1/2/3/fa ${FS}db 2>/dev/null
+ ckfail $?
+ ckf fa 1/2/3/fa
+ end
+
+ begin 'Move file from directory to directory'
+ mkdir -p da1/da2/da3
+ mkdir -p ${FS}db1/db2/db3
+ mkf da1/da2/da3/fa
+ mv da1/da2/da3/fa ${FS}db1/db2/db3/fb
+ ckok $?
+ ckf fa ${FS}db1/db2/db3/fb
+ cknt da1/da2/da3/fa
+ end
+
+ begin 'Rename directory'
+ mkd da
+ mv da ${FS}db
+ ckok $?
+ ckd da ${FS}db
+ cknt da
+ end
+
+ begin 'Move directory to directory name'
+ mkd da1/da2/da3/da
+ mkdir -p ${FS}db1/db2/db3
+ mv da1/da2/da3/da ${FS}db1/db2/db3/db
+ ckok $?
+ ckd da ${FS}db1/db2/db3/db
+ cknt da1/da2/da3/da
+ end
+
+ begin 'Move directory to directory'
+ mkd da1/da2/da3/da
+ mkdir -p ${FS}db1/db2/db3
+ mv da1/da2/da3/da ${FS}db1/db2/db3
+ ckok $?
+ ckd da ${FS}db1/db2/db3/da
+ cknt da1/da2/da3/da
+ end
+
+ begin 'Move directory to existing empty directory'
+ mkd da1/da2/da3/da
+ mkdir -p ${FS}db1/db2/db3/da
+ mv da1/da2/da3/da ${FS}db1/db2/db3
+ ckok $?
+ ckd da ${FS}db1/db2/db3/da
+ cknt da1/da2/da3/da
+ end
+
+ begin 'Move directory to existing non-empty directory'
+ mkd da1/da2/da3/da
+ mkdir -p ${FS}db1/db2/db3/da/full
+ # Should fail (per the semantics of rename(2))
+ mv da1/da2/da3/da ${FS}db1/db2/db3 2>/dev/null
+ ckfail $?
+ ckd da da1/da2/da3/da
+ end
+
+ begin 'Move directory to existing file'
+ mkd da1/da2/da3/da
+ mkdir -p ${FS}db1/db2/db3
+ :> ${FS}db1/db2/db3/da
+ # Should fail per POSIX step 3b:
+ # Destination path is a file not of type directory
+ # and source_file is a file of type directory
+ mv da1/da2/da3/da ${FS}db1/db2/db3/da 2>/dev/null
+ ckfail $?
+ ckd da da1/da2/da3/da
+ end
+
+ begin 'Rename fifo'
+ mkp fa
+ mv fa ${FS}fb
+ ckok $?
+ ckp fa ${FS}fb
+ cknt fa
+ end
+
+ begin 'Move fifos into directory'
+ mkp fa
+ mkp fb
+ mkdir -p ${FS}1/2/3
+ mv fa fb ${FS}1/2/3
+ ckok $?
+ ckp fa ${FS}1/2/3/fa
+ ckp fb ${FS}1/2/3/fb
+ cknt fa
+ cknt fb
+ end
+
+ begin 'Move fifo from directory to fifo'
+ mkdir -p 1/2/3
+ mkp 1/2/3/fa
+ mv 1/2/3/fa ${FS}fb
+ ckok $?
+ ckp fa ${FS}fb
+ cknt 1/2/3/fa
+ end
+
+ begin 'Move fifo from directory to directory'
+ mkdir -p da1/da2/da3
+ mkdir -p ${FS}db1/db2/db3
+ mkp da1/da2/da3/fa
+ mv da1/da2/da3/fa ${FS}db1/db2/db3/fb
+ ckok $?
+ ckp fa ${FS}db1/db2/db3/fb
+ cknt da1/da2/da3/fa
+ end
+done
OpenPOWER on IntegriCloud