1 // Copyright 2019 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
18 #include <string_view>
20 #include "pw_preprocessor/compiler.h"
21 #include "pw_unit_test/event_handler.h"
23 namespace pw::unit_test {
25 // An event handler implementation which produces human-readable test output.
29 // >>> Running MyTestSuite.TestCase1
30 // [SUCCESS] 128 <= 129
31 // [FAILURE] 'a' == 'b'
32 // at ../path/to/my/file_test.cc:4831
33 // <<< Test MyTestSuite.TestCase1 failed
35 class SimplePrintingEventHandler : public EventHandler {
37 // Function for writing output as a string.
38 using WriteFunction = void (*)(const std::string_view& string,
41 // Instantiates an event handler with a function to which to output results.
42 // If verbose is set, information for successful tests is written as well as
44 SimplePrintingEventHandler(WriteFunction write_function, bool verbose = false)
45 : write_(write_function), verbose_(verbose) {}
47 void RunAllTestsStart() override;
48 void RunAllTestsEnd(const RunTestsSummary& run_tests_summary) override;
49 void TestCaseStart(const TestCase& test_case) override;
50 void TestCaseEnd(const TestCase& test_case, TestResult result) override;
51 void TestCaseExpect(const TestCase& test_case,
52 const TestExpectation& expectation) override;
53 void TestCaseDisabled(const TestCase& test_case) override;
56 void WriteLine(const char* format, ...) PW_PRINTF_FORMAT(2, 3);
63 } // namespace pw::unit_test