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

RC_PARAMS and GoogleTest #297

Open
kalaracey opened this issue Jul 24, 2022 · 2 comments
Open

RC_PARAMS and GoogleTest #297

kalaracey opened this issue Jul 24, 2022 · 2 comments

Comments

@kalaracey
Copy link

kalaracey commented Jul 24, 2022

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
Copy link
Author

kalaracey commented Jul 29, 2022

Updated original post to use RC_GTEST_FIXTURE_PROP rather than RC_GTEST_PROP.

@erasmussen1
Copy link

Thanks the great library. I use it with address sanitizer "-fsanitize=address", is works great.

Yes, it would be great to have a macro like below to put in the testfixture (in Setup(), and TearDown() ).

Note: this means you have to remove "const" from rc::detail::configuration()

#define RC_FORCE_MAX_SUCCESS(n)   {   \
        if (int{(n)} > 0) {                                        \
            rc::detail::configuration().testParams.maxSuccess = n; \
        }                                                          \
    }

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