xref: /llvm-project/libcxx/test/std/input.output/iostream.format/print.fun/print.sh.cpp (revision 257eb74524446a919b3378afad39de37cc470ce4)
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9 // UNSUPPORTED: no-filesystem
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11 
12 // XFAIL: availability-fp_to_chars-missing
13 
14 // <print>
15 
16 // template<class... Args>
17 //   void print(format_string<Args...> fmt, Args&&... args);
18 
19 // Testing this properly is quite hard; the function unconditionally
20 // writes to stdout. When stdout is redirected to a file it is no longer
21 // considered a terminal. The function is a small wrapper around
22 //
23 // template<class... Args>
24 //   void print(FILE* stream, format_string<Args...> fmt, Args&&... args);
25 //
26 // So do minimal tests for this function and rely on the FILE* overload
27 // to do more testing.
28 //
29 // The testing is based on the testing for std::cout.
30 
31 // RUN: %{build}
32 // RUN: echo -n "1234 一二三四 true 0x0" > %t.expected
33 // RUN: %{exec} %t.exe > %t.actual
34 // RUN: diff -u %t.actual %t.expected
35 
36 #include <print>
37 
38 int main(int, char**) {
39   // The data is passed as-is so it does not depend on the encoding of the input.
40   std::print("{} {} ", 1234, "一二三四");
41   std::print("{} {}", true, nullptr);
42 
43   return 0;
44 }
45