Skip to content

Commit 67cd2d0

Browse files
authored
Update doctest to version 2.4.12 (#1896)
1 parent 560ea5f commit 67cd2d0

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

test/common/doctest.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Modifications Copyright (c) 2020-2025 Intel Corporation
3+
Modifications Copyright (c) 2025 UXL Foundation Contributors
34
Modifications Licensed under the Apache License, Version 2.0;
45
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
56
*/
@@ -10,7 +11,7 @@
1011
//
1112
// doctest.h - the lightest feature-rich C++ single-header testing framework for unit tests and TDD
1213
//
13-
// Copyright (c) 2016-2023 Viktor Kirilov
14+
// Copyright (c) 2016-2025 Viktor Kirilov
1415
//
1516
// Distributed under the MIT Software License
1617
// See accompanying file LICENSE.txt or copy at
@@ -54,7 +55,7 @@
5455

5556
#define DOCTEST_VERSION_MAJOR 2
5657
#define DOCTEST_VERSION_MINOR 4
57-
#define DOCTEST_VERSION_PATCH 11
58+
#define DOCTEST_VERSION_PATCH 12
5859

5960
// util we need here
6061
#define DOCTEST_TOSTR_IMPL(x) #x
@@ -978,6 +979,7 @@ struct ContextOptions //!OCLINT too many fields
978979
bool no_skip; // don't skip test cases which are marked to be skipped
979980
bool gnu_file_line; // if line numbers should be surrounded with :x: and not (x):
980981
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
981983
bool no_line_numbers; // if source code line numbers should be omitted from the output
982984
bool no_debug_output; // no output in the debug console when a debugger is attached
983985
bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!!
@@ -1634,8 +1636,9 @@ DOCTEST_CLANG_SUPPRESS_WARNING_POP
16341636
// https://github.com/catchorg/Catch2/issues/870
16351637
// https://github.com/catchorg/Catch2/issues/565
16361638
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+
16391642
}
16401643

16411644
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
32993302
#define DOCTEST_CONFIG_OPTIONS_PREFIX "dt-"
33003303
#endif
33013304

3305+
#ifndef DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR
3306+
#define DOCTEST_CONFIG_OPTIONS_FILE_PREFIX_SEPARATOR ':'
3307+
#endif
3308+
33023309
#ifndef DOCTEST_THREAD_LOCAL
33033310
#if defined(DOCTEST_CONFIG_NO_MULTITHREADING) || DOCTEST_MSVC && (DOCTEST_MSVC < DOCTEST_COMPILER(19, 0, 0))
33043311
#define DOCTEST_THREAD_LOCAL
@@ -3808,15 +3815,15 @@ String::size_type String::capacity() const {
38083815
}
38093816

38103817
String String::substr(size_type pos, size_type cnt) && {
3811-
cnt = std::min(cnt, size() - 1 - pos);
3818+
cnt = std::min(cnt, size() - pos);
38123819
char* cptr = c_str();
38133820
memmove(cptr, cptr + pos, cnt);
38143821
setSize(cnt);
38153822
return std::move(*this);
38163823
}
38173824

38183825
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);
38203827
return String{ c_str() + pos, cnt };
38213828
}
38223829

@@ -3948,6 +3955,26 @@ const char* skipPathFromFilename(const char* file) {
39483955
forward = back;
39493956
return forward + 1;
39503957
}
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];
39513978
}
39523979
#endif // DOCTEST_CONFIG_DISABLE
39533980
return file;
@@ -6238,6 +6265,8 @@ namespace {
62386265
<< Whitespace(sizePrefixDisplay*1) << ":n: vs (n): for line numbers in output\n";
62396266
s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "npf, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "no-path-filenames=<bool> "
62406267
<< 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";
62416270
s << " -" DOCTEST_OPTIONS_PREFIX_DISPLAY "nln, --" DOCTEST_OPTIONS_PREFIX_DISPLAY "no-line-numbers=<bool> "
62426271
<< Whitespace(sizePrefixDisplay*1) << "0 instead of real line numbers in output\n";
62436272
// ================================================================================== << 79
@@ -6742,6 +6771,7 @@ void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) {
67426771
DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-skip", "ns", no_skip, false);
67436772
DOCTEST_PARSE_AS_BOOL_OR_FLAG("gnu-file-line", "gfl", gnu_file_line, !bool(DOCTEST_MSVC));
67446773
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, "");
67456775
DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-line-numbers", "nln", no_line_numbers, false);
67466776
DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-debug-output", "ndo", no_debug_output, false);
67476777
DOCTEST_PARSE_AS_BOOL_OR_FLAG("no-skipped-summary", "nss", no_skipped_summary, false);

0 commit comments

Comments
 (0)