since we do not rely on FMT_DEPRECATED_OSTREAM to define the
fmt::formatter for us anymore, let's stop defining `FMT_DEPRECATED_OSTREAM`.
in this change,
* utils: drop the range formatters in to_string.hh and to_string.c, as
we don't use them anymore. and the tests for them in
test/boost/string_format_test.cc are removed accordingly.
* utils: use fmt to print chunk_vector and small_vector. as
we are not able to print the elements using operator<< anymore
after switching to {fmt} formatters.
* test/boost: specialize fmt::details::is_std_string_like<bytes>
due to a bug in {fmt} v9, {fmt} fails to format a range whose
element type is `basic_sstring<uint8_t>`, as it considers it
as a string-like type, but `basic_sstring<uint8_t>`'s char type
is signed char, not char. this issue does not exist in {fmt} v10,
so, in this change, we add a workaround to explicitly specialize
the type trait to assure that {fmt} format this type using its
`fmt::formatter` specialization instead of trying to format it
as a string. also, {fmt}'s generic ranges formatter calls the
pair formatter's `set_brackets()` and `set_separator()` methods
when printing the range, but operator<< based formatter does not
provide these method, we have to include this change in the change
switching to {fmt}, otherwise the change specializing
`fmt::details::is_std_string_like<bytes>` won't compile.
* test/boost: in tests, we use `BOOST_REQUIRE_EQUAL()` and its friends
for comparing values. but without the operator<< based formatters,
Boost.Test would not be able to print them. after removing
the homebrew formatters, we need to use the generic
`boost_test_print_type()` helper to do this job. so we are
including `test_utils.hh` in tests so that we can print
the formattable types.
* treewide: add "#include "utils/to_string.hh" where
`fmt::formatter<optional<>>` is used.
* configure.py: do not define FMT_DEPRECATED_OSTREAM
* cmake: do not define FMT_DEPRECATED_OSTREAM
Refs #13245
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
98 lines
2.7 KiB
C++
98 lines
2.7 KiB
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include "test/lib/result_set_assertions.hh"
|
|
|
|
static inline
|
|
sstring to_sstring(const bytes& b) {
|
|
return sstring(b.begin(), b.end());
|
|
}
|
|
|
|
bool
|
|
row_assertion::matches(const query::result_set_row& row) const {
|
|
for (auto&& column_and_value : _expected_values) {
|
|
auto&& name = column_and_value.first;
|
|
auto&& value = column_and_value.second;
|
|
|
|
// FIXME: result_set_row works on sstring column names instead of more general "bytes".
|
|
auto ss_name = to_sstring(name);
|
|
|
|
const data_value* val = row.get_data_value(ss_name);
|
|
if (val == nullptr) {
|
|
if (!value.is_null()) {
|
|
return false;
|
|
}
|
|
} else {
|
|
if (*val != value) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
if (_only_that) {
|
|
for (auto&& e : row.cells()) {
|
|
auto name = to_bytes(e.first);
|
|
if (!_expected_values.contains(name)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
sstring
|
|
row_assertion::describe(schema_ptr schema) const {
|
|
return format("{{{}}}", fmt::join(_expected_values | boost::adaptors::transformed([&schema] (auto&& e) {
|
|
auto&& name = e.first;
|
|
auto&& value = e.second;
|
|
const column_definition* def = schema->get_column_definition(name);
|
|
if (!def) {
|
|
BOOST_FAIL(format("Schema is missing column definition for '{}'", name));
|
|
}
|
|
if (value.is_null()) {
|
|
return format("{}=null", to_sstring(name));
|
|
} else {
|
|
return format("{}=\"{}\"", to_sstring(name), def->type->to_string(def->type->decompose(value)));
|
|
}
|
|
}), ", "));
|
|
}
|
|
|
|
const result_set_assertions&
|
|
result_set_assertions::has(const row_assertion& ra) const {
|
|
for (auto&& row : _rs.rows()) {
|
|
if (ra.matches(row)) {
|
|
return *this;
|
|
}
|
|
}
|
|
BOOST_FAIL(format("Row {} not found in {}", ra.describe(_rs.schema()), _rs));
|
|
return *this;
|
|
}
|
|
|
|
const result_set_assertions&
|
|
result_set_assertions::has_only(const row_assertion& ra) const {
|
|
BOOST_REQUIRE(_rs.rows().size() == 1);
|
|
auto& row = _rs.rows()[0];
|
|
if (!ra.matches(row)) {
|
|
BOOST_FAIL(format("Expected {} but got {}", ra.describe(_rs.schema()), row));
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
const result_set_assertions&
|
|
result_set_assertions::is_empty() const {
|
|
BOOST_REQUIRE_EQUAL(_rs.rows().size(), 0);
|
|
return *this;
|
|
}
|
|
|
|
const result_set_assertions&
|
|
result_set_assertions::has_size(int row_count) const {
|
|
BOOST_REQUIRE_EQUAL(_rs.rows().size(), row_count);
|
|
return *this;
|
|
}
|