summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2007-11-23 13:51:10 +0100
committerJim Meyering <meyering@redhat.com>2007-11-24 15:09:17 +0100
commita382db6a04dd05c1acc669a7769fb2297b237500 (patch)
tree6b859b2619886e0cf3fbb2fa3de48b0b19605a44 /tests
parent5c11250915f1521fa65502c1e4765ddd41c96edc (diff)
downloadcoreutils-a382db6a04dd05c1acc669a7769fb2297b237500.tar.xz
Test the new feature: cp -p preserves the GID whenever possible.
* tests/cp/preserve-gid: New file. Test for today's change. * tests/cp/Makefile.am (TESTS): Add preserve-gid. * tests/Makefile.am (all_t): Add tc. (tc): New target.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/cp/Makefile.am2
-rwxr-xr-xtests/cp/preserve-gid94
3 files changed, 98 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f7c837fae..2db18f02a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,7 +48,7 @@ SUBDIRS = \
uniq wc
## N O T E :: Please do not add new directories.
-all_t = t1 t2 t3 t4 t5 t6 t7 t8 t9 ta tb
+all_t = t1 t2 t3 t4 t5 t6 t7 t8 t9 ta tb tc
.PHONY: check-root $(all_t)
check-root: $(all_t)
@@ -74,6 +74,8 @@ ta:
cd mkdir && $(MAKE) check TESTS=writable-under-readonly
tb:
cd mv && $(MAKE) check TESTS=sticky-to-xpart
+tc:
+ cd cp && $(MAKE) check TESTS=preserve-gid
check-recursive: root-hint
diff --git a/tests/cp/Makefile.am b/tests/cp/Makefile.am
index 1fbdc3f67..159b93af6 100644
--- a/tests/cp/Makefile.am
+++ b/tests/cp/Makefile.am
@@ -27,7 +27,7 @@ TESTS = \
link-no-deref \
cp-deref \
acl \
- preserve-2 r-vs-symlink link-preserve \
+ preserve-2 r-vs-symlink link-preserve preserve-gid \
backup-1 no-deref-link1 no-deref-link2 no-deref-link3 backup-is-src \
same-file cp-mv-backup symlink-slash slink-2-slink fail-perm dir-slash \
perm cp-HL cp-i special-bits link dir-rm-dest cp-parents deref-slink \
diff --git a/tests/cp/preserve-gid b/tests/cp/preserve-gid
new file mode 100755
index 000000000..c1ecb7fff
--- /dev/null
+++ b/tests/cp/preserve-gid
@@ -0,0 +1,94 @@
+#!/bin/sh
+# Verify that cp -p preserves GID when it is possible.
+
+# Copyright (C) 2007 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "$srcdir/../lang-default"
+PRIV_CHECK_ARG=require-root . "$srcdir/../priv-check"
+. "$srcdir/../test-lib.sh"
+
+create() {
+ echo "$1" > "$1" || exit 1
+ chown "$2:$3" "$1" || exit 1
+}
+
+t0() {
+ f=$1; shift
+ u=$1; shift
+ g=$1; shift
+ rm -f b || exit 1
+ "$@" "$f" b || exit 1
+ s=`stat -c '%u %g' b`
+ if test "x$s" != "x$u $g"; then
+ echo "$0: $* $f b: $u $g != $s" 1>&2
+ (exit 1); exit 1
+ fi
+}
+
+t1() {
+ f=$1; shift
+ u=$1; shift
+ g=$1; shift
+ t0 "$f" "$u" "$g" setuidgid -g "$nameless_gid1,$nameless_gid2" "$nameless_uid" "$@"
+}
+
+if test "x$VERBOSE" = xyes; then
+ set -x
+ cp --version
+fi
+
+nameless_uid=`$PERL -e 'foreach my $i (1000..16*1024-1) { getpwuid $i or (print "$i\n"), exit }'`
+nameless_gid1=`$PERL -e 'foreach my $i (1000..16*1024) { getgrgid $i or (print "$i\n"), exit }'`
+nameless_gid2=`$PERL -e 'foreach my $i ('"$nameless_gid1"'+1..16*1024) { getgrgid $i or (print "$i\n"), exit }'`
+
+if [ -z "$nameless_uid" ] || [ -z "$nameless_gid1" ] || [ -z "$nameless_gid2" ]; then
+ echo "$0: couldn't find a nameless UID or GID" 1>&2
+ (exit 77); exit 77
+fi
+
+chown "$nameless_uid" .
+
+create a0 0 0
+create b0 "$nameless_uid" "$nameless_gid1"
+create b1 "$nameless_uid" "$nameless_gid2"
+create c0 0 "$nameless_gid1"
+create c1 0 "$nameless_gid2"
+
+t0 a0 0 0 cp
+t0 b0 0 0 cp
+t0 b1 0 0 cp
+t0 c0 0 0 cp
+t0 c1 0 0 cp
+
+t0 a0 0 0 cp -p
+t0 b0 "$nameless_uid" "$nameless_gid1" cp -p
+t0 b1 "$nameless_uid" "$nameless_gid2" cp -p
+t0 c0 0 "$nameless_gid1" cp -p
+t0 c1 0 "$nameless_gid2" cp -p
+
+t1 a0 "$nameless_uid" "$nameless_gid1" cp
+t1 b0 "$nameless_uid" "$nameless_gid1" cp
+t1 b1 "$nameless_uid" "$nameless_gid1" cp
+t1 c0 "$nameless_uid" "$nameless_gid1" cp
+t1 c1 "$nameless_uid" "$nameless_gid1" cp
+
+t1 a0 "$nameless_uid" "$nameless_gid1" cp -p
+t1 b0 "$nameless_uid" "$nameless_gid1" cp -p
+t1 b1 "$nameless_uid" "$nameless_gid2" cp -p
+t1 c0 "$nameless_uid" "$nameless_gid1" cp -p
+t1 c1 "$nameless_uid" "$nameless_gid2" cp -p
+
+(exit 0); exit 0