]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3210] fix different exception message on BSD
authorAndrei Pavel <andrei@isc.org>
Mon, 4 Mar 2024 15:21:05 +0000 (17:21 +0200)
committerAndrei Pavel <andrei@isc.org>
Thu, 21 Mar 2024 16:30:04 +0000 (18:30 +0200)
src/lib/util/tests/str_unittests.cc

index accaf218bde1fc6496b6c816db192af7d8e87673..78d28ce569795108f19af7f1d5a9c8aae099f002 100644 (file)
@@ -14,6 +14,7 @@
 #include <exception>
 #include <sstream>
 #include <string>
+#include <unordered_set>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -391,8 +392,22 @@ TEST_F(StringUtilTest, decodeFormattedHexString) {
 TEST_F(StringUtilTest, stringSanitizer) {
     // Bad regular expression should throw.
     StringSanitizerPtr ss;
-    ASSERT_THROW_MSG(ss.reset(new StringSanitizer("[bogus-regex", "")), BadValue,
-                     "invalid regex: '[bogus-regex', Invalid range in bracket expression.");
+
+    try {
+        ss.reset(new StringSanitizer("[bogus-regex", ""));
+    } catch (BadValue const& ex) {
+        unordered_set<string> expected{
+            // BSD
+            "invalid regex: '[bogus-regex', The expression contained mismatched [ and ].",
+            // Linux
+            "invalid regex: '[bogus-regex', Invalid range in bracket expression.",
+        };
+        if (!expected.count(ex.what())) {
+            FAIL() << "unexpected BadValue exception message: " << ex.what();
+        }
+    } catch (exception const& ex) {
+        FAIL() << "unexpected exception: " << ex.what();
+    }
 
     string good_data(StringSanitizer::MAX_DATA_SIZE, '0');
     string bad_data(StringSanitizer::MAX_DATA_SIZE + 1, '0');