tesseract v5.3.3.20231005
gtest_throw_on_failure_ex_test.cc File Reference
#include "gtest/gtest.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdexcept>

Go to the source code of this file.

Functions

void Fail (const char *msg)
 
void TestFailureThrowsRuntimeError ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ Fail()

void Fail ( const char *  msg)

Definition at line 44 of file gtest_throw_on_failure_ex_test.cc.

44 {
45 printf("FAILURE: %s\n", msg);
46 fflush(stdout);
47 exit(1);
48}

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 79 of file gtest_throw_on_failure_ex_test.cc.

79 {
80 testing::InitGoogleTest(&argc, argv);
81
82 // We want to ensure that people can use Google Test assertions in
83 // other testing frameworks, as long as they initialize Google Test
84 // properly and set the thrown-on-failure mode. Therefore, we don't
85 // use Google Test's constructs for defining and running tests
86 // (e.g. TEST and RUN_ALL_TESTS) here.
87
89 return 0;
90}
void TestFailureThrowsRuntimeError()
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6660

◆ TestFailureThrowsRuntimeError()

void TestFailureThrowsRuntimeError ( )

Definition at line 52 of file gtest_throw_on_failure_ex_test.cc.

52 {
53 testing::GTEST_FLAG(throw_on_failure) = true;
54
55 // A successful assertion shouldn't throw.
56 try {
57 EXPECT_EQ(3, 3);
58 } catch(...) {
59 Fail("A successful assertion wrongfully threw.");
60 }
61
62 // A failed assertion should throw a subclass of std::runtime_error.
63 try {
64 EXPECT_EQ(2, 3) << "Expected failure";
65 } catch(const std::runtime_error& e) {
66 if (strstr(e.what(), "Expected failure") != nullptr) return;
67
68 printf("%s",
69 "A failed assertion did throw an exception of the right type, "
70 "but the message is incorrect. Instead of containing \"Expected "
71 "failure\", it is:\n");
72 Fail(e.what());
73 } catch(...) {
74 Fail("A failed assertion threw the wrong type of exception.");
75 }
76 Fail("A failed assertion should've thrown but didn't.");
77}
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043
#define GTEST_FLAG(name)
Definition: gtest-port.h:2205
void Fail(const char *msg)