Files
scylladb/test/lib/exception_utils.hh
Nadav Har'El 09a3c63345 cross-tree: allow std::source_location in clang 14
We recently (commit 6a5d9ff261) started
to use std::source_location instead of std::experimental::source_location.
However, this does not work on clang 14, because libc++ 12's
<source_location> only works if __builtin_source_location, and that is
not available on clang 14.

clang 15 is just three months old, and several relatively-recent
distributions still carry clang 14 so it would be nice to support it
as well.

So this patch adds a trivial compatibility header file, which, when
included and compiled with clang 14, it aliases the functional
std::experimental::source_location to std::source_location.

It turns out it's enough to include the new header file from three
headers that included <source_location> -  I guess all other uses
of source_location depend on those header files directly or indirectly.
We may later need to include the compatibility header file in additional
places, bug for now we don't.

Refs #12259

Signed-off-by: Nadav Har'El <nyh@scylladb.com>

Closes #12265
2022-12-11 20:28:49 +02:00

42 lines
1.4 KiB
C++

/*
* Copyright (C) 2019-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <source_location>
#include "utils/source_location-compat.hh"
#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