1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef TEST_SUPPORT_CONCAT_MACROS_H
10 #define TEST_SUPPORT_CONCAT_MACROS_H
15 #include "assert_macros.h"
16 #include "test_macros.h"
18 #ifndef TEST_HAS_NO_LOCALIZATION
24 # ifndef TEST_HAS_NO_LOCALIZATION
26 concept test_char_streamable
= requires(T
&& value
) { std::stringstream
{} << std::forward
<T
>(value
); };
29 // If possible concatenates message for the assertion function, else returns a
30 // default message. Not being able to stream is not considered and error. For
31 // example, streaming to std::wcerr doesn't work properly in the CI. Therefore
32 // the formatting tests should only stream to std::string.
34 // The macro TEST_WRITE_CONCATENATED can be used to evaluate the arguments
35 // lazily. This useful when using this function in combination with
37 template <class... Args
>
38 std::string
test_concat_message([[maybe_unused
]] Args
&&... args
) {
39 # ifndef TEST_HAS_NO_LOCALIZATION
40 if constexpr ((test_char_streamable
<Args
> && ...)) {
41 std::stringstream sstr
;
42 ((sstr
<< std::forward
<Args
>(args
)), ...);
46 return "Message discarded since it can't be streamed to std::cerr.\n";
49 // Writes its arguments to stderr, using the test_concat_message helper.
50 # define TEST_WRITE_CONCATENATED(...) [&] { ::test_eprintf("%s", ::test_concat_message(__VA_ARGS__).c_str()); }
52 #endif // TEST_STD_VER > 17
54 #endif // TEST_SUPPORT_CONCAT_MACROS_H