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

doctest::skip() argument evaluation time. #795

Open
migunov97 opened this issue Aug 1, 2023 · 1 comment
Open

doctest::skip() argument evaluation time. #795

migunov97 opened this issue Aug 1, 2023 · 1 comment

Comments

@migunov97
Copy link

It's convenient to decide to skip some tests in run time. In (pseudo) code below test won't be skipped. doctest::skip() called after global variables initialization, but before main(). It seems, the most convenient moment to call skip is inside doctest::Context::applyCommandLine () or doctest::Context::run()

tests_main.cpp:
static bool needToSkip = false;

TEST_CASE("test name" * doctest::skip (needToSkip)) {...}

int main (int argc, char** argv)
{
needToSkip = true;
doctest::Context context;
context.applyCommandLine (argc, argv);
return context.run ();
}

@mitchgrout
Copy link

I don't believe that's going to work, since TEST_CASE will expand to a static variable declaration that uses your needToSkip variable. When the global ctor's are run, your test case will read the value of needToSkip at that point. Since those ctor's are run prior to the main method being entered, it would always observe needToSkip as false, so your test would never be disabled AFAIK.

I could see your need here being resolved by #822 instead, although it lifts the burden of disabling your tests to the command-line invocation.

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