kaycxx-test
C++ unit test framework
Loading...
Searching...
No Matches
assert_null.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/nullable.hpp>
19#include <kaycxx/test/detail/to_string.hpp>
20
21namespace kaycxx::test {
22
34template <detail::nullable T>
36 T const& actual,
37 std::string_view reason = {},
38 std::optional<std::source_location> location = std::source_location::current()
39) {
40 if (!(actual == nullptr)) {
41 auto actual_string = detail::to_string(actual);
42 auto message = std::format("Expected <{}> to be null", actual_string);
43 throw assertion_error(
44 message,
45 reason,
46 std::move(actual_string),
47 "null",
48 location
49 );
50 }
51}
52
53} // namespace kaycxx::test
Defines the assertion_error type.
Unit test framework functions and types.
Definition test.hpp:15
void assert_null(T const &actual, std::string_view reason={}, std::optional< std::source_location > location=std::source_location::current())
Asserts that the argument is null.
Definition assert_null.hpp:35