Fixes comments and tests for the moment of generator parameter evaluation in INSTANTIATE_TEST_CASE_P.
This commit is contained in:
parent
06d04c0945
commit
90030d74c8
@ -133,9 +133,12 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
|||||||
// in the given test case, whether their definitions come before or
|
// in the given test case, whether their definitions come before or
|
||||||
// AFTER the INSTANTIATE_TEST_CASE_P statement.
|
// AFTER the INSTANTIATE_TEST_CASE_P statement.
|
||||||
//
|
//
|
||||||
// Please also note that generator expressions are evaluated in
|
// Please also note that generator expressions (including parameters to the
|
||||||
// RUN_ALL_TESTS(), after main() has started. This allows evaluation of
|
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
||||||
// parameter list based on command line parameters.
|
// This allows the user on one hand, to adjust generator parameters in order
|
||||||
|
// to dynamically determine a set of tests to run and on the other hand,
|
||||||
|
// give the user a chance to inspect the generated tests with Google Test
|
||||||
|
// reflection API before RUN_ALL_TESTS() is executed.
|
||||||
//
|
//
|
||||||
// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
|
// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
|
||||||
// for more examples.
|
// for more examples.
|
||||||
|
@ -692,13 +692,15 @@ INSTANTIATE_TEST_CASE_P(TestExpansionModule, TestGenerationTest,
|
|||||||
ValuesIn(test_generation_params));
|
ValuesIn(test_generation_params));
|
||||||
|
|
||||||
// This test verifies that the element sequence (third parameter of
|
// This test verifies that the element sequence (third parameter of
|
||||||
// INSTANTIATE_TEST_CASE_P) is evaluated in RUN_ALL_TESTS and not at the call
|
// INSTANTIATE_TEST_CASE_P) is evaluated in InitGoogleTest() and neither at
|
||||||
// site of INSTANTIATE_TEST_CASE_P.
|
// the call site of INSTANTIATE_TEST_CASE_P nor in RUN_ALL_TESTS(). For
|
||||||
// For that, we declare param_value_ to be a static member of
|
// that, we declare param_value_ to be a static member of
|
||||||
// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in main(),
|
// GeneratorEvaluationTest and initialize it to 0. We set it to 1 in
|
||||||
// just before invocation of RUN_ALL_TESTS. If the sequence is evaluated
|
// main(), just before invocation of InitGoogleTest(). After calling
|
||||||
// before that moment, INSTANTIATE_TEST_CASE_P will create a test with
|
// InitGoogleTest(), we set the value to 2. If the sequence is evaluated
|
||||||
// parameter 0, and the test body will fail the assertion.
|
// before or after InitGoogleTest, INSTANTIATE_TEST_CASE_P will create a
|
||||||
|
// test with parameter other than 1, and the test body will fail the
|
||||||
|
// assertion.
|
||||||
class GeneratorEvaluationTest : public TestWithParam<int> {
|
class GeneratorEvaluationTest : public TestWithParam<int> {
|
||||||
public:
|
public:
|
||||||
static int param_value() { return param_value_; }
|
static int param_value() { return param_value_; }
|
||||||
@ -815,10 +817,19 @@ int main(int argc, char **argv) {
|
|||||||
#if GTEST_HAS_PARAM_TEST
|
#if GTEST_HAS_PARAM_TEST
|
||||||
// Used in TestGenerationTest test case.
|
// Used in TestGenerationTest test case.
|
||||||
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
|
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
|
||||||
// Used in GeneratorEvaluationTest test case.
|
// Used in GeneratorEvaluationTest test case. Tests that the updated value
|
||||||
|
// will be picked up for instantiating tests in GeneratorEvaluationTest.
|
||||||
GeneratorEvaluationTest::set_param_value(1);
|
GeneratorEvaluationTest::set_param_value(1);
|
||||||
#endif // GTEST_HAS_PARAM_TEST
|
#endif // GTEST_HAS_PARAM_TEST
|
||||||
|
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
|
#if GTEST_HAS_PARAM_TEST
|
||||||
|
// Used in GeneratorEvaluationTest test case. Tests that value updated
|
||||||
|
// here will NOT be used for instantiating tests in
|
||||||
|
// GeneratorEvaluationTest.
|
||||||
|
GeneratorEvaluationTest::set_param_value(2);
|
||||||
|
#endif // GTEST_HAS_PARAM_TEST
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user