Skip to content

Commit ad0f31c

Browse files
koniarikJan Koniarik
andauthored
Enabled bin_to_hex utest for stdformat, fixed std::formatter (#3315)
* Enabled bin_to_hex utest for stdformat, and fixed std::formatter * fixed usage of \ in macos.yml * explicitly cast diff variable in test_sink * moved from ::iterator to decltype * added fix for custom callbacks --------- Co-authored-by: Jan Koniarik <veverak@Jans-MacBook-Pro.local>
1 parent 96a8f62 commit ad0f31c

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

.github/workflows/macos.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ jobs:
99
build:
1010
runs-on: macOS-latest
1111
name: "macOS Clang (C++11, Release)"
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
config:
16+
- USE_STD_FORMAT: 'ON'
17+
BUILD_EXAMPLE: 'OFF'
18+
- USE_STD_FORMAT: 'OFF'
19+
BUILD_EXAMPLE: 'ON'
20+
1221
steps:
1322
- uses: actions/checkout@v4
1423
- name: Build
@@ -17,12 +26,13 @@ jobs:
1726
cmake .. \
1827
-DCMAKE_BUILD_TYPE=Release \
1928
-DCMAKE_CXX_STANDARD=11 \
20-
-DSPDLOG_BUILD_EXAMPLE=ON \
21-
-DSPDLOG_BUILD_EXAMPLE_HO=ON \
29+
-DSPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} \
30+
-DSPDLOG_BUILD_EXAMPLE_HO=${{ matrix.config.BUILD_EXAMPLE }} \
2231
-DSPDLOG_BUILD_WARNINGS=ON \
2332
-DSPDLOG_BUILD_BENCH=OFF \
2433
-DSPDLOG_BUILD_TESTS=ON \
2534
-DSPDLOG_BUILD_TESTS_HO=OFF \
35+
-DSPDLOG_USE_STD_FORMAT=${{ matrix.config.USE_STD_FORMAT }} \
2636
-DSPDLOG_SANITIZE_ADDRESS=OFF
2737
make -j 4
2838
ctest -j 4 --output-on-failure

include/spdlog/fmt/bin_to_hex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace
102102

103103
template <typename T>
104104
struct formatter<spdlog::details::dump_info<T>, char> {
105-
const char delimiter = ' ';
105+
char delimiter = ' ';
106106
bool put_newlines = true;
107107
bool put_delimiters = true;
108108
bool use_uppercase = false;

tests/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ set(SPDLOG_UTESTS_SOURCES
4848
test_cfg.cpp
4949
test_time_point.cpp
5050
test_stopwatch.cpp
51-
test_circular_q.cpp)
51+
test_circular_q.cpp
52+
test_bin_to_hex.cpp)
5253

5354
if(NOT SPDLOG_NO_EXCEPTIONS)
5455
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
@@ -58,10 +59,6 @@ if(systemd_FOUND)
5859
list(APPEND SPDLOG_UTESTS_SOURCES test_systemd.cpp)
5960
endif()
6061

61-
if(NOT SPDLOG_USE_STD_FORMAT)
62-
list(APPEND SPDLOG_UTESTS_SOURCES test_bin_to_hex.cpp)
63-
endif()
64-
6562
enable_testing()
6663

6764
function(spdlog_prepare_test test_target spdlog_lib)

tests/test_custom_callbacks.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ TEST_CASE("custom_callback_logger", "[custom_callback_logger]") {
1616
spdlog::memory_buf_t formatted;
1717
formatter.format(msg, formatted);
1818
auto eol_len = strlen(spdlog::details::os::default_eol);
19-
lines.emplace_back(formatted.begin(), formatted.end() - eol_len);
19+
using diff_t = typename std::iterator_traits<decltype(formatted.end())>::difference_type;
20+
lines.emplace_back(formatted.begin(), formatted.end() - static_cast<diff_t>(eol_len));
2021
});
2122
std::shared_ptr<spdlog::sinks::test_sink_st> test_sink(new spdlog::sinks::test_sink_st);
2223

tests/test_sink.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class test_sink : public base_sink<Mutex> {
4747
base_sink<Mutex>::formatter_->format(msg, formatted);
4848
// save the line without the eol
4949
auto eol_len = strlen(details::os::default_eol);
50+
using diff_t = typename std::iterator_traits<decltype(formatted.end())>::difference_type;
5051
if (lines_.size() < lines_to_save) {
51-
lines_.emplace_back(formatted.begin(), formatted.end() - eol_len);
52+
lines_.emplace_back(formatted.begin(), formatted.end() - static_cast<diff_t>(eol_len));
5253
}
5354
msg_counter_++;
5455
std::this_thread::sleep_for(delay_);

0 commit comments

Comments
 (0)