kaycxx-test
C++ unit test framework
Loading...
Searching...
No Matches
assert_equal.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
11#include <format>
12#include <optional>
13#include <source_location>
14#include <string_view>
15#include <utility>
16
18#include <kaycxx/test/detail/equals.hpp>
19#include <kaycxx/test/detail/to_string.hpp>
20
21namespace kaycxx::test {
22
40template <typename Actual, typename Expected>
41requires detail::equals_supported<Actual, Expected>
43 Actual const& actual,
44 Expected const& expected,
45 std::string_view reason = {},
46 std::optional<std::source_location> location = std::source_location::current()
47) {
48 if (!detail::equals(actual, expected)) {
49 auto actual_string = detail::to_string(actual);
50 auto expected_string = detail::to_string(expected);
51 auto message = std::format("Expected <{}> to equal <{}>", actual_string, expected_string);
52 throw assertion_error(
53 message,
54 reason,
55 std::move(actual_string),
56 std::move(expected_string),
57 location
58 );
59 }
60}
61
62} // namespace kaycxx::test
Defines the assertion_error type.
Unit test framework functions and types.
Definition test.hpp:15
void assert_equal(Actual const &actual, Expected const &expected, std::string_view reason={}, std::optional< std::source_location > location=std::source_location::current())
Asserts that two values are equal.
Definition assert_equal.hpp:42