bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: tests/chgrp/basic revamped


From: Jim Meyering
Subject: FYI: tests/chgrp/basic revamped
Date: Sun, 17 Sep 2006 23:00:40 +0200

FYI, I've just done this.
It was too hard to debug failures when they were expressed
as diffs of --verbose and -c-based output.

2006-09-17  Jim Meyering  <address@hidden>

        * tests/chgrp/basic: On an OpenBSD system, rather than failing
        due to a known problem, merely warn about it.
        Rewrite to avoid testing output of chgrp --verbose and chgrp -c.
        Instead, use stat to test file system for desired results, directly.
        * tests/chgrp/Makefile.am (TESTS_ENVIRONMENT): Set host_triplet.

Index: tests/chgrp/basic
===================================================================
RCS file: /fetish/cu/tests/chgrp/basic,v
retrieving revision 1.23
diff -u -r1.23 basic
--- tests/chgrp/basic   17 Aug 2006 19:58:25 -0000      1.23
+++ tests/chgrp/basic   17 Sep 2006 20:55:12 -0000
@@ -54,99 +54,73 @@
 chgrp $g2 f2 || fail=1
 chgrp -R $g1 d || fail=1

-# Don't let verbose output interfere.
-test "$VERBOSE" = yes && set +x
+d_files='d d/f3'

