Run format tests without locale support

Build format-test.cc with FMT_USE_LOCALE=0 in nolocale-test instead of a
separate test file. This replaces two ad-hoc checks with the whole format
test suite. The locale-dependent tests were guarded by the removed
FMT_STATIC_THOUSANDS_SEPARATOR macro, so the guard never took effect.
This commit is contained in:
Victor Zverovich
2026-09-27 10:15:42 -07:00
parent 225bf7f287
commit 5da4e9a3fb
5 changed files with 15 additions and 24 deletions
+2 -4
View File
@@ -2245,10 +2245,8 @@ template <typename Context> class value {
FMT_ENABLE_IF(use_formatter<T>::value || !FMT_BUILTIN_TYPES)>
FMT_CONSTEXPR FMT_INLINE value(T& x) : value(x, custom_tag()) {}
// Could accept const pointer instead, but this avoids a GCC 16+ false
// positive from `-Wmaybe-uninitialized` in Debug builds, in `named_arg_store`
// constructor. Related bug report:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127470
// A non-const pointer avoids a bogus gcc 16 -Wmaybe-uninitialized at -O0 in
// named_arg_store: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127470.
FMT_ALWAYS_INLINE value(named_arg_info<char_type>* args, size_t size)
: named_args{args, size} {}
+2 -3
View File
@@ -2793,9 +2793,8 @@ template <typename Char, typename Grouping, typename OutputIt,
FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f,
const format_specs& specs, sign s,
int exp_upper, locale_ref loc) -> OutputIt {
Char point = FMT_USE_LOCALE && specs.localized()
? detail::decimal_point<Char>(loc)
: Char('.');
bool localized = FMT_USE_LOCALE && specs.localized();
Char point = localized ? detail::decimal_point<Char>(loc) : Char('.');
int significand_size = get_significand_size(f);
int exp = f.exponent + significand_size - 1;
if (specs.type() == presentation_type::fixed ||
+4 -2
View File
@@ -128,11 +128,13 @@ if (FMT_PEDANTIC)
target_compile_options(noexception-test PRIVATE ${PEDANTIC_COMPILE_FLAGS})
endif ()
# Test that the library compiles without locale.
add_executable(nolocale-test ../src/format.cc nolocale-test.cc)
# Test that the library works without locale support.
add_executable(nolocale-test format-test.cc mock-allocator.h ${TEST_MAIN_SRC}
../src/format.cc ../src/os.cc)
target_include_directories(nolocale-test
PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_compile_definitions(nolocale-test PRIVATE FMT_USE_LOCALE=0)
target_link_libraries(nolocale-test gtest)
target_compile_options(nolocale-test
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>)
add_test(NAME nolocale-test COMMAND nolocale-test)
+7 -2
View File
@@ -1560,6 +1560,7 @@ TEST(format_test, format_int_locale) {
TEST(format_test, format_float) {
EXPECT_EQ(fmt::format("{}", 0.0f), "0");
EXPECT_EQ(fmt::format("{0:f}", 392.5f), "392.500000");
EXPECT_EQ(fmt::format("{:L}", 1234.5), "1234.5");
}
TEST(format_test, format_double) {
@@ -2250,7 +2251,9 @@ TEST(format_test, fill_via_appender) {
TEST(format_test, formatted_size) {
EXPECT_EQ(2u, fmt::formatted_size("{}", 42));
#if FMT_USE_LOCALE
EXPECT_EQ(2u, fmt::formatted_size(std::locale(), "{}", 42));
#endif
}
TEST(format_test, format_to_no_args) {
@@ -2483,7 +2486,9 @@ TEST(format_int_test, format_int) {
std::to_string(max_value<int64_t>()));
}
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
// This file is also compiled with FMT_USE_LOCALE=0 by nolocale-test, so tests
// that use std::locale must go in this block.
#if FMT_USE_LOCALE
# include <locale>
@@ -2548,7 +2553,7 @@ TEST(format_test, format_locale) {
EXPECT_EQ(fmt::format(loc, "{:10Lo}", 12345), " 30,071");
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
#endif // FMT_USE_LOCALE
struct convertible_to_nonconst_cstring {
operator char*() const {
-13
View File
@@ -1,13 +0,0 @@
// Formatting library for C++ - no-locale tests
//
// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors
// All rights reserved.
//
// For the license information refer to format.h.
#include "fmt/format.h"
int main() {
if (fmt::format("{:L}", 1234567) != "1234567") return 1;
if (fmt::format("{:L}", 1234.5) != "1234.5") return 1;
}