Skip to content

Commit

Permalink
Update libcxx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Nov 15, 2024
1 parent 9cd7c4c commit 968ac1c
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 105 deletions.
2 changes: 2 additions & 0 deletions test/sources/libcxx/Support.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <cmath>
#include <optional>

#include "../../../include/momo/Version.h"

//#define LIBCPP_HAS_BAD_NEWS_FOR_MOMO

#if defined(__cpp_lib_containers_ranges)
Expand Down
12 changes: 2 additions & 10 deletions test/sources/libcxx/map/map.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main(int, char**)
}
#endif

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
momo::stdish::map m{ P{1,1L}, P{2,2L}, P{1,1L}, P{INT_MAX,1L}, P{3,1L} };

Expand Down Expand Up @@ -140,16 +140,14 @@ int main(int, char**)
assert(m.get_allocator().get_id() == 45);
}

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
// Examples from LWG3025
momo::stdish::map m{std::pair{1, 1}, {2, 2}, {3, 3}};
ASSERT_SAME_TYPE(decltype(m), momo::stdish::map<int, int>);

#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
momo::stdish::map m2{m.begin(), m.end()};
ASSERT_SAME_TYPE(decltype(m2), momo::stdish::map<int, int>);
#endif
}
#endif

Expand All @@ -158,13 +156,9 @@ int main(int, char**)
momo::stdish::map m1{{std::pair{1, 2}, {3, 4}}, std::less<int>()};
ASSERT_SAME_TYPE(decltype(m1), momo::stdish::map<int, int>);

#if !defined(TEST_GCC) && !defined(TEST_CLANG)
#if MOMO_VERSION_MAJOR > 3
using value_type = std::pair<const int, int>;
momo::stdish::map m2{{value_type{1, 2}, {3, 4}}, std::less<int>()};
ASSERT_SAME_TYPE(decltype(m2), momo::stdish::map<int, int>);
#endif
#endif
}

#if TEST_STD_VER >= 23
Expand Down Expand Up @@ -196,10 +190,8 @@ int main(int, char**)
}
#endif

#if MOMO_VERSION_MAJOR > 3
//AssociativeContainerDeductionGuidesSfinaeAway<std::map, std::map<int, long>>();
AssociativeContainerDeductionGuidesSfinaeAway<momo::stdish::map, momo::stdish::map<int, long>>();
#endif

return 0;
}
8 changes: 2 additions & 6 deletions test/sources/libcxx/map/map.cons/deduct_const.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,23 @@ int main(int, char**)
}
#endif

#if !defined(TEST_GCC) && !defined(TEST_CLANG)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
momo::stdish::map m{ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} };

ASSERT_SAME_TYPE(decltype(m), momo::stdish::map<int, long>);
const PC expected_m[] = { {1, 1L}, {2,2L}, {3,1L}, {INT_MAX,1L} };
assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
}
#endif

#if MOMO_VERSION_MAJOR > 3
{
momo::stdish::map m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, std::greater<int>());

ASSERT_SAME_TYPE(decltype(m), momo::stdish::map<int, long, std::greater<int>>);
const PC expected_m[] = { {INT_MAX,1L}, {3,1L}, {2,2L}, {1, 1L} };
assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
}
#endif

{
momo::stdish::map m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, std::greater<int>(), test_allocator<PC>(0, 43));
Expand All @@ -93,7 +92,6 @@ int main(int, char**)
assert(m.get_allocator().get_id() == 43);
}

#if MOMO_VERSION_MAJOR > 3
{
momo::stdish::map m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, test_allocator<PC>(0, 45));

Expand All @@ -102,8 +100,6 @@ int main(int, char**)
assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
assert(m.get_allocator().get_id() == 45);
}
#endif
#endif

return 0;
}
12 changes: 2 additions & 10 deletions test/sources/libcxx/multimap/multimap.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main(int, char**)
}
#endif

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
momo::stdish::multimap m{ P{1,1L}, P{2,2L}, P{1,1L}, P{INT_MAX,1L}, P{3,1L} };

Expand Down Expand Up @@ -140,16 +140,14 @@ int main(int, char**)
assert(m.get_allocator().get_id() == 45);
}

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
// Examples from LWG3025
momo::stdish::multimap m{std::pair{1, 1}, {2, 2}, {3, 3}};
ASSERT_SAME_TYPE(decltype(m), momo::stdish::multimap<int, int>);

#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
momo::stdish::multimap m2{m.begin(), m.end()};
ASSERT_SAME_TYPE(decltype(m2), momo::stdish::multimap<int, int>);
#endif
}
#endif

