Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / thread / thread.threads / thread.thread.class / thread.thread.id / format.functions.vformat.pass.cpp
blob10b73175e99022e5d2041e79db36573887938395
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
9 // UNSUPPORTED: no-threads
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // TODO FMT This test should not require std::to_chars(floating-point)
14 // XFAIL: availability-fp_to_chars-missing
16 // <thread>
18 // template<class charT>
19 // struct formatter<thread::id, charT>;
21 // string vformat(string_view fmt, format_args args);
22 // wstring vformat(wstring_view fmt, wformat_args args);
24 #include <format>
25 #include <cassert>
27 #include "assert_macros.h"
28 #include "concat_macros.h"
29 #include "format.functions.tests.h"
30 #include "test_macros.h"
32 auto test = []<class CharT, class... Args>(
33 std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) {
34 std::basic_string<CharT> out = std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
35 TEST_REQUIRE(out == expected,
36 TEST_WRITE_CONCATENATED(
37 "\nFormat string ", fmt, "\nExpected output ", expected, "\nActual output ", out, '\n'));
40 auto test_exception =
41 []<class CharT, class... Args>(
42 [[maybe_unused]] std::string_view what,
43 [[maybe_unused]] std::basic_string_view<CharT> fmt,
44 [[maybe_unused]] Args&&... args) {
45 TEST_VALIDATE_EXCEPTION(
46 std::format_error,
47 [&]([[maybe_unused]] const std::format_error& e) {
48 TEST_LIBCPP_REQUIRE(
49 e.what() == what,
50 TEST_WRITE_CONCATENATED(
51 "\nFormat string ", fmt, "\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
53 TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
56 int main(int, char**) {
57 format_tests<char>(test, test_exception);
59 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
60 format_tests<wchar_t>(test, test_exception);
61 #endif
63 return 0;