File: CxxTestRunner.tpl

package info (click to toggle)
0ad 0.28.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 182,352 kB
  • sloc: cpp: 201,989; javascript: 19,730; ansic: 15,057; python: 6,597; sh: 2,046; perl: 1,232; xml: 543; java: 533; makefile: 105
file content (154 lines) | stat: -rw-r--r-- 3,404 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// vim: set filetype=cpp :

#include <cstring>
#include <cxxtest/Descriptions.h>
#include <cxxtest/ErrorPrinter.h>
#include <cxxtest/XmlPrinter.h>
#include <iostream>
#include <ps/DllLoader.h>
#include <string>

void usage(const char* prog) {
	const std::string help = std::string("Usage: ") + prog  + R"( [options]

--format    junit|simple    simple: default, good for cli - junit: for use by CI
--help                      This message
--libdir    dir             Where to find extra shared libraries, used for running tests in staging area
--list                      List available test by suite
--output    file            File to write to, defaults to stdout
--suite     suite           Only run named suite
--test      test            Only run named test of given suite
)";
	std::printf("%s\n", help.c_str());
}

int main(int argc, char **argv)
{

	char* suite = nullptr;
	char* test = nullptr;
	bool xml = false;
	std::ostream* output = &std::cout;
    std::ofstream out;

	for (int i = 1; i < argc; ++i)
	{
		if (std::strcmp(argv[i], "--libdir") == 0)
		{
			if (++i >= argc)
			{
				std::printf("Option libdir requires an optarg\n\n");
				usage(argv[0]);
				std::exit(1);
			}

			DllLoader::OverrideLibdir(argv[i]);
		}
		else if (std::strcmp(argv[i], "--format") == 0)
		{
			if (++i >= argc)
			{
				std::printf("Option format requires an optarg\n\n");
				usage(argv[0]);
				std::exit(1);
			}

			if (std::strcmp(argv[i], "junit") == 0)
				xml  = true;
			else if (std::strcmp(argv[i], "simple") == 0)
				xml = false;
			else
			{
				std::printf("Unkown format: %s\n\n", argv[i]);
				usage(argv[0]);
				std::exit(1);
			}
		}
		else if (std::strcmp(argv[i], "--output") == 0)
		{
			if (++i >= argc)
			{
				std::printf("Option output requires an optarg\n\n");
				usage(argv[0]);
				std::exit(1);
			}

			out.open(argv[i]);
			output = &out;
		}
		else if (std::strcmp(argv[i], "--list") == 0)
		{
			for (CxxTest::SuiteDescription *sd = CxxTest::RealWorldDescription().firstSuite(); sd; sd = sd->next())
			{
				std::printf("%s\n", sd->suiteName());
				for (CxxTest::TestDescription *td = sd->firstTest(); td; td = td->next())
					std::printf("    %s\n", td->testName());
			}
			std::exit(0);
		}
		else if (std::strcmp(argv[i], "--suite") == 0)
		{
			if (++i >= argc)
			{
				std::printf("Option suite requires an optarg\n\n");
				usage(argv[0]);
				std::exit(1);
			}
			suite = argv[i];
		}
		else if (std::strcmp(argv[i], "--test") == 0)
		{
			if (++i >= argc)
			{
				std::printf("Option test requires an optarg\n\n");
				usage(argv[0]);
				std::exit(1);
			}
			test = argv[i];
		}
		else if (std::strcmp(argv[i], "--help") == 0)
		{
			usage(argv[0]);
			std::exit(0);
		}
		else
		{
			std::printf("Unkown argument: %s\n\n", argv[i]);
			usage(argv[0]);
			std::exit(1);
		}
	}

	if (test)
	{
		if (!suite)
		{
			std::printf("test needs a suite specified\n\n");
			usage(argv[0]);
			std::exit(1);
		}
		if (!CxxTest::leaveOnly(suite, test))
		{
			std::printf("Unknown test '%s' in suite '%s'\n\n", test, suite);
			usage(argv[0]);
			std::exit(1);
		}
	}
	else if (suite)
	{
		if (!CxxTest::leaveOnly(suite))
		{
			std::printf("Unknown suite '%s'\n\n", suite);
			usage(argv[0]);
			std::exit(1);
		}
	}

	if (xml)
		return CxxTest::XmlPrinter(*output).run();

	return CxxTest::ErrorPrinter(*output).run();
}

// The CxxTest "world"
<CxxTest world>