summaryrefslogtreecommitdiff
path: root/test/main.c
blob: 965ffeda64c35d302fe98e7a22563af3542c47d8 (plain)
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
// Copyright (C) 2010-2016 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#include "framework.h"
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#else
#include "../getopt_long.h"
#endif

// *INDENT-OFF* disable uncrustify
#define SUITE(name) unsigned suite_ ## name(unsigned);
#include "suites.h"
#undef SUITE
// *INDENT-ON* enable uncrustify

const char USAGE_TEXT[] =
  "Usage:\n"
  "    test [options]\n"
  "\n"
  "Options:\n"
  "    -h, --help      print this help text\n"
  "    -v, --verbose   enable verbose logging of tests\n";

int
main(int argc, char **argv)
{
	suite_fn suites[] = {
#define SUITE(name) &suite_ ## name,
#include "suites.h"
#undef SUITE
		NULL
	};
	static const struct option options[] = {
		{"help", no_argument, NULL, 'h'},
		{"verbose", no_argument, NULL, 'v'},
		{NULL, 0, NULL, 0}
	};
	int verbose = 0;
	int c;
	char *testdir, *dir_before;
	int result;

#ifdef _WIN32
	putenv("CCACHE_DETECT_SHEBANG=1");
#endif

	while ((c = getopt_long(argc, argv, "hv", options, NULL)) != -1) {
		switch (c) {
		case 'h':
			fprintf(stdout, USAGE_TEXT);
			return 0;

		case 'v':
			verbose = 1;
			break;

		default:
			fprintf(stderr, USAGE_TEXT);
			return 1;
		}
	}

	if (getenv("RUN_FROM_BUILD_FARM")) {
		verbose = 1;
	}

	testdir = format("testdir.%d", (int)getpid());
	cct_create_fresh_dir(testdir);
	dir_before = gnu_getcwd();
	cct_chdir(testdir);
	result = cct_run(suites, verbose);
	if (result == 0) {
		cct_chdir(dir_before);
		cct_wipe(testdir);
	}
	free(testdir);
	free(dir_before);
	return result;
}