Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / format / format.tuple / format.functions.format.pass.cpp
blob8cdcc9d081d4be85af8201b444a31f4f301fb212
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 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
12 // TODO FMT This test should not require std::to_chars(floating-point)
13 // XFAIL: availability-fp_to_chars-missing
15 // <format>
17 // template<class charT, formattable<charT>... Ts>
18 // struct formatter<pair-or-tuple<Ts...>, charT>
20 // tested in the format functions
22 // template<class... Args>
23 // string format(format-string<Args...> fmt, const Args&... args);
24 // template<class... Args>
25 // wstring format(wformat-string<Args...> fmt, const Args&... args);
27 #include <format>
28 #include <cassert>
30 #include "format.functions.tests.h"
31 #include "test_format_string.h"
32 #include "test_macros.h"
33 #include "assert_macros.h"
34 #include "concat_macros.h"
36 auto test = []<class CharT, class... Args>(
37 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) {
38 std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...);
39 TEST_REQUIRE(out == expected,
40 TEST_WRITE_CONCATENATED(
41 "\nFormat string ", fmt.get(), "\nExpected output ", expected, "\nActual output ", out, '\n'));
44 auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
45 // After P2216 most exceptions thrown by std::format become ill-formed.
46 // Therefore this tests does nothing.
47 // A basic ill-formed test is done in format.verify.cpp
48 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument.
51 int main(int, char**) {
52 run_tests<char>(test, test_exception);
54 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
55 run_tests<wchar_t>(test, test_exception);
56 #endif
58 return 0;