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 
27 StdoutReporter::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",
85  m_ok, m_fail, m_skip, (m_ok + m_fail + m_skip));
86 
87 #ifdef __HOST__
88  fflush(stdout);
89 #endif /* __HOST__ */
90 }
GREEN
@ GREEN
Definition: VGA.h:68
StdoutReporter.h
string.h
TerminalCodes.h
StdoutReporter::reportBefore
virtual void reportBefore(TestInstance &test)
Report start of a test.
Definition: StdoutReporter.cpp:42
libgen.h
StdoutReporter::reportFinish
virtual void reportFinish(List< TestInstance * > &tests)
Report completion of all tests.
Definition: StdoutReporter.cpp:77
TestReporter::m_skip
uint m_skip
Definition: TestReporter.h:139
List::count
Size count() const
Get the number of items on the list.
Definition: List.h:402
TestResult::Success
@ Success
Definition: TestResult.h:56
TestReporter::m_multiline
bool m_multiline
Multi line output.
Definition: TestReporter.h:136
StdoutReporter::reportAfter
virtual void reportAfter(TestInstance &test, TestResult &result)
Report finish of a test.
Definition: StdoutReporter.cpp:56
TestReporter::m_fail
uint m_fail
Definition: TestReporter.h:139
TestResult::Failure
@ Failure
Definition: TestResult.h:57
TestReporter::m_argv
char ** m_argv
Argument values.
Definition: TestReporter.h:127
basename
char * basename(char *path)
Return the last component of a pathname.
Definition: basename.cpp:21
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
WHITE
@ WHITE
Definition: VGA.h:81
TestReporter::m_ok
uint m_ok
Test statistics.
Definition: TestReporter.h:139
stdio.h
TestResult::getDescription
String & getDescription()
Get result description.
Definition: TestResult.cpp:45
TestResult
Represents a Test result created by a TestInstance.
Definition: TestResult.h:47
StdoutReporter::reportBegin
virtual void reportBegin(List< TestInstance * > &tests)
Report start of testing.
Definition: StdoutReporter.cpp:32
ListIterator.h
TestReporter
Responsible for outputting test results.
Definition: TestReporter.h:35
TestInstance::m_name
String m_name
Name of the test instance.
Definition: TestInstance.h:68
RED
@ RED
Definition: VGA.h:70
List< TestInstance * >
stdlib.h
YELLOW
#define YELLOW
Definition: TerminalCodes.h:41
StdoutReporter::StdoutReporter
StdoutReporter(int argc, char **argv)
Constructor.
Definition: StdoutReporter.cpp:27
TestResult::Skipped
@ Skipped
Definition: TestResult.h:58
TestCase.h
TestResult::getResult
const Result getResult() const
Get result code.
Definition: TestResult.cpp:40
TestInstance
Represents a test instance.
Definition: TestInstance.h:35