Skip to content

Commit

Permalink
fixed #369 - added the ability to override file_line_to_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
onqtam committed May 17, 2020
1 parent abb0461 commit e3ce091
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
28 changes: 13 additions & 15 deletions doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3464,8 +3464,8 @@ namespace {
// matching of a string against a wildcard mask (case sensitivity configurable) taken from
// https://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing
int wildcmp(const char* str, const char* wild, bool caseSensitive) {
const char* cp = nullptr;
const char* mp = nullptr;
const char* cp = str;
const char* mp = wild;

while((*str) && (*wild != '*')) {
if((caseSensitive ? (*wild != *str) : (tolower(*wild) != tolower(*str))) &&
Expand Down Expand Up @@ -3928,15 +3928,6 @@ namespace detail {
namespace {
using namespace detail;

std::ostream& file_line_to_stream(std::ostream& s, const char* file, int line,
const char* tail = "") {
const auto opt = getContextOptions();
s << Color::LightGrey << skipPathFromFilename(file) << (opt->gnu_file_line ? ":" : "(")
<< (opt->no_line_numbers ? 0 : line) // 0 or the real num depending on the option
<< (opt->gnu_file_line ? ":" : "):") << tail;
return s;
}

#if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
struct FatalConditionHandler
{
Expand Down Expand Up @@ -4950,12 +4941,19 @@ namespace {
s << "\n";
}

virtual void file_line_to_stream(const char* file, int line,
const char* tail = "") {
s << Color::LightGrey << skipPathFromFilename(file) << (opt.gnu_file_line ? ":" : "(")
<< (opt.no_line_numbers ? 0 : line) // 0 or the real num depending on the option
<< (opt.gnu_file_line ? ":" : "):") << tail;
}

void logTestStart() {
if(hasLoggedCurrentTestStart)
return;

separator_to_stream();
file_line_to_stream(s, tc->m_file.c_str(), tc->m_line, "\n");
file_line_to_stream(tc->m_file.c_str(), tc->m_line, "\n");
if(tc->m_description)
s << Color::Yellow << "DESCRIPTION: " << Color::None << tc->m_description << "\n";
if(tc->m_test_suite && tc->m_test_suite[0] != '\0')
Expand Down Expand Up @@ -5246,7 +5244,7 @@ namespace {
void test_case_exception(const TestCaseException& e) override {
logTestStart();

file_line_to_stream(s, tc->m_file.c_str(), tc->m_line, " ");
file_line_to_stream(tc->m_file.c_str(), tc->m_line, " ");
successOrFailColoredStringToStream(false, e.is_crash ? assertType::is_require :
assertType::is_check);
s << Color::Red << (e.is_crash ? "test case CRASHED: " : "test case THREW exception: ")
Expand Down Expand Up @@ -5284,7 +5282,7 @@ namespace {

logTestStart();

file_line_to_stream(s, rb.m_file, rb.m_line, " ");
file_line_to_stream(rb.m_file, rb.m_line, " ");
successOrFailColoredStringToStream(!rb.m_failed, rb.m_at);
if((rb.m_at & (assertType::is_throws_as | assertType::is_throws_with)) ==
0) //!OCLINT bitwise operator in conditional
Expand Down Expand Up @@ -5342,7 +5340,7 @@ namespace {

logTestStart();

file_line_to_stream(s, mb.m_file, mb.m_line, " ");
file_line_to_stream(mb.m_file, mb.m_line, " ");
s << getSuccessOrFailColor(false, mb.m_severity)
<< getSuccessOrFailString(mb.m_severity & assertType::is_warn, mb.m_severity,
"MESSAGE") << ": ";
Expand Down
26 changes: 13 additions & 13 deletions doctest/parts/doctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,6 @@ namespace detail {
namespace {
using namespace detail;

std::ostream& file_line_to_stream(std::ostream& s, const char* file, int line,
const char* tail = "") {
const auto opt = getContextOptions();
s << Color::LightGrey << skipPathFromFilename(file) << (opt->gnu_file_line ? ":" : "(")
<< (opt->no_line_numbers ? 0 : line) // 0 or the real num depending on the option
<< (opt->gnu_file_line ? ":" : "):") << tail;
return s;
}

#if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
struct FatalConditionHandler
{
Expand Down Expand Up @@ -1641,9 +1632,11 @@ namespace {
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
}

#ifndef DOCTEST_INTERNAL_ERROR
#define DOCTEST_INTERNAL_ERROR(msg) \
throw_exception(std::logic_error( \
__FILE__ ":" DOCTEST_TOSTR(__LINE__) ": Internal doctest error: " msg))
#endif // DOCTEST_INTERNAL_ERROR

// clang-format off

Expand Down Expand Up @@ -2338,12 +2331,19 @@ namespace {
s << "\n";
}

virtual void file_line_to_stream(const char* file, int line,
const char* tail = "") {
s << Color::LightGrey << skipPathFromFilename(file) << (opt.gnu_file_line ? ":" : "(")
<< (opt.no_line_numbers ? 0 : line) // 0 or the real num depending on the option
<< (opt.gnu_file_line ? ":" : "):") << tail;
}

void logTestStart() {
if(hasLoggedCurrentTestStart)
return;

separator_to_stream();
file_line_to_stream(s, tc->m_file.c_str(), tc->m_line, "\n");
file_line_to_stream(tc->m_file.c_str(), tc->m_line, "\n");
if(tc->m_description)
s << Color::Yellow << "DESCRIPTION: " << Color::None << tc->m_description << "\n";
if(tc->m_test_suite && tc->m_test_suite[0] != '\0')
Expand Down Expand Up @@ -2634,7 +2634,7 @@ namespace {
void test_case_exception(const TestCaseException& e) override {
logTestStart();

file_line_to_stream(s, tc->m_file.c_str(), tc->m_line, " ");
file_line_to_stream(tc->m_file.c_str(), tc->m_line, " ");
successOrFailColoredStringToStream(false, e.is_crash ? assertType::is_require :
assertType::is_check);
s << Color::Red << (e.is_crash ? "test case CRASHED: " : "test case THREW exception: ")
Expand Down Expand Up @@ -2672,7 +2672,7 @@ namespace {

logTestStart();

file_line_to_stream(s, rb.m_file, rb.m_line, " ");
file_line_to_stream(rb.m_file, rb.m_line, " ");
successOrFailColoredStringToStream(!rb.m_failed, rb.m_at);
if((rb.m_at & (assertType::is_throws_as | assertType::is_throws_with)) ==
0) //!OCLINT bitwise operator in conditional
Expand Down Expand Up @@ -2730,7 +2730,7 @@ namespace {

logTestStart();

file_line_to_stream(s, mb.m_file, mb.m_line, " ");
file_line_to_stream(mb.m_file, mb.m_line, " ");
s << getSuccessOrFailColor(false, mb.m_severity)
<< getSuccessOrFailString(mb.m_severity & assertType::is_warn, mb.m_severity,
"MESSAGE") << ": ";
Expand Down

0 comments on commit e3ce091

Please sign in to comment.