37 #include "gtest/gtest.h" 39 using ::testing::EmptyTestEventListener;
41 using ::testing::Test;
43 using ::testing::TestEventListeners;
44 using ::testing::TestInfo;
45 using ::testing::TestPartResult;
46 using ::testing::UnitTest;
52 class TersePrinter :
public EmptyTestEventListener {
55 virtual void OnTestProgramStart(
const UnitTest& ) {}
58 virtual void OnTestProgramEnd(
const UnitTest& unit_test) {
59 fprintf(stdout,
"TEST %s\n", unit_test.Passed() ?
"PASSED" :
"FAILED");
64 virtual void OnTestStart(
const TestInfo& test_info) {
66 "*** Test %s.%s starting.\n",
67 test_info.test_case_name(),
73 virtual void OnTestPartResult(
const TestPartResult& test_part_result) {
76 test_part_result.failed() ?
"*** Failure" :
"Success",
77 test_part_result.file_name(),
78 test_part_result.line_number(),
79 test_part_result.summary());
84 virtual void OnTestEnd(
const TestInfo& test_info) {
86 "*** Test %s.%s ending.\n",
87 test_info.test_case_name(),
93 TEST(CustomOutputTest, PrintsMessage) {
94 printf(
"Printing something from the test body...\n");
97 TEST(CustomOutputTest, Succeeds) {
98 SUCCEED() <<
"SUCCEED() has been invoked from here";
101 TEST(CustomOutputTest, Fails) {
103 <<
"This test fails in order to demonstrate alternative failure messages";
108 int main(
int argc,
char **argv) {
111 bool terse_output =
false;
112 if (argc > 1 && strcmp(argv[1],
"--terse_output") == 0 )
115 printf(
"%s\n",
"Run this program with --terse_output to change the way " 116 "it prints its output.");
118 UnitTest& unit_test = *UnitTest::GetInstance();
123 TestEventListeners& listeners = unit_test.listeners();
129 delete listeners.Release(listeners.default_result_printer());
135 listeners.Append(
new TersePrinter);
141 int unexpectedly_failed_tests = 0;
142 for (
int i = 0; i < unit_test.total_test_case_count(); ++i) {
143 const TestCase& test_case = *unit_test.GetTestCase(i);
144 for (
int j = 0; j < test_case.total_test_count(); ++j) {
145 const TestInfo& test_info = *test_case.GetTestInfo(j);
148 if (test_info.result()->Failed() &&
149 strcmp(test_info.name(),
"Fails") != 0) {
150 unexpectedly_failed_tests++;
156 if (unexpectedly_failed_tests == 0)
int main(int argc, char **argv)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define TEST(test_case_name, test_name)
void InitGoogleTest(int *argc, char **argv)
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
#define EXPECT_EQ(expected, actual)
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)