|
1 | 1 | /* |
2 | 2 | Modifications Copyright (c) 2020-2025 Intel Corporation |
| 3 | + Modifications Copyright (c) 2025 UXL Foundation Contributors |
3 | 4 | Modifications Licensed under the Apache License, Version 2.0; |
4 | 5 | You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
5 | 6 | */ |
|
10 | 11 | // |
11 | 12 | // doctest.h - the lightest feature-rich C++ single-header testing framework for unit tests and TDD |
12 | 13 | // |
13 | | -// Copyright (c) 2016-2023 Viktor Kirilov |
| 14 | +// Copyright (c) 2016-2025 Viktor Kirilov |
14 | 15 | // |
15 | 16 | // Distributed under the MIT Software License |
16 | 17 | // See accompanying file LICENSE.txt or copy at |
|
54 | 55 |
|
55 | 56 | #define DOCTEST_VERSION_MAJOR 2 |
56 | 57 | #define DOCTEST_VERSION_MINOR 4 |
57 | | -#define DOCTEST_VERSION_PATCH 11 |
| 58 | +#define DOCTEST_VERSION_PATCH 12 |
58 | 59 |
|
59 | 60 | // util we need here |
60 | 61 | #define DOCTEST_TOSTR_IMPL(x) #x |
@@ -978,6 +979,7 @@ struct ContextOptions //!OCLINT too many fields |
978 | 979 | bool no_skip; // don't skip test cases which are marked to be skipped |
979 | 980 | bool gnu_file_line; // if line numbers should be surrounded with :x: and not (x): |
980 | 981 | bool no_path_in_filenames; // if the path to files should be removed from the output |
| 982 | + String strip_file_prefixes;// remove the longest matching one of these prefixes from any file paths in the output |
981 | 983 | bool no_line_numbers; // if source code line numbers should be omitted from the output |
982 | 984 | bool no_debug_output; // no output in the debug console when a debugger is attached |
983 | 985 | bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!! |
@@ -1634,8 +1636,9 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP |
1634 | 1636 | // https://github.com/catchorg/Catch2/issues/870 |
1635 | 1637 | // https://github.com/catchorg/Catch2/issues/565 |
1636 | 1638 | template <typename L> |
1637 | | - Expression_lhs<L> operator<<(L&& operand) { |
1638 | | - return Expression_lhs<L>(static_cast<L&&>(operand), m_at); |
| 1639 | + Expression_lhs<const L&&> operator<<(const L&& operand) { //bitfields bind to universal ref but not const rvalue ref |
| 1640 | + return Expression_lhs<const L&&>(static_cast<const L&&>(operand), m_at); |
| 1641 | + |
1639 | 1642 | } |
1640 | 1643 |
|
1641 | 1644 | template <typename L,typename types::enable_if<!doctest::detail::types::is_rvalue_reference<L>::value,void >::type* = nullptr> |
@@ -3299,6 +3302,10 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END |
3299 | 3302 | #define DOCTEST_CONFIG_OPTIONS_PREFIX "dt-" |
3300 | 3303 | #endif |
3301 | 3304 |
|
| 3305 | +#ifndef DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR |
| 3306 | +#define DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR ':' |
| 3307 | +#endif |
| 3308 | + |
3302 | 3309 | #ifndef DOCTEST_THREAD_LOCAL |
3303 | 3310 | #if defined(DOCTEST_CONFIG_NO_MULTITHREADING) || DOCTEST_MSVC && (DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0)) |
3304 | 3311 | #define DOCTEST_THREAD_LOCAL |
@@ -3808,15 +3815,15 @@ String::size_type String::capacity() const { |
3808 | 3815 | } |
3809 | 3816 |
|
3810 | 3817 | String String::substr(size_type pos, size_type cnt) && { |
3811 | | - cnt = std::min(cnt, size() - 1 - pos); |
| 3818 | + cnt = std::min(cnt, size() - pos); |
3812 | 3819 | char* cptr = c_str(); |
3813 | 3820 | memmove(cptr, cptr + pos, cnt); |
3814 | 3821 | setSize(cnt); |
3815 | 3822 | return std::move(*this); |
3816 | 3823 | } |
3817 | 3824 |
|
3818 | 3825 | String String::substr(size_type pos, size_type cnt) const & { |
3819 | | - cnt = std::min(cnt, size() - 1 - pos); |
| 3826 | + cnt = std::min(cnt, size() - pos); |
3820 | 3827 | return String{ c_str() + pos, cnt }; |
3821 | 3828 | } |
3822 | 3829 |
|
@@ -3948,6 +3955,26 @@ const char* skipPathFromFilename(const char* file) { |
3948 | 3955 | forward = back; |
3949 | 3956 | return forward + 1; |
3950 | 3957 | } |
| 3958 | + } else { |
| 3959 | + const auto prefixes = getContextOptions()->strip_file_prefixes; |
| 3960 | + const char separator = DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR; |
| 3961 | + String::size_type longest_match = 0U; |
| 3962 | + for(String::size_type pos = 0U; pos < prefixes.size(); ++pos) |
| 3963 | + { |
| 3964 | + const auto prefix_start = pos; |
| 3965 | + pos = std::min(prefixes.find(separator, prefix_start), prefixes.size()); |
| 3966 | + |
| 3967 | + const auto prefix_size = pos - prefix_start; |
| 3968 | + if(prefix_size > longest_match) |
| 3969 | + { |
| 3970 | + // TODO under DOCTEST_MSVC: does the comparison need strnicmp() to work with drive letter capitalization? |
| 3971 | + if(0 == std::strncmp(prefixes.c_str() + prefix_start, file, prefix_size)) |
| 3972 | + { |
| 3973 | + longest_match = prefix_size; |
| 3974 | + } |
| 3975 | + } |
| 3976 | + } |
| 3977 | + return &file[longest_match]; |
3951 | 3978 | } |
3952 | 3979 | #endif // DOCTEST_CONFIG_DISABLE |
3953 | 3980 | return file; |
@@ -6238,6 +6265,8 @@ namespace { |
6238 | 6265 | << Whitespace(sizePrefixDisplay*1) << ":n: vs (n): for line numbers in output\n"; |
6239 | 6266 | s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "npf, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "no-path-filenames=<bool> " |
6240 | 6267 | << Whitespace(sizePrefixDisplay*1) << "only filenames and no paths in output\n"; |
| 6268 | + s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "spp, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "skip-path-prefixes=<p1:p2> " |
| 6269 | + << Whitespace(sizePrefixDisplay*1) << "whenever file paths start with this prefix, remove it from the output\n"; |
6241 | 6270 | s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "nln, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "no-line-numbers=<bool> " |
6242 | 6271 | << Whitespace(sizePrefixDisplay*1) << "0 instead of real line numbers in output\n"; |
6243 | 6272 | // ================================================================================== << 79 |
@@ -6742,6 +6771,7 @@ void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) { |
6742 | 6771 | DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-skip", "ns", no_skip, false); |
6743 | 6772 | DOCTEST_PARSE_AS_BOOL_OR_FLAG("gnu-file-line", "gfl", gnu_file_line, !bool(DOCTEST_MSVC)); |
6744 | 6773 | DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-path-filenames", "npf", no_path_in_filenames, false); |
| 6774 | + DOCTEST_PARSE_STR_OPTION("strip-file-prefixes", "sfp", strip_file_prefixes, ""); |
6745 | 6775 | DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-line-numbers", "nln", no_line_numbers, false); |
6746 | 6776 | DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-debug-output", "ndo", no_debug_output, false); |
6747 | 6777 | DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-skipped-summary", "nss", no_skipped_summary, false); |
|
0 commit comments