emil-e / rapidcheck

QuickCheck clone for C++ with the goal of being simple to use with as little boilerplate as possible.
BSD 2-Clause "Simplified" License
1.01k stars 172 forks source link

RC_PARAMS and GoogleTest #297

Open kalaracey opened 2 years ago

kalaracey commented 2 years ago

Hey, thanks for the great library. I was wondering if it's possible to set RC_PARAMS with the GoogleTest integration from within the test. I tried setting the environment variable in my test suite constructor to no avail:

#include <gtest/gtest.h>
#include <cstdlib>
#include <rapidcheck/gtest.h>
#include <vector>

class TestSuite : public ::testing::Test {
  protected:
    TestSuite() {
      putenv("RC_PARAMS=max_success=100000");
    }
};

// ...

RC_GTEST_FIXTURE_PROP(TestSuite, RapidCheck, (std::vector<int> arg)) {
  // ...
  RC_ASSERT(/* ... */);
}

The only output from RapidCheck I see is like

Using configuration: seed=13725330511029654191

FWIW, using putenv from main did work, as in

#include <rapidcheck.h>
#include <vector>
#include <cstdlib>

int main() {
  putenv("RC_PARAMS=max_success=100000");
  rc::check("my property", [](std::vector<int>) { /* ... */ });
  return 0;
}

With that, I see

Using configuration: max_success=100000 seed=3088896386735555752

- my property
OK, passed 100000 tests

Thanks.

kalaracey commented 2 years ago

Updated original post to use RC_GTEST_FIXTURE_PROP rather than RC_GTEST_PROP.