From de731efd4cbc172b8d5ce84ef7c7f39a4527d82b Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sun, 2 Jan 2022 17:03:58 +0100 Subject: [PATCH] [libc++][format] Improve an exception message. The fix in D116381 makes an existing exception message wrong. This improves the message and fixes the associated unit tests. Note other message can be also be improved, but that will be done later. Changing these messages may cause merge conflicts with other patches that are under review or WIP. Depends on D116381 Reviewed By: #libc, Quuxplusone, ldionne Differential Revision: https://reviews.llvm.org/D116495 --- libcxx/include/__format/parser_std_format_spec.h | 2 +- .../std_format_spec_bool.pass.cpp | 15 ++++------- .../std_format_spec_char.pass.cpp | 15 ++++------- .../std_format_spec_integer.pass.cpp | 15 ++++------- .../std_format_spec_string.pass.cpp | 30 ++++++++-------------- .../format/format.functions/format_tests.h | 8 ++---- 6 files changed, 28 insertions(+), 57 deletions(-) diff --git a/libcxx/include/__format/parser_std_format_spec.h b/libcxx/include/__format/parser_std_format_spec.h index 5ab6b42..6eae27d 100644 --- a/libcxx/include/__format/parser_std_format_spec.h +++ b/libcxx/include/__format/parser_std_format_spec.h @@ -214,7 +214,7 @@ __parse_arg_id(const _CharT* __begin, const _CharT* __end, auto& __parse_ctx) { __format::__parse_arg_id(__begin, __end, __parse_ctx); if (__r.__ptr == __end || *__r.__ptr != _CharT('}')) - __throw_format_error("A format-spec arg-id should terminate at a '}'"); + __throw_format_error("Invalid arg-id"); ++__r.__ptr; return __r; diff --git a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp index 90b24a2..6d233f8 100644 --- a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp +++ b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_bool.pass.cpp @@ -160,19 +160,14 @@ constexpr void test_as_string() { test_exception>("End of input while parsing format-spec arg-id", CSTR("{")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{0")); + test_exception>("Invalid arg-id", CSTR("{0")); test_exception>( "The arg-id of the format-spec starts with an invalid character", CSTR("{a")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{1")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9:")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9a")); + test_exception>("Invalid arg-id", CSTR("{1")); + test_exception>("Invalid arg-id", CSTR("{9")); + test_exception>("Invalid arg-id", CSTR("{9:")); + test_exception>("Invalid arg-id", CSTR("{9a")); static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); diff --git a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_char.pass.cpp b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_char.pass.cpp index 018f7dd..e2306e1 100644 --- a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_char.pass.cpp +++ b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_char.pass.cpp @@ -169,19 +169,14 @@ constexpr void test_as_char() { test_exception>("End of input while parsing format-spec arg-id", CSTR("{")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{0")); + test_exception>("Invalid arg-id", CSTR("{0")); test_exception>( "The arg-id of the format-spec starts with an invalid character", CSTR("{a")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{1")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9:")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9a")); + test_exception>("Invalid arg-id", CSTR("{1")); + test_exception>("Invalid arg-id", CSTR("{9")); + test_exception>("Invalid arg-id", CSTR("{9:")); + test_exception>("Invalid arg-id", CSTR("{9a")); static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); diff --git a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_integer.pass.cpp b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_integer.pass.cpp index 3e8a668..bb915e6 100644 --- a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_integer.pass.cpp +++ b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_integer.pass.cpp @@ -209,19 +209,14 @@ constexpr void test() { test_exception>("End of input while parsing format-spec arg-id", CSTR("{")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{0")); + test_exception>("Invalid arg-id", CSTR("{0")); test_exception>( "The arg-id of the format-spec starts with an invalid character", CSTR("{a")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{1")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9:")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9a")); + test_exception>("Invalid arg-id", CSTR("{1")); + test_exception>("Invalid arg-id", CSTR("{9")); + test_exception>("Invalid arg-id", CSTR("{9:")); + test_exception>("Invalid arg-id", CSTR("{9a")); static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); diff --git a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_string.pass.cpp b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_string.pass.cpp index e7bccbb..f53c6e8 100644 --- a/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_string.pass.cpp +++ b/libcxx/test/libcxx/utilities/format/format.string/format.string.std/std_format_spec_string.pass.cpp @@ -164,19 +164,14 @@ constexpr void test() { test_exception>("End of input while parsing format-spec arg-id", CSTR("{")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{0")); + test_exception>("Invalid arg-id", CSTR("{0")); test_exception>( "The arg-id of the format-spec starts with an invalid character", CSTR("{a")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{1")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9:")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR("{9a")); + test_exception>("Invalid arg-id", CSTR("{1")); + test_exception>("Invalid arg-id", CSTR("{9")); + test_exception>("Invalid arg-id", CSTR("{9:")); + test_exception>("Invalid arg-id", CSTR("{9a")); static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); @@ -226,19 +221,14 @@ constexpr void test() { test_exception>("End of input while parsing format-spec arg-id", CSTR(".{")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR(".{0")); + test_exception>("Invalid arg-id", CSTR(".{0")); test_exception>( "The arg-id of the format-spec starts with an invalid character", CSTR(".{a")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR(".{1")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR(".{9")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR(".{9:")); - test_exception>( - "A format-spec arg-id should terminate at a '}'", CSTR(".{9a")); + test_exception>("Invalid arg-id", CSTR(".{1")); + test_exception>("Invalid arg-id", CSTR(".{9")); + test_exception>("Invalid arg-id", CSTR(".{9:")); + test_exception>("Invalid arg-id", CSTR(".{9a")); static_assert(std::__format::__number_max == 2'147'483'647, "Update the assert and the test."); diff --git a/libcxx/test/std/utilities/format/format.functions/format_tests.h b/libcxx/test/std/utilities/format/format.functions/format_tests.h index 1d19719..3de307b 100644 --- a/libcxx/test/std/utilities/format/format.functions/format_tests.h +++ b/libcxx/test/std/utilities/format/format.functions/format_tests.h @@ -176,9 +176,7 @@ void format_test_string(T world, T universe, TestFunction check, "Using automatic argument numbering in manual argument numbering mode", STR("hello {0:{}}"), world, 1); // Arg-id may not have leading zeros. - check_exception( - "A format-spec arg-id should terminate at a '}'", - STR("hello {0:{01}}"), world, 1); + check_exception("Invalid arg-id", STR("hello {0:{01}}"), world, 1); // *** precision *** #if _LIBCPP_VERSION @@ -214,9 +212,7 @@ void format_test_string(T world, T universe, TestFunction check, "Using automatic argument numbering in manual argument numbering mode", STR("hello {0:.{}}"), world, 1); // Arg-id may not have leading zeros. - check_exception( - "A format-spec arg-id should terminate at a '}'", - STR("hello {0:.{01}}"), world, 1); + check_exception("Invalid arg-id", STR("hello {0:.{01}}"), world, 1); // *** locale-specific form *** check_exception("The format-spec should consume the input or end with a '}'", -- 2.7.4