From a05eb1d0dbe3d85fb3149c3f14970a39c7994f0d Mon Sep 17 00:00:00 2001
From: Enrico Seiler <enrico.seiler@hotmail.de>
Date: Thu, 22 Aug 2019 16:23:11 +0200
Forwarded: https://github.com/seqan/seqan3/pull/1223
Subject: [PATCH] [FIX] Do not test file permissions when running as root

---
 .../format_parse_validators_test.cpp          | 32 +++++++++++++++----
 1 file changed, 26 insertions(+), 6 deletions(-)

--- seqan3.orig/test/unit/argument_parser/format_parse_validators_test.cpp
+++ seqan3/test/unit/argument_parser/format_parse_validators_test.cpp
@@ -327,8 +327,12 @@
     }
 }
 
-#if __has_include(<filesystem>)
 // Setting the permissions with perm_options is not available in the experimental/filesystem branch.
+#if __has_include(<filesystem>)
+// We need to be able to check for user `root` since `root` will always have all permissions
+#if __has_include(<unistd.h>)
+#include <unistd.h>
+
 TEST(validator_test, inputfile_not_readable)
 {
     test::tmp_filename tmp_name{"my_file.test"};
@@ -342,7 +346,10 @@
                                  std::filesystem::perms::others_read,
                                  std::filesystem::perm_options::remove);
 
-    EXPECT_THROW(input_file_validator{}(tmp_file), parser_invalid_argument);
+    if (getuid())
+    {
+        EXPECT_THROW(input_file_validator{}(tmp_file), parser_invalid_argument);
+    }
 
     std::filesystem::permissions(tmp_file,
                                  std::filesystem::perms::owner_read | std::filesystem::perms::group_read |
@@ -364,7 +371,10 @@
                                  std::filesystem::perms::others_read,
                                  std::filesystem::perm_options::remove);
 
-    EXPECT_THROW(input_directory_validator{}(tmp_dir), parser_invalid_argument);
+    if (getuid())
+    {
+        EXPECT_THROW(input_directory_validator{}(tmp_dir), parser_invalid_argument);
+    }
 
     std::filesystem::permissions(tmp_dir,
                                  std::filesystem::perms::owner_read | std::filesystem::perms::group_read |
@@ -385,7 +395,10 @@
                                  std::filesystem::perms::others_write,
                                  std::filesystem::perm_options::remove);
 
-    EXPECT_THROW(output_file_validator{}(tmp_file), parser_invalid_argument);
+    if (getuid())
+    {
+        EXPECT_THROW(output_file_validator{}(tmp_file), parser_invalid_argument);
+    }
 
     // make sure we can remove the directory.
     std::filesystem::permissions(tmp_file.parent_path(),
@@ -408,7 +421,10 @@
                                      std::filesystem::perms::others_write,
                                      std::filesystem::perm_options::remove);
 
-        EXPECT_THROW(output_directory_validator{}(tmp_dir), parser_invalid_argument);
+        if (getuid())
+        {
+            EXPECT_THROW(output_directory_validator{}(tmp_dir), parser_invalid_argument);
+        }
 
         // make sure we can remove the directory.
         std::filesystem::permissions(tmp_dir.parent_path(),
@@ -430,7 +446,10 @@
                                      std::filesystem::perms::others_write,
                                      std::filesystem::perm_options::remove);
 
-        EXPECT_THROW(output_directory_validator{}(tmp_dir), parser_invalid_argument);
+        if (getuid())
+        {
+            EXPECT_THROW(output_directory_validator{}(tmp_dir), parser_invalid_argument);
+        }
 
         // make sure we can remove the directory.
         std::filesystem::permissions(tmp_dir,
@@ -439,6 +458,7 @@
                                      std::filesystem::perm_options::add);
     }
 }
+#endif // __has_include(<unistd.h>)
 #endif // __has_include(<filesystem>)
 
 TEST(validator_test, arithmetic_range_validator_success)
