Files
scylladb/test/lib/exception_utils.cc
Pavel Emelyanov 54edb44b20 code: Stop using seastar::compat::source_location
And switch to std::source_location.
Upcoming seastar update will deprecate its compatibility layer.

The patch is

  for f in $(git grep -l 'seastar::compat::source_location'); do
    sed -e 's/seastar::compat::source_location/std::source_location/g' -i $f;
  done

and removal of few header includes.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>

Closes scylladb/scylladb#27309
2025-11-27 19:10:11 +02:00

56 lines
2.2 KiB
C++

/*
* Copyright (C) 2019-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#include "test/lib/exception_utils.hh"
#include <boost/regex.hpp>
#include <boost/test/unit_test.hpp>
#include <fmt/format.h>
#include <fmt/ostream.h>
std::function<bool(const std::exception&)> exception_predicate::make(
std::function<bool(const std::exception&)> check,
std::function<sstring(const std::exception&)> err) {
return [check = std::move(check), err = std::move(err)] (const std::exception& e) {
const bool status = check(e);
BOOST_CHECK_MESSAGE(status, err(e));
return status;
};
}
std::function<bool(const std::exception&)> exception_predicate::message_contains(
const sstring& fragment,
const std::source_location& loc) {
return make([=] (const std::exception& e) { return sstring(e.what()).find(fragment) != sstring::npos; },
[=] (const std::exception& e) {
return fmt::format("Message '{}' doesn't contain '{}'\n{}:{}: invoked here",
e.what(), fragment, loc.file_name(), loc.line());
});
}
std::function<bool(const std::exception&)> exception_predicate::message_equals(
const sstring& text,
const std::source_location& loc) {
return make([=] (const std::exception& e) { return text == e.what(); },
[=] (const std::exception& e) {
return fmt::format("Message '{}' doesn't equal '{}'\n{}:{}: invoked here",
e.what(), text, loc.file_name(), loc.line());
});
}
std::function<bool(const std::exception&)> exception_predicate::message_matches(
const std::string& regex,
const std::source_location& loc) {
// Use boost::regex since std::regex (with libstdc++ 12) uses too much stack
return make([=] (const std::exception& e) { return boost::regex_search(e.what(), boost::regex(regex)); },
[=] (const std::exception& e) {
return fmt::format("Message '{}' doesn't match '{}'\n{}:{}: invoked here",
e.what(), regex, loc.file_name(), loc.line());
});
}