Skip to content

Commit

Permalink
if no unit test and is in debug generates assert otherwise generates …
Browse files Browse the repository at this point in the history
…exception
  • Loading branch information
gammasoft71 committed Oct 5, 2023
1 parent 014ffc3 commit 98884f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/xtd.tunit/include/xtd/tunit/base_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "abort_error.h"
#include "assert_error.h"
#include "ignore_error.h"
#include <xtd/environment>
#include <xtd/types>
#include <xtd/typeof>
#include <xtd/ustring>
Expand Down Expand Up @@ -213,6 +214,9 @@ namespace xtd {
/// @return The xtd::ustring that contains the joined string.
static xtd::ustring join_items(const xtd::ustring& str);
/// @}

private:
static bool is_debug() noexcept {return environment::compiler_version().build_type() == build_type::debug;}
};
}
}
7 changes: 5 additions & 2 deletions src/xtd.tunit/src/xtd/tunit/base_assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../../../include/xtd/tunit/settings.h"
#include "../../../include/xtd/tunit/unit_test.h"
#include "../../../include/xtd/tunit/test.h"
#include <xtd/diagnostics/assert>

using namespace std;
using namespace xtd;
Expand Down Expand Up @@ -45,7 +46,7 @@ void base_assert::fail(const ustring& message) {
}

void base_assert::fail(const ustring& message, const stack_frame& stack_frame) {
base_assert::fail("", "", message, stack_frame);
fail("", "", message, stack_frame);
}

void base_assert::error() {
Expand Down Expand Up @@ -81,7 +82,9 @@ void base_assert::fail(const ustring& expected, const ustring& actual, const ust
test::current_test().expect_ = expected;
test::current_test().status_ = test::test_status::failed;
}
throw assert_error(message != ""_s ? message : "assertion failed!"_s);
if (!test::has_current_unit_test() && is_debug()) {
assert_(false, message != ""_s ? message : "assertion failed!"_s);
} else throw assert_error(message != ""_s ? message : "assertion failed!"_s);
}

void base_assert::ignore() {
Expand Down

0 comments on commit 98884f6

Please sign in to comment.