Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking non-awaitable coroutines #339

Open
chghehe opened this issue Aug 14, 2024 · 1 comment
Open

Mocking non-awaitable coroutines #339

chghehe opened this issue Aug 14, 2024 · 1 comment

Comments

@chghehe
Copy link

chghehe commented Aug 14, 2024

Using Conan package trompeloeil/48 and gcc-14.

The code below

#include <catch2/catch_all.hpp>
#include <catch2/trompeloeil.hpp>

#include <generator>

class Mock
{
public:
  MAKE_MOCK0(fibonacci,std::generator<int>());
};

TEST_CASE("fibonacci 7")
{
  Mock m;
  ALLOW_CALL(m, fibonacci())
    .CO_YIELD(0)
    .CO_YIELD(1)
    .CO_YIELD(1)
    .CO_YIELD(2)
    .CO_YIELD(3)
    .CO_YIELD(5)
    .CO_YIELD(8)
    .CO_RETURN()
    ;

  REQUIRE_THAT(m.fibonacci(), Catch::Matchers::RangeEquals(std::array{0, 1, 1, 2, 3, 5, 8}));
}

produces compile time error:

trompeloeil/coro.hpp:54:56: error: ‘class std::generator’ has no member named ‘await_resume’

Seems that non-awaitable coroutines are not supported (yet).

More than that, I cannot directly mock these functions (like Mock::fibonacci()) with RETURN() statement due to static assertions.

Since at this moment std::generator<> is implemented in gcc-14 only, the following implementations might be used for reproduction purposes:

@rollbear
Copy link
Owner

Thank you. I will have a look and see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants