[libc-commits] [libc] 707996e - [libc] handle case where /dev/tty doesn't exist

Michael Jones via libc-commits libc-commits at lists.llvm.org
Mon Oct 10 15:41:01 PDT 2022


Author: Michael Jones
Date: 2022-10-10T15:40:52-07:00
New Revision: 707996e486df11db0ff28695e75a2375db20030c

URL: https://github.com/llvm/llvm-project/commit/707996e486df11db0ff28695e75a2375db20030c
DIFF: https://github.com/llvm/llvm-project/commit/707996e486df11db0ff28695e75a2375db20030c.diff

LOG: [libc] handle case where /dev/tty doesn't exist

In the isatty test it was assumed that /dev/tty existed, but that's not
always the case. Now we check for that.

Differential Revision: https://reviews.llvm.org/D135626

Added: 
    

Modified: 
    libc/test/src/unistd/isatty_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/unistd/isatty_test.cpp b/libc/test/src/unistd/isatty_test.cpp
index 28e4659dc2a6..79e0e0eb1467 100644
--- a/libc/test/src/unistd/isatty_test.cpp
+++ b/libc/test/src/unistd/isatty_test.cpp
@@ -38,10 +38,11 @@ TEST(LlvmLibcIsATTYTest, BadFdTest) {
 TEST(LlvmLibcIsATTYTest, DevTTYTest) {
   constexpr const char *TTY_FILE = "/dev/tty";
   int fd = __llvm_libc::open(TTY_FILE, O_RDONLY);
-  ASSERT_EQ(errno, 0);
-  ASSERT_GT(fd, 0);
-  EXPECT_THAT(__llvm_libc::isatty(fd), Succeeds(1));
-  ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
+  if (fd > 0) {
+    ASSERT_EQ(errno, 0);
+    EXPECT_THAT(__llvm_libc::isatty(fd), Succeeds(1));
+    ASSERT_THAT(__llvm_libc::close(fd), Succeeds(0));
+  }
 }
 
 TEST(LlvmLibcIsATTYTest, FileTest) {


        


More information about the libc-commits mailing list