xref: /llvm-project/libcxx/test/std/input.output/iostream.format/print.fun/print.sh.cpp (revision 1cf970db4e5499f6b38d9c6644935a78d758802c)
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: executor-has-no-bash
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 // TODO PRINT Use lit builtin echo
33 
34 // FILE_DEPENDENCIES: echo.sh
35 // RUN: %{build}
36 // RUN: %{exec} bash echo.sh -n "1234 一二三四 true 0x0" > %t.expected
37 // RUN: %{exec} "%t.exe" > %t.actual
38 // RUN: diff -u %t.actual %t.expected
39 
40 #include <print>
41 
42 int main(int, char**) {
43   // The data is passed as-is so it does not depend on the encoding of the input.
44   std::print("{} {} ", 1234, "一二三四");
45   std::print("{} {}", true, nullptr);
46 
47   return 0;
48 }
49