[libcxx-commits] [libcxx] [libc++][print] Adds ostream overloads. (PR #73262)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 12 09:44:15 PST 2023


================
@@ -0,0 +1,165 @@
+//===----------------------------------------------------------------------===//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// UNSUPPORTED: no-filesystem
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// XFAIL: availability-fp_to_chars-missing
+// XFAIL: availability-print-missing
+
+// Clang modules do not work with the definiton of _LIBCPP_TESTING_PRINT_IS_TERMINAL
+// XFAIL: clang-modules-build
+// <ostream>
+
+// Tests the implementation of
+//  void __vprint_unicode(ostream& os, string_view fmt,
+//                        format_args args, bool write_nl);
+
+// In the library when the std::cout is redirected to a file it is no
+// longer considered a terminal and the special terminal handling is no
+// longer executed. By testing this function we can "force" emulate a
+// terminal.
+// Note write_nl is tested by the public API.
+
+#include <cstdio>
+bool is_terminal(FILE*);
+#define _LIBCPP_TESTING_PRINT_IS_TERMINAL ::is_terminal
+
+#include "filesystem_test_helper.h"
+#include <cassert>
+#include <fstream>
+#include <iostream>
+#include <ostream>
+#include <sstream>
+
+#include "test_macros.h"
+
+#include <print> // TODO REMOVE
+
+scoped_test_env env;
+std::string filename = env.create_file("output.txt");
+
+int is_terminal_calls        = 0;
+bool should_call_is_terminal = false;
+bool is_terminal_result      = false;
+bool is_terminal(FILE*) {
+  ++is_terminal_calls;
+  assert(should_call_is_terminal);
+  return is_terminal_result;
+}
+
+static void test_is_terminal_not_a_file_stream() {
----------------
ldionne wrote:

Can you please add plain-english comments that describe what these tests are doing? I generally recommend using

```
// what this is testing
{
    the test code
}
```

but if you want to stick with functions please add plain-english comments to clarify what is being tested.

https://github.com/llvm/llvm-project/pull/73262


More information about the libcxx-commits mailing list