-(
-  chgrp -c $g1 f
-  chgrp -c $g2 f
-  chgrp -c $g2 f
-  chgrp --verbose '' f
-  chgrp --verbose $g1 f
-  chgrp --verbose $g1 f
-  chgrp --verbose --reference=f2 f
-  chgrp -R --verbose $g2 d
-  chgrp -R --verbose $g1 d
-  chgrp -R -c $g2 d
-  chgrp -R -c $g1 d
-  chgrp -c $g2 d
-
-  rm -f f
-  touch f
-  ln -s f symlink
-  chgrp $g1 f
-  chgrp -h $g2 symlink
-
-  # This should not change the group of f.
-  chgrp -h -c $g2 symlink
-  chown --from=:$g1 -c :$g2 f
-
-  # This *should* change the group of f.
-  # Though note that the diagnostic is misleading in that
-  # it says the `group of `symlink'' has been changed.
-  chgrp -c $g1 symlink
-  chown --from=:$g1 -c :$g2 f
-
-  # If -R is specified without -H or L, -h is assumed.
-  chgrp -h $g1 f symlink
-  chgrp -R $g2 symlink
-  chown --from=:$g1 -c :$g2 f
-
-  # Make sure we can change the group of inaccessible files.
-  chmod a-r f
-  chown --from=:$g2 -c :$g1 f
-  chmod 0 f
-  chown --from=:$g1 -c :$g2 f
-
-  # chown() must not be optimized away even when
-  # the file's owner and group already have the desired value.
-  rm -f f g
-  touch f g
-  chgrp $g1 f g
-  chgrp $g2 g
-  sleep 1
-  chgrp $g1 f
-
-  # The following no-change chgrp command is supposed to update f's ctime,
-  # but on OpenBSD, it appears to be a no-op for some file system types
-  # (at least NFS) so g's ctime is more recent.  This is not a big deal;
-  # this test works fine when the files are on a local file system (/tmp).
-  chgrp '' f
-  ls -c -t f g
-
-) 2>&1 | sed "
-  s/' to .*[^0-9:].*/' to SOMENAME/
-  s/\([ :]\)$g1$/\1G1/
-  s/\([ :]\)$g2$/\1G2/
-" > actual
-
-cat <<\EOF > expected
-changed group of `f' to G1
-changed group of `f' to G2
-ownership of `f' retained
-changed group of `f' to G1
-group of `f' retained as G1
-changed group of `f' to SOMENAME
-changed group of `d/f3' to G2
-changed group of `d' to G2
-changed group of `d/f3' to G1
-changed group of `d' to G1
-changed group of `d/f3' to G2
-changed group of `d' to G2
-changed group of `d/f3' to G1
-changed group of `d' to G1
-changed group of `d' to G2
-changed ownership of `f' to :G2
-changed group of `symlink' to G1
-changed ownership of `f' to :G2
-changed ownership of `f' to :G2
-changed ownership of `f' to :G1
-changed ownership of `f' to :G2
-f
-g
-EOF
-
-cmp expected actual \
-  || { diff expected actual 1>&2; fail=1; }
+chgrp $g1 f || fail=1  ; test `stat --p=%g f` = $g1 || fail=1
+chgrp $g2 f || fail=1  ; test `stat --p=%g f` = $g2 || fail=1
+chgrp $g2 f || fail=1  ; test `stat --p=%g f` = $g2 || fail=1
+chgrp '' f  || fail=1  ; test `stat --p=%g f` = $g2 || fail=1
+chgrp $g1 f || fail=1  ; test `stat --p=%g f` = $g1 || fail=1
+chgrp $g1 f || fail=1  ; test `stat --p=%g f` = $g1 || fail=1
+chgrp --reference=f2 f ; test `stat --p=%g f` = $g2 || fail=1
+
+chgrp -R $g2 d ||fail=1; test `stat --p=%g: $d_files` = "$g2:$g2:" || fail=1
+chgrp -R $g1 d ||fail=1; test `stat --p=%g: $d_files` = "$g1:$g1:" || fail=1
+chgrp -R $g2 d ||fail=1; test `stat --p=%g: $d_files` = "$g2:$g2:" || fail=1
+chgrp -R $g1 d ||fail=1; test `stat --p=%g: $d_files` = "$g1:$g1:" || fail=1
+chgrp $g2 d    ||fail=1; test `stat --p=%g: $d_files` = "$g2:$g1:" || fail=1
+
+rm -f f
+touch f
+ln -s f symlink
+chgrp $g1 f; test `stat --printf=%g f` = $g1 || fail=1
+
+# This should not change the group of f.
+test `stat --printf=%g f` = $g1 || fail=1
+test `stat --printf=%g symlink` = $g1 || fail=1
+chgrp -h $g2 symlink
+test `stat --printf=%g f` = $g1 || fail=1
+test `stat --printf=%g symlink` = $g2 || fail=1
+
+chown --from=:$g1 :$g2 f; test `stat --printf=%g f` = $g2 || fail=1
+
+# This *should* change the group of f.
+# Though note that the diagnostic is misleading in that
+# it says the `group of `symlink'' has been changed.
+chgrp $g1 symlink; test `stat --printf=%g f` = $g1 || fail=1
+chown --from=:$g1 :$g2 f; test `stat --printf=%g f` = $g2 || fail=1
+
+# If -R is specified without -H or L, -h is assumed.
+chgrp -h $g1 f symlink; test `stat --printf=%g symlink` = $g1 || fail=1
+chgrp -R $g2 symlink
+chown --from=:$g1 :$g2 f; test `stat --printf=%g f` = $g2 || fail=1
+
+# Make sure we can change the group of inaccessible files.
+chmod a-r f
+chown --from=:$g2 :$g1 f; test `stat --printf=%g f` = $g1 || fail=1
+chmod 0 f
+chown --from=:$g1 :$g2 f; test `stat --printf=%g f` = $g2 || fail=1
+
+# chown() must not be optimized away even when
+# the file's owner and group already have the desired value.
+rm -f f g
+touch f g
+chgrp $g1 f g
+chgrp $g2 g
+sleep 1
+chgrp $g1 f
+
+# The following no-change chgrp command is supposed to update f's ctime,
+# but on OpenBSD, it appears to be a no-op for some file system types
+# (at least NFS) so g's ctime is more recent.  This is not a big deal;
+# this test works fine when the files are on a local file system (/tmp).
+chgrp '' f
+test "`ls -C -c -t f g`" = 'f  g' || \
+  {
+    case $host_triplet in
+      *openbsd*) echo ignoring known OpenBSD-specific chgrp failure 1>&2  ;;
+      *)         echo no-change chgrp failed to update ctime 1>&2; fail=1 ;;
+    esac
+  }

 (exit $fail); exit $fail
Index: tests/chgrp/Makefile.am
===================================================================
RCS file: /fetish/cu/tests/chgrp/Makefile.am,v
retrieving revision 1.7
diff -u -r1.7 Makefile.am
--- tests/chgrp/Makefile.am     3 Jul 2006 12:55:25 -0000       1.7
+++ tests/chgrp/Makefile.am     12 Sep 2006 09:49:57 -0000
@@ -4,4 +4,5 @@
 TESTS = no-x posix-H basic deref recurse
 EXTRA_DIST = $(TESTS)
 TESTS_ENVIRONMENT = \
+  host_triplet=$(host_triplet) \
   PATH="$(VG_PATH_PREFIX)`pwd`/../../src$(PATH_SEPARATOR)$$PATH"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]