Files
scylladb/test/lib/exception_utils.cc
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

55 lines
2.2 KiB
C++

/*
* Copyright (C) 2019-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "test/lib/exception_utils.hh"
#include <regex>
#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::experimental::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::experimental::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::experimental::source_location& loc) {
return make([=] (const std::exception& e) { return std::regex_search(e.what(), std::regex(regex)); },
[=] (const std::exception& e) {
return fmt::format("Message '{}' doesn't match '{}'\n{}:{}: invoked here",
e.what(), regex, loc.file_name(), loc.line());
});
}