Skip to content

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

@chghehe

Description

@chghehe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions