Skip to content

Commit 59a3b7d

Browse files
committed
Fix test_extreme_bucket_count_value_construction test on some platforms
Both std::bad_alloc or std::length_error excpetions can be thrown depending on the platform memory overcommit behaviour and total memory
1 parent 0c3c858 commit 59a3b7d

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

tests/robin_map_tests.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -745,41 +745,44 @@ BOOST_AUTO_TEST_CASE(test_modify_value_through_iterator_with_const_qualifier) {
745745
/**
746746
* constructor
747747
*/
748+
748749
BOOST_AUTO_TEST_CASE(test_extreme_bucket_count_value_construction) {
749-
TSL_RH_CHECK_THROW(
750+
// std::bad_alloc or std::length_error will be thrown depending on the
751+
// platform overcommit
752+
TSL_RH_CHECK_THROW_EITHER(
750753
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
751754
std::allocator<std::pair<int, int>>, false,
752755
tsl::rh::power_of_two_growth_policy<2>>(
753756
std::numeric_limits<std::size_t>::max())),
754-
std::length_error);
757+
std::bad_alloc, std::length_error);
755758

756-
TSL_RH_CHECK_THROW(
759+
TSL_RH_CHECK_THROW_EITHER(
757760
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
758761
std::allocator<std::pair<int, int>>, false,
759762
tsl::rh::power_of_two_growth_policy<2>>(
760763
std::numeric_limits<std::size_t>::max() / 2 + 1)),
761-
std::length_error);
764+
std::bad_alloc, std::length_error);
762765

763-
TSL_RH_CHECK_THROW(
766+
TSL_RH_CHECK_THROW_EITHER(
764767
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
765768
std::allocator<std::pair<int, int>>, false,
766769
tsl::rh::prime_growth_policy>(
767770
std::numeric_limits<std::size_t>::max())),
768-
std::length_error);
771+
std::bad_alloc, std::length_error);
769772

770-
TSL_RH_CHECK_THROW(
773+
TSL_RH_CHECK_THROW_EITHER(
771774
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
772775
std::allocator<std::pair<int, int>>, false,
773776
tsl::rh::prime_growth_policy>(
774777
std::numeric_limits<std::size_t>::max() / 2)),
775-
std::length_error);
778+
std::bad_alloc, std::length_error);
776779

777-
TSL_RH_CHECK_THROW(
780+
TSL_RH_CHECK_THROW_EITHER(
778781
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
779782
std::allocator<std::pair<int, int>>, false,
780783
tsl::rh::mod_growth_policy<>>(
781784
std::numeric_limits<std::size_t>::max())),
782-
std::length_error);
785+
std::bad_alloc, std::length_error);
783786
}
784787

785788
BOOST_AUTO_TEST_CASE(test_range_construct) {

tests/utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@
3636

3737
#ifdef TSL_RH_NO_EXCEPTIONS
3838
#define TSL_RH_CHECK_THROW(S, E)
39+
#define TSL_RH_CHECK_THROW_EITHER(S, E1, E2)
3940
#else
4041
#define TSL_RH_CHECK_THROW(S, E) BOOST_CHECK_THROW(S, E)
42+
#define TSL_RH_CHECK_THROW_EITHER(S, E1, E2) \
43+
do { \
44+
try { \
45+
S; \
46+
BOOST_CHECK(false); \
47+
} catch (const E1&) { \
48+
} catch (const E2&) { \
49+
} \
50+
} while (0)
4151
#endif
4252

4353
template <typename T>

0 commit comments

Comments
 (0)