Domanda

Is it possible to use more than one EXPECT_EXIT macros in a single test on the Windows platform? The problem occurs because on the Windows platform death tests work in a "threadsafe" mode, so the process spawned by EXPECT_EXIT macros will run all the test from the beginning. Consider sample code:

TEST_F(MyFixtureDeathTest, Test1)
{
    EXPECT_EXIT(f(), ::testing::ExitedWithCode(1), "message1");

//....
// actions after the exit (for instanse, emulation of the application correct restart)
//....

    EXPECT_EXIT(g(), ::testing::ExitedWithCode(1), "message2");
}

So when the test gets to the second EXPECT_EXIT macros it will make the code to run from the test beginning, so it will invoke the f() function, make exit there and actually never get to the body of g() function. Maybe, I shouldn't use the GoogleTest for this task at all, should I?

Any help is appreciated. Thanks.

UPD. (clarification) Actually, I'm quite sure now that in the described code snippet even the function f() won't be invoked from the process spawned by the the second EXPECT_EXIT macro.

UPD. The problem now seems a bit different to me. As VladLosev said, the first macro will be totally ignored in the child process spawned by the second macro. But in case of any asserts in the between of two macro based on the some results of f() function the child process will hit assert and exit there, so it won't be able to get to g().

È stato utile?

Soluzione

No, this code will work as expected. A death test child process knows which death test macro it was invoked from and will only execute tested statement specified in that macro. E.g., in your code, the child proces invoked in the second EXPECT_EXIT macro will only execute g() and skip f().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top