Files
scylladb/test/lib/exception_utils.hh
Avi Kivity 6a5d9ff261 treewide: use non-experimental std::source_location
Now that we use libstdc++ 12, we can use the standardized
source_location.

Closes #12137
2022-11-30 11:06:43 +02:00

41 lines
1.4 KiB
C++

/*
* Copyright (C) 2019-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <source_location>
#include <functional>
#include <seastar/core/sstring.hh>
#include "seastarx.hh"
namespace exception_predicate {
/// Makes an exception predicate that applies \p check function to verify the exception and \p err
/// function to create an error message if the check fails.
extern std::function<bool(const std::exception&)> make(
std::function<bool(const std::exception&)> check,
std::function<sstring(const std::exception&)> err);
/// Returns a predicate that will check if the exception message contains the given fragment.
extern std::function<bool(const std::exception&)> message_contains(
const sstring& fragment,
const std::source_location& loc = std::source_location::current());
/// Returns a predicate that will check if the exception message equals the given text.
extern std::function<bool(const std::exception&)> message_equals(
const sstring& text,
const std::source_location& loc = std::source_location::current());
/// Returns a predicate that will check if the exception message matches the given regular expression.
extern std::function<bool(const std::exception&)> message_matches(
const std::string& regex,
const std::source_location& loc = std::source_location::current());
} // namespace exception_predicate