Expand All @@ -158,13 +156,9 @@ int main(int, char**)
momo::stdish::multimap m1{{std::pair{1, 2}, {3, 4}}, std::less<int>()};
ASSERT_SAME_TYPE(decltype(m1), momo::stdish::multimap<int, int>);

#if !defined(TEST_GCC) && !defined(TEST_CLANG)
#if MOMO_VERSION_MAJOR > 3
using value_type = std::pair<const int, int>;
momo::stdish::multimap m2{{value_type{1, 2}, {3, 4}}, std::less<int>()};
ASSERT_SAME_TYPE(decltype(m2), momo::stdish::multimap<int, int>);
#endif
#endif
}

#if TEST_STD_VER >= 23
Expand Down Expand Up @@ -196,10 +190,8 @@ int main(int, char**)
}
#endif

#if MOMO_VERSION_MAJOR > 3
//AssociativeContainerDeductionGuidesSfinaeAway<std::multimap, std::multimap<int, long>>();
AssociativeContainerDeductionGuidesSfinaeAway<momo::stdish::multimap, momo::stdish::multimap<int, long>>();
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,23 @@ int main(int, char**)
}
#endif

#if !defined(TEST_GCC) && !defined(TEST_CLANG)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
momo::stdish::multimap m{ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} };

ASSERT_SAME_TYPE(decltype(m), momo::stdish::multimap<int, long>);
const PC expected_m[] = { {1,1L}, {1,1L}, {2,2L}, {3,1L}, {INT_MAX,1L} };
assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
}
#endif

#if MOMO_VERSION_MAJOR > 3
{
momo::stdish::multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, std::greater<int>());

ASSERT_SAME_TYPE(decltype(m), momo::stdish::multimap<int, long, std::greater<int>>);
const PC expected_m[] = { {INT_MAX,1L}, {3,1L}, {2,2L}, {1,1L}, {1,1L} };
assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
}
#endif

{
momo::stdish::multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, std::greater<int>(), test_allocator<PC>(0, 43));
Expand All @@ -93,7 +92,6 @@ int main(int, char**)
assert(m.get_allocator().get_id() == 43);
}

#if MOMO_VERSION_MAJOR > 3
{
momo::stdish::multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, test_allocator<PC>(0, 45));

Expand All @@ -102,8 +100,6 @@ int main(int, char**)
assert(std::equal(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
assert(m.get_allocator().get_id() == 45);
}
#endif
#endif

return 0;
}
8 changes: 3 additions & 5 deletions test/sources/libcxx/multiset/multiset.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int main(int, char **) {
}
#endif

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
momo::stdish::multiset s{ 1, 2, 1, INT_MAX, 3 };

Expand Down Expand Up @@ -159,7 +159,7 @@ int main(int, char **) {
assert(s.get_allocator().get_id() == 45);
}

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
NotAnAllocator a;
momo::stdish::multiset s{ a }; // multiset(initializer_list<NotAnAllocator>)
Expand Down Expand Up @@ -189,7 +189,7 @@ int main(int, char **) {
assert(s.size() == 3);
}

#if !defined(TEST_GCC)
#if !(defined(TEST_GCC) && __GNUC__ < 13)
{
int source[3] = { 3, 4, 5 };
momo::stdish::multiset s{ source, source + 3 }; // multiset(initializer_list<int*>)
Expand Down Expand Up @@ -227,10 +227,8 @@ int main(int, char **) {
}
#endif

#if MOMO_VERSION_MAJOR > 3
//AssociativeContainerDeductionGuidesSfinaeAway<std::multiset, std::multiset<int>>();
AssociativeContainerDeductionGuidesSfinaeAway<momo::stdish::multiset, momo::stdish::multiset<int>>();
#endif

return 0;
}
2 changes: 0 additions & 2 deletions test/sources/libcxx/set/set.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ int main(int, char **) {
}
#endif

