#include <gtest/gtest.h>
#include <iostream>
void f()
{
std::cout<<"Some text" <<std::endl;
std::cerr<<"Some error" <<std::endl;
abort();
}
TEST(A, B)
{
::testing::internal::CaptureStdout();
ASSERT_DEATH(f(), "");
std::string capturedStdout = ::testing::internal::GetCapturedStdout().c_str();
EXPECT_STREQ("Some text", capturedStdout.c_str());
}
int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from A
[ RUN ] A.B
src/test_temp.cpp:16: Failure
Value of: capturedStdout.c_str()
Actual: ""
Expected: "Some text"
[ FAILED ] A.B (27 ms)
[----------] 1 test from A (27 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (28 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] A.B
1 FAILED TEST
--
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
EXPECT_STR. Why it happens?_Sam
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframework+unsub...@googlegroups.com.
Hi.
Thanks for answer. I know about second parameter to ASSERT_DEATH. But look at this example. It should fail on ASSERT_DEATH not on
EXPECT_STR. Why it happens?
http://stackoverflow.com/questions/3803465/how-to-capture-stdout-stderr-with-googletest - first solution from second post with buffer redirection is better?
In google test public api exist some function to test stdout and stderr?
_Sam
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.