Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

Range matchers do not stringify a range produced by std::generator<>

Open chghehe opened this issue 6 months ago • 0 comments

Range matchers do not stringify ranges produced by synchronous co_yield generator.

#include <catch2/catch_all.hpp>
#include <generator>
#include <ranges>

TEST_CASE("fibonacci")
{
  auto fibonacci = []<typename T = int>() -> std::generator<int>
    {
      T j = 0;
      T i = 1;
      co_yield j;
      for(;;) {
        co_yield i;
        T tmp = i;
        i += j;
        j = tmp;
      }
    };

  CHECK_THAT(fibonacci() | std::views::take(7), Catch::Matchers::RangeEquals(std::array{0, 1, 1, 2, 3, 5, 9}));
}

Expected behavior

FAILED:
  CHECK_THAT( fibonacci() | std::views::take(7), Catch::Matchers::RangeEquals(std::array{0, 1, 1, 2, 3, 5, 9}) )
with expansion:
  { 0, 1, 1, 2, 3, 5, 8 } elements are { 0, 1, 1, 2, 3, 5, 9 }

Actual behaviour

FAILED:
  CHECK_THAT( fibonacci() | std::views::take(7), Catch::Matchers::RangeEquals(std::array{0, 1, 1, 2, 3, 5, 9}) )
with expansion:
  {?} elements are { 0, 1, 1, 2, 3, 5, 9 }

Platform information:

  • OS: Ubuntu 24.04
  • Compiler: gcc-14
  • Catch version: 3.6.0

Probably, related to #2646

chghehe avatar Aug 15 '24 10:08 chghehe