[libc-commits] [libc] ed34cb2 - [libc] Add a test for `fputs` to check using `stdout` and `stderr`

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Fri Jun 16 09:02:04 PDT 2023


Author: Joseph Huber
Date: 2023-06-16T11:01:55-05:00
New Revision: ed34cb2cd78143a3ec99a91fe2db79bdb1ddfd85

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

LOG: [libc] Add a test for `fputs` to check using `stdout` and `stderr`

This patch adds a test directly for the `fputs` function similar to the
existing `puts` test. This lets us know that the default file pointers
are function and the `fputs` interface works.

Reviewed By: lntue

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

Added: 
    libc/test/src/stdio/fputs_test.cpp

Modified: 
    libc/test/src/stdio/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt
index cc71bf5a57bae..19fd4942de74a 100644
--- a/libc/test/src/stdio/CMakeLists.txt
+++ b/libc/test/src/stdio/CMakeLists.txt
@@ -211,6 +211,16 @@ add_libc_test(
     libc.src.stdio.puts
 )
 
+add_libc_test(
+  fputs_test
+  SUITE
+    libc_stdio_unittests
+  SRCS
+    fputs_test.cpp
+  DEPENDS
+    libc.src.stdio.fputs
+)
+
 add_libc_unittest(
   putc_test
   SUITE

diff  --git a/libc/test/src/stdio/fputs_test.cpp b/libc/test/src/stdio/fputs_test.cpp
new file mode 100644
index 0000000000000..8c206966b954a
--- /dev/null
+++ b/libc/test/src/stdio/fputs_test.cpp
@@ -0,0 +1,26 @@
+//===-- Unittests for puts ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/File/file.h"
+#include "src/stdio/fputs.h"
+
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcPutsTest, PrintOut) {
+  int result;
+
+  constexpr char simple[] = "A simple string written to stdout\n";
+  result =
+      __llvm_libc::fputs(simple, reinterpret_cast<FILE *>(__llvm_libc::stdout));
+  EXPECT_GE(result, 0);
+
+  constexpr char more[] = "A simple string written to stderr\n";
+  result =
+      __llvm_libc::fputs(more, reinterpret_cast<FILE *>(__llvm_libc::stderr));
+  EXPECT_GE(result, 0);
+}


        


More information about the libc-commits mailing list