#if MOMO_VERSION_MAJOR > 3
//AssociativeContainerDeductionGuidesSfinaeAway<std::set, std::set<int>>();
AssociativeContainerDeductionGuidesSfinaeAway<momo::stdish::set, momo::stdish::set<int>>();
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ constexpr void ContainerAdaptorDeductionGuidesSfinaeAway() {
// (container, alloc)
//
// Cannot deduce from (container, BAD_alloc)
static_assert(SFINAEs_away<Container, std::vector<T>, BadAlloc>);
static_assert(SFINAEs_away<Container, std::array<T, 1>, BadAlloc>);

// (iter, iter)
//
Expand Down
18 changes: 11 additions & 7 deletions test/sources/libcxx/support/from_range_associative_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <cassert>
#include <cstddef>
#include <ranges>
#include <vector>
#include <span>
#include <utility>

#include "exception_safety_helpers.h"
Expand Down Expand Up @@ -64,7 +64,7 @@ template <template <class ...> class Container,
class Comp,
class Alloc,
class ValueType = std::pair<const K, V>>
void test_associative_map_with_input(std::vector<ValueType>&& input) {
void test_associative_map_with_input(std::span<ValueType> input) {
{ // (range)
auto in = wrap_input<Iter, Sent>(input);
Container<K, V> c(std::from_range, in);
Expand Down Expand Up @@ -114,12 +114,14 @@ template <template <class ...> class Container,
class Comp,
class Alloc>
void test_associative_map() {
auto test_with_input = &test_associative_map_with_input<Container, K, V, Iter, Sent, Comp, Alloc>;
//auto test_with_input = &test_associative_map_with_input<Container, K, V, Iter, Sent, Comp, Alloc>;
auto test_with_input = [] <size_t N> (std::pair<const K, V> (&&input)[N], size_t count = N)
{ return test_associative_map_with_input<Container, K, V, Iter, Sent, Comp, Alloc>(std::span(input, count)); };

// Normal input.
test_with_input({{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}});
// Empty input.
test_with_input({});
test_with_input({{}}, 0);
// Single-element input.
test_with_input({{1, 2}});
}
Expand Down Expand Up @@ -206,7 +208,7 @@ template <template <class ...> class Container,
class Sent,
class Comp,
class Alloc>
void test_associative_set_with_input(std::vector<T>&& input) {
void test_associative_set_with_input(std::span<T> input) {
{ // (range)
std::ranges::subrange in(Iter(input.data()), Sent(Iter(input.data() + input.size())));
Container<T> c(std::from_range, in);
Expand Down Expand Up @@ -255,12 +257,14 @@ template <template <class ...> class Container,
class Comp,
class Alloc>
void test_associative_set() {
auto test_with_input = &test_associative_set_with_input<Container, T, Iter, Sent, Comp, Alloc>;
//auto test_with_input = &test_associative_set_with_input<Container, T, Iter, Sent, Comp, Alloc>;
auto test_with_input = [] <size_t N> (T (&&input)[N], size_t count = N)
{ return test_associative_set_with_input<Container, T, Iter, Sent, Comp, Alloc>(std::span(input, count)); };

// Normal input.
test_with_input({0, 5, 12, 7, -1, 8, 26});
// Empty input.
test_with_input({});
test_with_input({{}}, 0);
// Single-element input.
test_with_input({5});
}
Expand Down
16 changes: 4 additions & 12 deletions test/sources/libcxx/support/from_range_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <cstddef>
#include <iterator>
#include <type_traits>
#include <vector>

#include "min_allocator.h"
#include "test_allocator.h"
Expand All @@ -40,17 +39,10 @@ constexpr auto wrap_input(Range&& input) {
return std::ranges::subrange(std::move(b), std::move(e));
}

template <class Iter, class Sent, class T, std::size_t N>
constexpr auto wrap_input(std::array<T, N>& input) {
auto b = Iter(input.data());
auto e = Sent(Iter(input.data() + input.size()));
return std::ranges::subrange(std::move(b), std::move(e));
}

template <class Iter, class Sent, class T>
constexpr auto wrap_input(std::vector<T>& input) {
auto b = Iter(input.data());
auto e = Sent(Iter(input.data() + input.size()));
template <class Iter, class Sent, std::ranges::contiguous_range Range>
constexpr auto wrap_input(Range&& input) {
auto b = Iter(std::ranges::data(input));
auto e = Sent(Iter(std::ranges::data(input) + std::ranges::size(input)));
return std::ranges::subrange(std::move(b), std::move(e));
}

Expand Down
14 changes: 0 additions & 14 deletions test/sources/libcxx/support/from_range_sequence_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,6 @@ constexpr void test_sequence_container_move_only() {
[[maybe_unused]] Container<MoveOnly> c(std::from_range, in);
}

template <class Iter,
class Sent,
class Alloc,
class ValidateFunc>
constexpr void test_vector_bool(ValidateFunc validate) {
// Normal input.
test_sequence_container_with_input<std::vector, bool, Iter, Sent, Alloc>(
std::array{true, false, false, true, false, true, true, true, false, true}, validate);
// Empty input.
test_sequence_container_with_input<std::vector, bool, Iter, Sent, Alloc>(std::array<bool, 0>{}, validate);
// Single-element input.
test_sequence_container_with_input<std::vector, bool, Iter, Sent, Alloc>(std::array{true}, validate);
}

template <template <class ...> class Container>
void test_exception_safety_throwing_copy() {
#if !defined(TEST_HAS_NO_EXCEPTIONS)
Expand Down
Loading

0 comments on commit 968ac1c

Please sign in to comment.