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

Add support for generators #59

Open
cschreib opened this issue Jan 19, 2023 · 1 comment
Open

Add support for generators #59

cschreib opened this issue Jan 19, 2023 · 1 comment
Labels
enhancement New feature or request maybe For issues that aren't critial, or need more exploration

Comments

@cschreib
Copy link
Member

cschreib commented Jan 19, 2023

Generators is a feature from Catch2. It is somewhat similar to a SECTION() that generates a different value each time it is entered. This has been requested on reddit.

This is currently not on the roadmap, mostly because:

  • I didn't know if people used them, and
  • they seem like they would be complex to implement.

Now I have some data that people do use them, so there's extra motivation to implement it. Still need to weigh the pros and cons. The API would likely be different from Catch2 however, likely using concepts rather than a virtual interface.

@cschreib cschreib added this to the v1.x milestone Jan 19, 2023
@cschreib cschreib added the enhancement New feature or request label Jan 19, 2023
@cschreib cschreib modified the milestones: v1.1, v1.x Mar 28, 2023
@cschreib cschreib added maybe For issues that aren't critial, or need more exploration and removed enhancement New feature or request labels May 28, 2023
@cschreib cschreib removed this from the v1.x milestone May 28, 2023
@vid512
Copy link

vid512 commented Jul 6, 2023

I have used simple generators (FixedValuesGenerator?) to a limited degree in some of my code, like this:

int param1 = GENERATE(0, 1, 50, 99, 100);
int param2 = GENERATE(0x10, 0x100, 0x1000);
bool param3 = GENERATE(true, false);
auto x = func(param1, param2, param3);
CHECK( ... );
if (param1 > 0) {
  CHECK( ... );
}
if (param3) {
  CHECK( ... )
}

If I understand things correctly, the same thing can currently be implemented in Snitch like this:

for (int param1 : std::vector<int>{0, 1, 50, 99, 100}) {
  CAPTURE(param1);
  for (int param2 : std::vector<int>{0x10, 0x100, 0x1000}) {
    CAPTURE(param2);
    for (bool param3 : std::vector<bool>{true, false}) {
      CAPTURE(param3);
      ... do the tests ...
    }
  }
}

(I have not tested this)

Surely the code with GENERATE looks much nicer, but that is syntactic sugar only. Question is: are the any more complicated usage scenarios of GENERATE, which can't be modeled like this?

If all generators can be fully replaced with similar code, then I would support adding them only if they can be added without any significant bloat. But, if generators can be implemented as a special case of SECTIONs with few extra parameters, then go for it.

@cschreib cschreib added the enhancement New feature or request label Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maybe For issues that aren't critial, or need more exploration
Projects
None yet
Development

No branches or pull requests

2 participants