FreeNOS
StdoutReporter.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <libgen.h>
22#include <ListIterator.h>
23#include <TerminalCodes.h>
24#include "TestCase.h"
25#include "StdoutReporter.h"
26
27StdoutReporter::StdoutReporter(int argc, char **argv)
28 : TestReporter(argc, argv)
29{
30}
31
33{
34 if (m_multiline)
35 printf("%s%s: running %d tests\r\n", WHITE, basename(m_argv[0]), tests.count());
36
37#ifdef __HOST__
38 fflush(stdout);
39#endif /* __HOST__ */
40}
41
43{
44 printf("%s%s: %s", WHITE, basename(m_argv[0]), *test.m_name);
45
46 if (m_multiline)
47 printf("\r\n");
48 else
49 printf(" .. ");
50
51#ifdef __HOST__
52 fflush(stdout);
53#endif /* __HOST__ */
54}
55
57{
58 if (m_multiline)
59 printf("%s%s: %s .. ", WHITE, basename(m_argv[0]), *test.m_name);
60
61 switch (result.getResult())
62 {
63 case TestResult::Success: printf("%sOK\r\n", GREEN); break;
64 case TestResult::Failure: printf("%sFAIL\r\n%s\r\n", RED, *result.getDescription()); break;
65 case TestResult::Skipped: printf("%sSKIP\r\n", YELLOW); break;
66 }
67 printf("%s", WHITE);
68
69 if (m_multiline)
70 printf("\r\n");
71
72#ifdef __HOST__
73 fflush(stdout);
74#endif /* __HOST__ */
75}
76
78{
79 if (m_fail)
80 printf("%s: %sFAIL%s ", basename(m_argv[0]), RED, WHITE);
81 else
82 printf("%s: %sOK%s ", basename(m_argv[0]), GREEN, WHITE);
83
84 printf("(%d passed %d failed %d skipped %d total)\r\n",
86
87#ifdef __HOST__
88 fflush(stdout);
89#endif /* __HOST__ */
90}
Simple linked list template class.
Definition List.h:37
Size count() const
Get the number of items on the list.
Definition List.h:402
virtual void reportBegin(List< TestInstance * > &tests)
Report start of testing.
virtual void reportBefore(TestInstance &test)
Report start of a test.
virtual void reportFinish(List< TestInstance * > &tests)
Report completion of all tests.
virtual void reportAfter(TestInstance &test, TestResult &result)
Report finish of a test.
StdoutReporter(int argc, char **argv)
Constructor.
Represents a test instance.
String m_name
Name of the test instance.
Responsible for outputting test results.
uint m_ok
Test statistics.
char ** m_argv
Argument values.
bool m_multiline
Multi line output.
Represents a Test result created by a TestInstance.
Definition TestResult.h:48
String & getDescription()
Get result description.
const Result getResult() const
Get result code.
C char * basename(char *path)
Return the last component of a pathname.
Definition basename.cpp:21
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22
#define WHITE
#define RED
#define YELLOW
#define GREEN