[libc-commits] [PATCH] D135626: [libc] handle case where /dev/tty doesn't exist

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Oct 10 15:40:31 PDT 2022


michaelrj created this revision.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135626

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


Index: libc/test/src/unistd/isatty_test.cpp
===================================================================
--- libc/test/src/unistd/isatty_test.cpp
+++ libc/test/src/unistd/isatty_test.cpp
@@ -38,10 +38,11 @@
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135626.466649.patch
Type: text/x-patch
Size: 707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221010/550c9987/attachment.bin>


More information about the libc-commits mailing list