Pigweed
 
Loading...
Searching...
No Matches
pw::unit_test::SimplePrintingEventHandler Class Reference

#include <simple_printing_event_handler.h>

Inheritance diagram for pw::unit_test::SimplePrintingEventHandler:
pw::unit_test::GoogleTestStyleEventHandler pw::unit_test::EventHandler

Public Types

using WriteFunction = void(*)(std::string_view string, bool append_newline)
 

Public Member Functions

constexpr SimplePrintingEventHandler (WriteFunction write_function, bool verbose=false)
 
- Public Member Functions inherited from pw::unit_test::GoogleTestStyleEventHandler
void TestProgramStart (const ProgramSummary &program_summary) override
 Called before any test activity starts.
 
void EnvironmentsSetUpEnd () override
 Called after environment setup for each iteration of tests ends.
 
void TestSuiteStart (const TestSuite &test_suite) override
 Called before the test suite starts.
 
void TestSuiteEnd (const TestSuite &test_suite) override
 Called after the test suite ends.
 
void EnvironmentsTearDownEnd () override
 Called after environment teardown for each iteration of tests ends.
 
void TestProgramEnd (const ProgramSummary &program_summary) override
 Called after all test activities have ended.
 
void RunAllTestsStart () override
 Called before all tests are run.
 
void RunAllTestsEnd (const RunTestsSummary &run_tests_summary) override
 Called after all tests are run.
 
void TestCaseStart (const TestCase &test_case) override
 Called when a new test case is started.
 
void TestCaseEnd (const TestCase &test_case, TestResult result) override
 
void TestCaseExpect (const TestCase &test_case, const TestExpectation &expectation) override
 
void TestCaseDisabled (const TestCase &test_case) override
 Called when a disabled test case is encountered.
 
virtual void TestProgramStart (const ProgramSummary &program_summary)=0
 Called before any test activity starts.
 
virtual void EnvironmentsSetUpEnd ()=0
 Called after environment setup for each iteration of tests ends.
 
virtual void TestSuiteStart (const TestSuite &test_suite)=0
 Called before the test suite starts.
 
virtual void TestSuiteEnd (const TestSuite &test_suite)=0
 Called after the test suite ends.
 
virtual void EnvironmentsTearDownEnd ()=0
 Called after environment teardown for each iteration of tests ends.
 
virtual void TestProgramEnd (const ProgramSummary &program_summary)=0
 Called after all test activities have ended.
 
virtual void RunAllTestsStart ()=0
 Called before all tests are run.
 
virtual void RunAllTestsEnd (const RunTestsSummary &run_tests_summary)=0
 Called after all tests are run.
 
virtual void TestCaseStart (const TestCase &test_case)=0
 Called when a new test case is started.
 
virtual void TestCaseEnd (const TestCase &test_case, TestResult result)=0
 
virtual void TestCaseDisabled (const TestCase &)
 Called when a disabled test case is encountered.
 
virtual void TestCaseExpect (const TestCase &test_case, const TestExpectation &expectation)=0
 

Additional Inherited Members

- Protected Member Functions inherited from pw::unit_test::GoogleTestStyleEventHandler
constexpr GoogleTestStyleEventHandler (bool verbose)
 
bool verbose () const
 
virtual void Write (const char *content)=0
 
virtual void WriteLine (const char *format,...)=0
 

Detailed Description

Predefined event handler implementation that produces human-readable GoogleTest-style test output and sends it to a sink that you define. See pw::unit_test::EventHandler for explanations of emitted events.

Example:

#include "pw_unit_test/framework.h"
// pw_unit_test:light requires an event handler to be configured.
#include "pw_unit_test/simple_printing_event_handler.h"
void WriteString(std::string_view string, bool newline) {
printf("%s", string.data());
if (newline) {
printf("\n");
}
}
int main() {
// The following line has no effect with pw_unit_test_light, but makes
// this test compatible with upstream GoogleTest.
testing::InitGoogleTest();
// Since we are using pw_unit_test:light, set up an event handler.
pw::unit_test::RegisterEventHandler(&handler);
return RUN_ALL_TESTS();
}
Definition: simple_printing_event_handler.h:64

Example output:

>>> Running MyTestSuite.TestCase1
[SUCCESS] 128 <= 129
[FAILURE] 'a' == 'b'
at ../path/to/my/file_test.cc:4831
<<< Test MyTestSuite.TestCase1 failed

Member Function Documentation

◆ Write()

void pw::unit_test::SimplePrintingEventHandler::Write ( const char *  content)
inlineoverrideprivatevirtual

◆ WriteLine()

void pw::unit_test::SimplePrintingEventHandler::WriteLine ( const char *  format,
  ... 
)
overrideprivatevirtual

The documentation for this class was generated from the following file: