mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
add tests for format string compile-time checks
This commit is contained in:
committed by
Victor Zverovich
parent
8a2c3fb88f
commit
c7f88180f6
@ -167,5 +167,37 @@ expect_compile(udl-check "
|
|||||||
#endif
|
#endif
|
||||||
")
|
")
|
||||||
|
|
||||||
|
if (CMAKE_CXX_STANDARD GREATER_EQUAL 20)
|
||||||
|
# Compile-time argument type check
|
||||||
|
expect_compile(format-string-number-spec "
|
||||||
|
#ifdef FMT_HAS_CONSTEVAL
|
||||||
|
fmt::format(\"{:d}\", 42);
|
||||||
|
#endif
|
||||||
|
")
|
||||||
|
expect_compile(format-string-number-spec-error "
|
||||||
|
#ifdef FMT_HAS_CONSTEVAL
|
||||||
|
fmt::format(\"{:d}\", \"I am not a number\");
|
||||||
|
#else
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
" ERROR)
|
||||||
|
|
||||||
|
# Compile-time argument name check
|
||||||
|
expect_compile(format-string-name "
|
||||||
|
#if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
|
||||||
|
using namespace fmt::literals;
|
||||||
|
fmt::print(\"{foo}\", \"foo\"_a=42);
|
||||||
|
#endif
|
||||||
|
")
|
||||||
|
expect_compile(format-string-name-error "
|
||||||
|
#if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
|
||||||
|
using namespace fmt::literals;
|
||||||
|
fmt::print(\"{foo}\", \"bar\"_a=42);
|
||||||
|
#else
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
" ERROR)
|
||||||
|
endif ()
|
||||||
|
|
||||||
# Run all tests
|
# Run all tests
|
||||||
run_tests()
|
run_tests()
|
||||||
|
Reference in New Issue
Block a user