From 54d0219bf368640f3b532b25c6960b46c6e7467e Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Mon, 4 Mar 2024 17:21:05 +0200 Subject: [PATCH] [#3210] fix different exception message on BSD --- src/lib/util/tests/str_unittests.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/util/tests/str_unittests.cc b/src/lib/util/tests/str_unittests.cc index accaf218bd..78d28ce569 100644 --- a/src/lib/util/tests/str_unittests.cc +++ b/src/lib/util/tests/str_unittests.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -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 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'); -- 2.47.2