[libcxx-commits] [libcxx] ef94609 - [libcxx] [test] Use LIBCPP_ASSERT for libc++-specific checks

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Apr 16 16:25:21 PDT 2022


Author: Jonathan Wakely
Date: 2022-04-17T01:23:24+02:00
New Revision: ef94609d6ebe981767788e6877b0b3b731d425af

URL: https://github.com/llvm/llvm-project/commit/ef94609d6ebe981767788e6877b0b3b731d425af
DIFF: https://github.com/llvm/llvm-project/commit/ef94609d6ebe981767788e6877b0b3b731d425af.diff

LOG: [libcxx] [test] Use LIBCPP_ASSERT for libc++-specific checks

This makes it a little easier to reuse the libc++ tests for another
std::lib (specifically libstdc++).

The regex_error::what() strings are different in other
implementations, so should be tested with LIBCPP_ASSERT so that those
checks are skipped for other implementations.

The value of ECMAScript constant is non-zero in other implementations,
and conditionally for libc++, so adjust the preprocessor condition for
that too.

Reviewed By: ldionne, #libc, philnik, Mordante

Spies: Mordante, philnik, libcxx-commits

Differential Revision: https://reviews.llvm.org/D122574

Added: 
    

Modified: 
    libcxx/test/std/re/re.badexp/regex_error.pass.cpp
    libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/re/re.badexp/regex_error.pass.cpp b/libcxx/test/std/re/re.badexp/regex_error.pass.cpp
index cd63570b248c9..f1a1237a747a7 100644
--- a/libcxx/test/std/re/re.badexp/regex_error.pass.cpp
+++ b/libcxx/test/std/re/re.badexp/regex_error.pass.cpp
@@ -25,71 +25,71 @@ int main(int, char**)
     {
         std::regex_error e(std::regex_constants::error_collate);
         assert(e.code() == std::regex_constants::error_collate);
-        assert(e.what() == std::string("The expression contained an invalid collating element name."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained an invalid collating element name."));
     }
     {
         std::regex_error e(std::regex_constants::error_ctype);
         assert(e.code() == std::regex_constants::error_ctype);
-        assert(e.what() == std::string("The expression contained an invalid character class name."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained an invalid character class name."));
     }
     {
         std::regex_error e(std::regex_constants::error_escape);
         assert(e.code() == std::regex_constants::error_escape);
-        assert(e.what() == std::string("The expression contained an invalid escaped character, or a "
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained an invalid escaped character, or a "
                "trailing escape."));
     }
     {
         std::regex_error e(std::regex_constants::error_backref);
         assert(e.code() == std::regex_constants::error_backref);
-        assert(e.what() == std::string("The expression contained an invalid back reference."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained an invalid back reference."));
     }
     {
         std::regex_error e(std::regex_constants::error_brack);
         assert(e.code() == std::regex_constants::error_brack);
-        assert(e.what() == std::string("The expression contained mismatched [ and ]."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained mismatched [ and ]."));
     }
     {
         std::regex_error e(std::regex_constants::error_paren);
         assert(e.code() == std::regex_constants::error_paren);
-        assert(e.what() == std::string("The expression contained mismatched ( and )."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained mismatched ( and )."));
     }
     {
         std::regex_error e(std::regex_constants::error_brace);
         assert(e.code() == std::regex_constants::error_brace);
-        assert(e.what() == std::string("The expression contained mismatched { and }."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained mismatched { and }."));
     }
     {
         std::regex_error e(std::regex_constants::error_badbrace);
         assert(e.code() == std::regex_constants::error_badbrace);
-        assert(e.what() == std::string("The expression contained an invalid range in a {} expression."));
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained an invalid range in a {} expression."));
     }
     {
         std::regex_error e(std::regex_constants::error_range);
         assert(e.code() == std::regex_constants::error_range);
-        assert(e.what() == std::string("The expression contained an invalid character range, "
+        LIBCPP_ASSERT(e.what() == std::string("The expression contained an invalid character range, "
                "such as [b-a] in most encodings."));
     }
     {
         std::regex_error e(std::regex_constants::error_space);
         assert(e.code() == std::regex_constants::error_space);
-        assert(e.what() == std::string("There was insufficient memory to convert the expression into "
+        LIBCPP_ASSERT(e.what() == std::string("There was insufficient memory to convert the expression into "
                "a finite state machine."));
     }
     {
         std::regex_error e(std::regex_constants::error_badrepeat);
         assert(e.code() == std::regex_constants::error_badrepeat);
-        assert(e.what() == std::string("One of *?+{ was not preceded by a valid regular expression."));
+        LIBCPP_ASSERT(e.what() == std::string("One of *?+{ was not preceded by a valid regular expression."));
     }
     {
         std::regex_error e(std::regex_constants::error_complexity);
         assert(e.code() == std::regex_constants::error_complexity);
-        assert(e.what() == std::string("The complexity of an attempted match against a regular "
+        LIBCPP_ASSERT(e.what() == std::string("The complexity of an attempted match against a regular "
                "expression exceeded a pre-set level."));
     }
     {
         std::regex_error e(std::regex_constants::error_stack);
         assert(e.code() == std::regex_constants::error_stack);
-        assert(e.what() == std::string("There was insufficient memory to determine whether the regular "
+        LIBCPP_ASSERT(e.what() == std::string("There was insufficient memory to determine whether the regular "
                "expression could match the specified character sequence."));
     }
 

diff  --git a/libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp b/libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
index 791d5ba4c7ace..012ad4fe855dc 100644
--- a/libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
+++ b/libcxx/test/std/re/re.const/re.synopt/syntax_option_type.pass.cpp
@@ -38,7 +38,8 @@ int main(int, char**)
     assert(std::regex_constants::nosubs != 0);
     assert(std::regex_constants::optimize != 0);
     assert(std::regex_constants::collate != 0);
-#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO  // https://llvm.org/PR35967
+#if !defined _LIBCPP_VERSION || defined _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
+    // https://llvm.org/PR35967
     assert(std::regex_constants::ECMAScript != 0);
 #else
     assert(std::regex_constants::ECMAScript == 0);


        


More information about the libcxx-commits mailing list