FreeNOS
TAPReporter.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 "TAPReporter.h"
22 
23 TAPReporter::TAPReporter(int argc, char **argv)
24  : TestReporter(argc, argv)
25 {
26  m_count = 1;
27 }
28 
30 {
31  if (!m_multiline)
32  printf("1..%d # Start %s\r\n", tests.count(), m_argv[0]);
33 
34 #ifdef __HOST__
35  fflush(stdout);
36 #endif /* __HOST__ */
37 }
38 
40 {
41 }
42 
44 {
45  if (!m_multiline)
46  {
47  switch (result.getResult())
48  {
49  case TestResult::Success: printf("ok %d %s\r\n", m_count, *test.getName()); break;
50  case TestResult::Failure: printf("not ok %d %s %s\r\n", m_count, *test.getName(), *result.getDescription()); break;
51  case TestResult::Skipped: printf("ok %d %s # SKIP\r\n", m_count, *test.getName()); break;
52  }
53  m_count++;
54  }
55  else
56  {
57  switch (result.getResult())
58  {
59  case TestResult::Success: printf("# Finish %s OK\r\n", *test.getName()); break;
60  case TestResult::Failure: printf("# Finish %s FAIL\r\n", *test.getName()); break;
61  case TestResult::Skipped: printf("# Finish %s SKIP\r\n", *test.getName()); break;
62  }
63  }
64 
65 #ifdef __HOST__
66  fflush(stdout);
67 #endif /* __HOST__ */
68 }
69 
71 {
72  if (m_multiline)
73  {
74  printf("# Completed ");
75 
76  if (m_fail)
77  printf("FAIL ");
78  else
79  printf("OK ");
80 
81  printf("(%d passed %d failed %d skipped %d total)\r\n",
82  m_ok, m_fail, m_skip, (m_ok + m_fail + m_skip));
83 
84 #ifdef __HOST__
85  fflush(stdout);
86 #endif /* __HOST__ */
87  }
88 }
TAPReporter::TAPReporter
TAPReporter(int argc, char **argv)
Constructor.
Definition: TAPReporter.cpp:23
TAPReporter::m_count
uint m_count
Test counter.
Definition: TAPReporter.h:68
TAPReporter::reportBegin
virtual void reportBegin(List< TestInstance * > &tests)
Report start of testing.
Definition: TAPReporter.cpp:29
string.h
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
TAPReporter::reportAfter
virtual void reportAfter(TestInstance &test, TestResult &result)
Report finish of a test.
Definition: TAPReporter.cpp:43
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
TAPReporter.h
TAPReporter::reportBefore
virtual void reportBefore(TestInstance &test)
Report start of a test.
Definition: TAPReporter.cpp:39
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
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
TestInstance::getName
const String & getName() const
Retrieve test instance name.
Definition: TestInstance.cpp:31
TAPReporter::reportFinish
virtual void reportFinish(List< TestInstance * > &tests)
Report completion of all tests.
Definition: TAPReporter.cpp:70
TestReporter
Responsible for outputting test results.
Definition: TestReporter.h:35
List< TestInstance * >
stdlib.h
TestResult::Skipped
@ Skipped
Definition: TestResult.h:58
TestResult::getResult
const Result getResult() const
Get result code.
Definition: TestResult.cpp:40
TestInstance
Represents a test instance.
Definition: TestInstance.h:35