kaycxx-test
C++ unit test framework
Loading...
Searching...
No Matches
failure.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 <cstdint>
12#include <exception>
13#include <optional>
14#include <source_location>
15#include <string>
16#include <string_view>
17
18#include <kaycxx/assert.hpp>
19
20namespace kaycxx::test {
21
25class failure {
26public:
34 explicit failure(std::string_view description, kaycxx::assert::assertion_error const& error, std::source_location location);
35
43 explicit failure(std::string_view description, std::exception const& error, std::source_location location);
44
51 explicit failure(std::string_view description, std::source_location location);
52
58 std::string const& description() const noexcept;
59
65 std::string const& error_message() const noexcept;
66
72 std::source_location const& location() const noexcept;
73
79 std::optional<std::string> const& actual() const noexcept;
80
86 std::optional<std::string> const& expected() const noexcept;
87
88private:
90 std::string description_;
91
93 std::string error_message_;
94
96 std::source_location location_;
97
99 std::optional<std::string> actual_;
100
102 std::optional<std::string> expected_;
103};
104
105} // namespace kaycxx::test
Failure result passed to reporters when a test case or suite fails.
Definition failure.hpp:25
std::string const & error_message() const noexcept
Returns the failure message.
failure(std::string_view description, std::source_location location)
Creates a failure for a non-standard unknown exception.
failure(std::string_view description, std::exception const &error, std::source_location location)
Creates a failure from a standard exception and explicit source location.
std::string const & description() const noexcept
Returns the full test or suite description.
std::optional< std::string > const & expected() const noexcept
Returns the expected assertion value when available.
std::source_location const & location() const noexcept
Returns the source location.
failure(std::string_view description, kaycxx::assert::assertion_error const &error, std::source_location location)
Creates a failure from an assertion error.
std::optional< std::string > const & actual() const noexcept
Returns the actual assertion value when available.
Unit test framework functions and types.
Definition test.hpp:15