]> Savannah Git Hosting - gnulib.git/commitdiff
chown, lchown, fchownat tests: Avoid test failure on macOS 12.
authorBruno Haible <bruno@clisp.org>
Fri, 10 Feb 2023 12:46:22 +0000 (13:46 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 2 Mar 2023 20:56:07 +0000 (21:56 +0100)
* tests/test-chown.h (test_chown): Skip some assertions if
getgid() == (gid_t)-1.
* tests/test-lchown.h (test_lchown): Likewise.

ChangeLog
tests/test-chown.h
tests/test-lchown.h

index 36feddfa7e9b209b1861876357672271b1372279..74eabffda2ffafaf7e9367780b11beca4f3a5ebb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-02-10  Bruno Haible  <bruno@clisp.org>
+
+       chown, lchown, fchownat tests: Avoid test failure on macOS 12.
+       * tests/test-chown.h (test_chown): Skip some assertions if
+       getgid() == (gid_t)-1.
+       * tests/test-lchown.h (test_lchown): Likewise.
+
 2023-02-09  Bruno Haible  <bruno@clisp.org>
 
        math: Fix compilation error in C++ mode on macOS 12.5.
index c1cf7bb8f89b41b63bb03448cecfad986f2e49ef..4c7b6eec33fd2206a404daa05227ca2f381e72f1 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests of chown.
-   Copyright (C) 2009-2022 Free Software Foundation, Inc.
+   Copyright (C) 2009-2023 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
@@ -72,7 +72,10 @@ test_chown (int (*func) (char const *, uid_t, gid_t), bool print)
   ASSERT (stat (BASE "dir/file", &st1) == 0);
   ASSERT (st1.st_uid != (uid_t) -1);
   ASSERT (st1.st_gid != (gid_t) -1);
-  ASSERT (st1.st_gid == getegid ());
+  /* On macOS 12, when logged in through ssh, getgid () and getegid () are both
+     == (gid_t) -1.  */
+  if (getgid () != (gid_t) -1)
+    ASSERT (st1.st_gid == getegid ());
 
   /* Sanity check of error cases.  */
   errno = 0;
@@ -132,7 +135,8 @@ test_chown (int (*func) (char const *, uid_t, gid_t), bool print)
   if (1 < gids_count)
     {
       ASSERT (gids[1] != st1.st_gid);
-      ASSERT (gids[1] != (gid_t) -1);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] != (gid_t) -1);
       ASSERT (lstat (BASE "dir/link", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
       ASSERT (st1.st_gid == st2.st_gid);
@@ -156,7 +160,8 @@ test_chown (int (*func) (char const *, uid_t, gid_t), bool print)
       ASSERT (func (BASE "dir/link2", -1, gids[1]) == 0);
       ASSERT (stat (BASE "dir/file", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
-      ASSERT (gids[1] == st2.st_gid);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] == st2.st_gid);
       ASSERT (lstat (BASE "dir/link", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
       ASSERT (st1.st_gid == st2.st_gid);
index b1a73d45e9a2f1f6d134c0876afc032ea2fadd56..1c68f4a1bad4823b04ad3e7559b37af82877c301 100644 (file)
@@ -1,5 +1,5 @@
 /* Tests of lchown.
-   Copyright (C) 2009-2022 Free Software Foundation, Inc.
+   Copyright (C) 2009-2023 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
@@ -80,7 +80,10 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool print)
   ASSERT (stat (BASE "dir/file", &st1) == 0);
   ASSERT (st1.st_uid != (uid_t) -1);
   ASSERT (st1.st_gid != (gid_t) -1);
-  ASSERT (st1.st_gid == getegid ());
+  /* On macOS 12, when logged in through ssh, getgid () and getegid () are both
+     == (gid_t) -1.  */
+  if (getgid () != (gid_t) -1)
+    ASSERT (st1.st_gid == getegid ());
 
   /* Sanity check of error cases.  */
   errno = 0;
@@ -150,7 +153,8 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool print)
   if (1 < gids_count)
     {
       ASSERT (gids[1] != st1.st_gid);
-      ASSERT (gids[1] != (gid_t) -1);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] != (gid_t) -1);
       ASSERT (lstat (BASE "dir/link", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
       ASSERT (st1.st_gid == st2.st_gid);
@@ -180,7 +184,8 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool print)
       ASSERT (st1.st_gid == st2.st_gid);
       ASSERT (lstat (BASE "dir/link2", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
-      ASSERT (gids[1] == st2.st_gid);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] == st2.st_gid);
 
       /* Trailing slash follows through to directory.  */
       ASSERT (lstat (BASE "dir/link3", &st2) == 0);
@@ -196,7 +201,8 @@ test_lchown (int (*func) (char const *, uid_t, gid_t), bool print)
       ASSERT (st1.st_gid == st2.st_gid);
       ASSERT (lstat (BASE "dir/sub", &st2) == 0);
       ASSERT (st1.st_uid == st2.st_uid);
-      ASSERT (gids[1] == st2.st_gid);
+      if (getgid () != (gid_t) -1)
+        ASSERT (gids[1] == st2.st_gid);
     }
   else if (!CHOWN_CHANGE_TIME_BUG || HAVE_LCHMOD)
     {