Skip to content

Commit 54d0219

Browse files
committed
[#3210] fix different exception message on BSD
1 parent 7128d20 commit 54d0219

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/lib/util/tests/str_unittests.cc

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <exception>
1515
#include <sstream>
1616
#include <string>
17+
#include <unordered_set>
1718
#include <vector>
1819

1920
#include <gtest/gtest.h>
@@ -391,8 +392,22 @@ TEST_F(StringUtilTest, decodeFormattedHexString) {
391392
TEST_F(StringUtilTest, stringSanitizer) {
392393
// Bad regular expression should throw.
393394
StringSanitizerPtr ss;
394-
ASSERT_THROW_MSG(ss.reset(new StringSanitizer("[bogus-regex", "")), BadValue,
395-
"invalid regex: '[bogus-regex', Invalid range in bracket expression.");
395+
396+
try {
397+
ss.reset(new StringSanitizer("[bogus-regex", ""));
398+
} catch (BadValue const& ex) {
399+
unordered_set<string> expected{
400+
// BSD
401+
"invalid regex: '[bogus-regex', The expression contained mismatched [ and ].",
402+
// Linux
403+
"invalid regex: '[bogus-regex', Invalid range in bracket expression.",
404+
};
405+
if (!expected.count(ex.what())) {
406+
FAIL() << "unexpected BadValue exception message: " << ex.what();
407+
}
408+
} catch (exception const& ex) {
409+
FAIL() << "unexpected exception: " << ex.what();
410+
}
396411

397412
string good_data(StringSanitizer::MAX_DATA_SIZE, '0');
398413
string bad_data(StringSanitizer::MAX_DATA_SIZE + 1, '0');

0 commit comments

Comments
 (0)