Skip to content

Commit

Permalink
changes after merging doctest#741 - changed in the docs to and also r…
Browse files Browse the repository at this point in the history
…emoved from the code.
  • Loading branch information
onqtam committed Feb 27, 2023
1 parent 78d825a commit ee3dfce
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions doc/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Defining something ```globally``` means for every source file of the binary (exe
- [**```DOCTEST_CONFIG_ASSERTS_RETURN_VALUES```**](#doctest_config_asserts_return_values)
- [**```DOCTEST_CONFIG_EVALUATE_ASSERTS_EVEN_WHEN_DISABLED```**](#doctest_config_evaluate_asserts_even_when_disabled)
- [**```DOCTEST_CONFIG_NO_CONTRADICTING_INLINE```**](#doctest_config_no_contradicting_inline)
- [**```DOCTEST_CONFIG_NO_IOSTREAM```**](#doctest_config_no_iostream)
- [**```DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM```**](#doctest_config_no_include_iostream)
- [**```DOCTEST_CONFIG_HANDLE_EXCEPTION```**](#doctest_config_handle_exception)

For most people the only configuration needed is telling **doctest** which source file should host all the implementation code:
Expand Down Expand Up @@ -303,7 +303,7 @@ Some functions in doctest are marked with both `inline` and a compiler specific

However, this is known to cause some issues with a few compilers with hard to suppress warnings. This flag disables the use of the no-inline attribute in order to suppress the warning if your build requires that.

### **```DOCTEST_CONFIG_NO_IOSTREAM```**
### **```DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM```**

This option disables any inclusion of `<iostream>`, `std::cout` and `std::cerr`. This implies that the `cout` context field must be supplied. If
```DOCTEST_CONFIG_NO_EXCEPTIONS``` is defined, then the unhandled exception is not printed to `std::cerr`.
Expand Down
28 changes: 22 additions & 6 deletions doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,9 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
#include <utility>
#include <fstream>
#include <sstream>
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#include <iostream>
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#include <algorithm>
#include <iomanip>
#include <vector>
Expand Down Expand Up @@ -3282,8 +3284,14 @@ namespace {
#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
throw e;
#else // DOCTEST_CONFIG_NO_EXCEPTIONS
#ifdef DOCTEST_CONFIG_HANDLE_EXCEPTION
DOCTEST_CONFIG_HANDLE_EXCEPTION(e);
#else // DOCTEST_CONFIG_HANDLE_EXCEPTION
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
std::cerr << "doctest will terminate because it needed to throw an exception.\n"
<< "The message was: " << e.what() << '\n';
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#endif // DOCTEST_CONFIG_HANDLE_EXCEPTION
std::terminate();
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
}
Expand Down Expand Up @@ -3358,7 +3366,7 @@ namespace detail {

namespace timer_large_integer
{

#if defined(DOCTEST_PLATFORM_WINDOWS)
using type = ULONGLONG;
#else // DOCTEST_PLATFORM_WINDOWS
Expand Down Expand Up @@ -4994,7 +5002,7 @@ namespace detail {
m_string = tlssPop();
logged = true;
}

DOCTEST_ITERATE_THROUGH_REPORTERS(log_message, *this);

const bool isWarn = m_severity & assertType::is_warn;
Expand Down Expand Up @@ -5063,7 +5071,11 @@ namespace {
mutable XmlWriter* m_writer = nullptr;
};

#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
XmlWriter( std::ostream& os = std::cout );
#else // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
XmlWriter( std::ostream& os );
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
~XmlWriter();

XmlWriter( XmlWriter const& ) = delete;
Expand Down Expand Up @@ -5545,7 +5557,7 @@ namespace {
test_case_start_impl(in);
xml.ensureTagClosed();
}

void test_case_reenter(const TestCaseData&) override {}

void test_case_end(const CurrentTestCaseStats& st) override {
Expand Down Expand Up @@ -6267,7 +6279,7 @@ namespace {
subcasesStack.clear();
currentSubcaseLevel = 0;
}

void test_case_reenter(const TestCaseData&) override {
subcasesStack.clear();
}
Expand Down Expand Up @@ -6784,8 +6796,12 @@ int Context::run() {
fstr.open(p->out.c_str(), std::fstream::out);
p->cout = &fstr;
} else {
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
// stdout by default
p->cout = &std::cout;
#else // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
return EXIT_FAILURE;
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
}
}

Expand Down Expand Up @@ -6950,7 +6966,7 @@ int Context::run() {
DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_start, tc);

p->timer.start();

bool run_test = true;

do {
Expand Down Expand Up @@ -6991,7 +7007,7 @@ DOCTEST_MSVC_SUPPRESS_WARNING_POP
run_test = false;
p->failure_flags |= TestCaseFailureReason::TooManyFailedAsserts;
}

if(!p->nextSubcaseStack.empty() && run_test)
DOCTEST_ITERATE_THROUGH_REPORTERS(test_case_reenter, tc);
if(p->nextSubcaseStack.empty())
Expand Down
22 changes: 11 additions & 11 deletions doctest/parts/doctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
#include <utility>
#include <fstream>
#include <sstream>
#ifdef DOCTEST_CONFIG_INCLUDE_IOSTREAM
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#include <iostream>
#endif
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#include <algorithm>
#include <iomanip>
#include <vector>
Expand Down Expand Up @@ -197,11 +197,11 @@ namespace {
#else // DOCTEST_CONFIG_NO_EXCEPTIONS
#ifdef DOCTEST_CONFIG_HANDLE_EXCEPTION
DOCTEST_CONFIG_HANDLE_EXCEPTION(e);
#else
#ifdef DOCTEST_CONFIG_INCLUDE_IOSTREAM
#else // DOCTEST_CONFIG_HANDLE_EXCEPTION
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
std::cerr << "doctest will terminate because it needed to throw an exception.\n"
<< "The message was: " << e.what() << '\n';
#endif // DOCTEST_CONFIG_INCLUDE_IOSTREAM
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#endif // DOCTEST_CONFIG_HANDLE_EXCEPTION
std::terminate();
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
Expand Down Expand Up @@ -1982,11 +1982,11 @@ namespace {
mutable XmlWriter* m_writer = nullptr;
};

#ifdef DOCTEST_CONFIG_INCLUDE_IOSTREAM
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
XmlWriter( std::ostream& os = std::cout );
#else
#else // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
XmlWriter( std::ostream& os );
#endif
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
~XmlWriter();

XmlWriter( XmlWriter const& ) = delete;
Expand Down Expand Up @@ -3707,12 +3707,12 @@ int Context::run() {
fstr.open(p->out.c_str(), std::fstream::out);
p->cout = &fstr;
} else {
#ifdef DOCTEST_CONFIG_INCLUDE_IOSTREAM
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
// stdout by default
p->cout = &std::cout;
#else
#else // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
return EXIT_FAILURE;
#endif
#endif // DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
}
}

Expand Down
5 changes: 0 additions & 5 deletions doctest/parts/doctest_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,6 @@ DOCTEST_MSVC_SUPPRESS_WARNING(4623) // default constructor was implicitly define
#endif
#endif // DOCTEST_NO_SANITIZE_INTEGER

// Should std::cout/std::cerr ever be used by doctest?
#ifndef DOCTEST_CONFIG_NO_INCLUDE_IOSTREAM
#define DOCTEST_CONFIG_INCLUDE_IOSTREAM
#endif

// =================================================================================================
// == FEATURE DETECTION END ========================================================================
// =================================================================================================
Expand Down

0 comments on commit ee3dfce

Please sign in to comment.