Skip to content

Commit

Permalink
Merge pull request redpanda-data#16745 from mmaslankaprv/named-type-f…
Browse files Browse the repository at this point in the history
…ormatting

u/named_type: use fmt to format named type
  • Loading branch information
mmaslankaprv authored Feb 29, 2024
2 parents 599e82b + 1b0d1d7 commit 182e420
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/v/cloud_storage/tests/partition_manifest_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ SEASTAR_THREAD_TEST_CASE(test_no_size_bytes_segment_meta) {
std::runtime_error,
[](std::runtime_error ex) {
return std::string(ex.what()).find(
"Missing size_bytes value in {10-1-v1.log} segment meta")
"Missing size_bytes value in 10-1-v1.log segment meta")
!= std::string::npos;
});
}
Expand Down Expand Up @@ -791,8 +791,8 @@ SEASTAR_THREAD_TEST_CASE(test_no_closing_bracket_meta) {
[](std::runtime_error ex) {
return std::string(ex.what()).find(
"Failed to parse partition manifest "
"{\"b0000000/meta///-2147483648_-9223372036854775808/"
"manifest.json\"}: Missing a comma or '}' after an object "
"\"b0000000/meta///-2147483648_-9223372036854775808/"
"manifest.json\": Missing a comma or '}' after an object "
"member. at offset 325")
!= std::string::npos;
});
Expand Down
4 changes: 2 additions & 2 deletions src/v/cloud_storage/tests/topic_manifest_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ SEASTAR_THREAD_TEST_CASE(wrong_compaction_strategy_throws) {
[](std::runtime_error ex) {
return std::string(ex.what()).find(
"Failed to parse topic manifest "
"{\"30000000/meta/full-test-namespace/full-test-topic/"
"topic_manifest.json\"}: Invalid compaction_strategy: "
"\"30000000/meta/full-test-namespace/full-test-topic/"
"topic_manifest.json\": Invalid compaction_strategy: "
"wrong_value")
!= std::string::npos;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SEASTAR_THREAD_TEST_CASE(test_basic_serialization) {
cluster_metadata_manifest manifest;
manifest.update(make_manifest_stream(simple_manifest_json)).get();
BOOST_CHECK_EQUAL(100, manifest.upload_time_since_epoch.count());
auto uuid_str = "{01234567-89ab-cdef-0123-456789abcdef}";
auto uuid_str = "01234567-89ab-cdef-0123-456789abcdef";
BOOST_CHECK_EQUAL(fmt::to_string(manifest.cluster_uuid), uuid_str);
BOOST_CHECK_EQUAL(7, manifest.metadata_id());
BOOST_CHECK_EQUAL(42, manifest.controller_snapshot_offset());
Expand Down
2 changes: 1 addition & 1 deletion src/v/kafka/server/tests/group_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ SEASTAR_THREAD_TEST_CASE(generate_member_id) {
SEASTAR_THREAD_TEST_CASE(group_output) {
auto g = get();
auto s = fmt::format("{}", g);
BOOST_TEST(s.find("id={g}") != std::string::npos);
BOOST_TEST(s.find("id=g") != std::string::npos);
}

SEASTAR_THREAD_TEST_CASE(group_state_output) {
Expand Down
2 changes: 1 addition & 1 deletion src/v/kafka/server/tests/member_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ SEASTAR_THREAD_TEST_CASE(vote_for_protocols) {
SEASTAR_THREAD_TEST_CASE(output_stream) {
auto m = get_member();
auto s = fmt::format("{}", m);
BOOST_TEST(s.find("id={m}") != std::string::npos);
BOOST_TEST(s.find("id=m") != std::string::npos);
}

SEASTAR_THREAD_TEST_CASE(member_serde) {
Expand Down
8 changes: 6 additions & 2 deletions src/v/utils/named_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* by the Apache License, Version 2.0
*/
#pragma once
#include <fmt/ostream.h>

#include <cstdint>
#include <limits>
#include <ostream>
Expand Down Expand Up @@ -99,7 +101,8 @@ class base_named_type<T, Tag, std::true_type> {
}

friend std::ostream& operator<<(std::ostream& o, const base_named_type& t) {
return o << "{" << t() << "}";
fmt::print(o, "{}", t._value);
return o;
};

friend std::istream& operator>>(std::istream& i, base_named_type& t) {
Expand Down Expand Up @@ -173,7 +176,8 @@ class base_named_type<T, Tag, std::false_type> {
constexpr operator type() && { return std::move(_value); }

friend std::ostream& operator<<(std::ostream& o, const base_named_type& t) {
return o << "{" << t() << "}";
fmt::print(o, "{}", t._value);
return o;
};

friend std::istream& operator>>(std::istream& i, base_named_type& t) {
Expand Down

0 comments on commit 182e420

Please sign in to comment.