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

Have WithSeeds accept the GoogleTest ParameterGenerators (such as ValuesIn, Combine, etc). #46

Open
markww opened this issue Oct 3, 2022 · 2 comments

Comments

@markww
Copy link

markww commented Oct 3, 2022

I'm currently in the process of pitching my team on using FUZZ_TEST instead of regular old GoogleTest TEST_P. Most of our tests currently use TEST_P, and my goal is to incrementally convert them from TEST_P to FUZZ_TEST keeping the behavior the same other than fuzzing. This means keeping the deterministically-executed values the same, which I plan to do with WithSeeds.

Unfortunately, WithSeeds is less flexible than the GoogleTest parameter generators in a number of important ways:

  1. In the case where a TestWithParam is parameterized on a single parameter, TestWithParam does not insist that that single parameter is wrapped in a std::tuple, but WithSeeds does.

  2. GoogleTest provides Combine, which allows taking lists of parameter generators and performing the cartesian product of them, producing all possible combinations of the parameter generator's outputs. To replicate this, it looks like I'll either have to manually generate each possible combination or whittle down the inputs and argue to my team that it's ok.

Ideally, I'd like to do neither of these things. I'd like to just continue passing the same parameter generators I sent into INSTANTIATE_TEST_SUITE_WITH_PARAMS into WithSeeds and have it figure it out. Doing so would make convincing others that I am not introducing regressions much simpler.

@lszekeres
Copy link
Member

lszekeres commented Oct 3, 2022

Thanks! Yes, we plan to support this by allowing seeds to be assigned to domains too, not just to a FUZZ_TEST.

So, instead of this:

FUZZ_TEST(...)
  .WithSeeds({{"hi", 123}, {"hi", 456}, {"hello", 123}, {"hello", 456}});

You will be able to do:

FUZZ_TEST(...)
  .WithDomains(
    Arbitrary<string>.WithSeeds({"hi", "hello"}),
    Arbitrary<int>.WithSeeds({123, 456}));

Until that, one option to consider is to keep your existing TEST_P, add your FUZZ_TEST, but factor out the body of the test to a function, so that it's shared by the TEST_P and the FUZZ_TEST.

@markww
Copy link
Author

markww commented Oct 3, 2022

Thanks for the update, that sounds like it would work pretty well for my use case.

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