FreeNOS
TestRunner.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 <string.h>
19#include <ListIterator.h>
20#include "TestCase.h"
21#include "TestSuite.h"
22#include "TestRunner.h"
23#include "StdoutReporter.h"
24#include "TAPReporter.h"
25#include "XMLReporter.h"
26
27TestRunner::TestRunner(int argc, char **argv)
28{
29 // Set member default values.
30 m_argc = argc;
31 m_argv = argv;
32 m_reporter = new StdoutReporter(argc, argv);
33
34 // Check for command-line specified arguments.
35 for (int i = 0; i < argc; i++)
36 {
37 if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--tap") == 0)
38 {
39 if (m_reporter)
40 delete m_reporter;
41
42 m_reporter = new TAPReporter(argc, argv);
43 break;
44 }
45 else if (strcmp(argv[i], "-x") == 0 || strcmp(argv[i], "--xml") == 0)
46 {
47 if (m_reporter)
48 delete m_reporter;
49
50 m_reporter = new XMLReporter(argc, argv);
51 break;
52 }
53 else if (strcmp(argv[i], "-n") == 0)
54 {
56 }
57 }
58}
59
64
69
71{
72 // Prepare for testing.
74 m_reporter->begin(*tests);
75
76 // Execute tests. Report per-test stats.
77 for (ListIterator<TestInstance *> i(tests); i.hasCurrent(); i++)
78 {
79 TestInstance *test = i.current();
80 if (!test)
81 break;
82
83 m_reporter->prepare(*test);
84 TestResult result = test->run();
85 m_reporter->collect(*test, result);
86 }
87 // Finish testing. Report final stats.
88 m_reporter->finish(*tests);
89 return m_reporter->getFailed();
90}
Iterate through a List.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Simple linked list template class.
Definition List.h:37
Output TestResults to standard output.
static TestSuite * instance()
Retrieve the instance.
Definition Singleton.h:53
Output TestResults in TAP format to stdout.
Definition TAPReporter.h:37
Represents a test instance.
virtual TestResult run()=0
Run the test instance.
Responsible for outputting test results.
virtual void prepare(TestInstance &test)
Prepare for next test.
virtual void begin(List< TestInstance * > &tests)
Begin testing.
uint getFailed() const
Get fail count.
void setStatistics(bool value)
Set final statistics on/off.
virtual void finish(List< TestInstance * > &tests)
Finish testing.
virtual void collect(TestInstance &test, TestResult &result)
Collect test statistics.
Represents a Test result created by a TestInstance.
Definition TestResult.h:48
virtual ~TestRunner()
Destructor.
int m_argc
Program argument count.
Definition TestRunner.h:70
TestReporter * getReporter()
Get test reporter.
int run(void)
Run all discovered tests.
TestRunner(int argc, char **argv)
Class constructor.
TestReporter * m_reporter
Reports test results.
Definition TestRunner.h:76
char ** m_argv
Program argument values.
Definition TestRunner.h:73
List< TestInstance * > * getTests()
Retrieve a list of all tests.
Definition TestSuite.cpp:32
Output TestResults to standard output in XML format.
Definition XMLReporter.h:35
C int strcmp(const char *dest, const char *src)
Compare two strings.
Definition strcmp.cpp:20