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