Skip to content

Commit

Permalink
use source_location::current() method
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Oct 17, 2024
1 parent ceb320f commit 517ec2c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tests/xtd.tunit.unit_tests/src/assert_unit_tests/assert_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#include "unit_test_error.h"
#include <xtd/foreground_color>
#include <xtd/reset_color>
#include <xtd/source_location>
#include <iostream>
#include <sstream>
#include <string>

namespace assert_unit_tests {
template <typename expected_t, typename actual_t>
void assert_value(const std::string& name, const expected_t& expected, const actual_t& actual, const std::string& file, int line_number) {
void assert_value(const std::string& name, const expected_t& expected, const actual_t& actual, const xtd::source_location& location = xtd::source_location::current()) {
if (actual == expected)
std::cout << xtd::foreground_color(xtd::console_color::dark_green) << " SUCCEED " << xtd::reset_color() << name << std::endl;
else {
Expand All @@ -26,14 +27,11 @@ namespace assert_unit_tests {
while (std::getline(f, line))
std::cout << " " << line << std::endl;
std::cout << " Stack trace:" << std::endl;
std::cout << " " << file << ":" << line_number << std::endl;
std::cout << " " << location.file_name() << ":" << location.line() << std::endl;
throw unit_test_error("assertion failed!");
}
}
}

#define assert_value_(expected, actual) \
assert_unit_tests::assert_value(name, expected, actual, __FILE__, __LINE__)

#define assert_value_(expected, actual) \
assert_unit_tests::assert_value(name, expected, actual, __FILE__, __LINE__)
assert_unit_tests::assert_value(name, expected, actual)

0 comments on commit 517ec2c

Please sign in to comment.