From 34e3b6f73fc6e4cf14dc3fb33d49bbd2e1c12b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kr=C3=BCgler?= Date: Sun, 3 Jul 2022 18:25:34 +0200 Subject: [PATCH] Eliminate extra-test and merge it into existing std-test instead. Add conditionals for filesystem::path testing that does not run into the ambiguity problem. --- test/CMakeLists.txt | 2 -- test/ranges-std-test.cc | 26 -------------------------- test/std-test.cc | 19 ++++++++++++++++++- 3 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 test/ranges-std-test.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dda56656..5ac19629 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -78,7 +78,6 @@ add_fmt_test(printf-test) add_fmt_test(ranges-test ranges-odr-test.cc) add_fmt_test(scan-test) add_fmt_test(std-test) -add_fmt_test(ranges-std-test) try_compile(compile_result_unused ${CMAKE_CURRENT_BINARY_DIR} SOURCES ${CMAKE_CURRENT_LIST_DIR}/detect-stdfs.cc @@ -86,7 +85,6 @@ try_compile(compile_result_unused string(REGEX REPLACE ".*libfound \"([^\"]*)\".*" "\\1" STDLIBFS "${RAWOUTPUT}") if (STDLIBFS) target_link_libraries(std-test ${STDLIBFS}) - target_link_libraries(ranges-std-test ${STDLIBFS}) endif () add_fmt_test(unicode-test HEADER_ONLY) if (MSVC) diff --git a/test/ranges-std-test.cc b/test/ranges-std-test.cc deleted file mode 100644 index 6c8e8e4b..00000000 --- a/test/ranges-std-test.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Formatting library for C++ - tests for ranges and std combination -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. -// -// Copyright (c) 2022 - present, Dani-Hub (Daniel Kruegler) -// All rights reserved - -#include "fmt/ranges.h" -#include "fmt/std.h" - -#include -#include - -#include "gtest/gtest.h" - -TEST(ranges_std_test, format_vector_path) { -#ifdef __cpp_lib_filesystem - auto p = std::filesystem::path("foo/bar.txt"); - auto c = std::vector{"abc", "def"}; - EXPECT_EQ(fmt::format("path={}, range={}", p, c), - "path=\"foo/bar.txt\", range=[\"abc\", \"def\"]"); -#endif -} diff --git a/test/std-test.cc b/test/std-test.cc index 02b5a591..fc8f72a0 100644 --- a/test/std-test.cc +++ b/test/std-test.cc @@ -6,13 +6,18 @@ // For the license information refer to format.h. #include "fmt/std.h" +#include "fmt/ranges.h" #include +#include #include "gtest/gtest.h" TEST(std_test, path) { -#ifdef __cpp_lib_filesystem +// Test ambiguity problem described in #2954. We need to exclude compilers +// where the ambiguity problem cannot be solved for now. +#if defined(__cpp_lib_filesystem) && \ + (!FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920) EXPECT_EQ(fmt::format("{:8}", std::filesystem::path("foo")), "\"foo\" "); EXPECT_EQ(fmt::format("{}", std::filesystem::path("foo\"bar.txt")), "\"foo\\\"bar.txt\""); @@ -31,6 +36,18 @@ TEST(std_test, path) { #endif } +TEST(ranges_std_test, format_vector_path) { +// Test ambiguity problem described in #2954. We need to exclude compilers +// where the ambiguity problem cannot be solved for now. +#if defined(__cpp_lib_filesystem) && \ + (!FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920) + auto p = std::filesystem::path("foo/bar.txt"); + auto c = std::vector{"abc", "def"}; + EXPECT_EQ(fmt::format("path={}, range={}", p, c), + "path=\"foo/bar.txt\", range=[\"abc\", \"def\"]"); +#endif +} + TEST(std_test, thread_id) { EXPECT_FALSE(fmt::format("{}", std::this_thread::get_id()).empty()); }