[libc-commits] [PATCH] D152288: [libc] Add a test for `fputs` to check using `stdout` and `stderr`
Joseph Huber via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Jun 6 09:57:43 PDT 2023
jhuber6 created this revision.
jhuber6 added reviewers: sivachandra, lntue, michaelrj.
Herald added subscribers: libc-commits, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152288
Files:
libc/test/src/stdio/CMakeLists.txt
libc/test/src/stdio/fputs_test.cpp
Index: libc/test/src/stdio/fputs_test.cpp
===================================================================
--- /dev/null
+++ 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);
+}
Index: libc/test/src/stdio/CMakeLists.txt
===================================================================
--- libc/test/src/stdio/CMakeLists.txt
+++ libc/test/src/stdio/CMakeLists.txt
@@ -211,6 +211,16 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152288.528913.patch
Type: text/x-patch
Size: 1504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230606/fcee958f/attachment.bin>
More information about the libc-commits
mailing list