~ubuntu-branches/debian/stretch/ccache/stretch

« back to all changes in this revision

Viewing changes to test/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Joel Rosdahl
  • Date: 2010-12-02 21:05:17 UTC
  • mfrom: (5.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20101202210517-ji5owl2qa3s5c1rg
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Mode: -*-c-*- */
 
2
/*
 
3
 * Copyright (C) 2010 Joel Rosdahl
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify it
 
6
 * under the terms of the GNU General Public License as published by the Free
 
7
 * Software Foundation; either version 3 of the License, or (at your option)
 
8
 * any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 
13
 * more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along with
 
16
 * this program; if not, write to the Free Software Foundation, Inc., 51
 
17
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
18
 */
 
19
 
 
20
#include "test/framework.h"
 
21
#ifdef HAVE_GETOPT_LONG
 
22
#include <getopt.h>
 
23
#else
 
24
#include "getopt_long.h"
 
25
#endif
 
26
 
 
27
#define SUITE(name) unsigned suite_##name(unsigned);
 
28
#include "test/suites.h"
 
29
#undef SUITE
 
30
 
 
31
const char USAGE_TEXT[] =
 
32
        "Usage:\n"
 
33
        "    test [options]\n"
 
34
        "\n"
 
35
        "Options:\n"
 
36
        "    -h, --help      print this help text\n"
 
37
        "    -v, --verbose   enable verbose logging of tests\n";
 
38
 
 
39
int
 
40
main(int argc, char **argv)
 
41
{
 
42
        suite_fn suites[] = {
 
43
#define SUITE(name) &suite_##name,
 
44
#include "test/suites.h"
 
45
#undef SUITE
 
46
                NULL
 
47
        };
 
48
        static const struct option options[] = {
 
49
                {"help", no_argument, NULL, 'h'},
 
50
                {"verbose", no_argument, NULL, 'v'},
 
51
                {NULL, 0, NULL, 0}
 
52
        };
 
53
        int verbose = 0;
 
54
        int c;
 
55
        char *testdir, *dir_before;
 
56
        int result;
 
57
 
 
58
        while ((c = getopt_long(argc, argv, "hv", options, NULL)) != -1) {
 
59
                switch (c) {
 
60
                case 'h':
 
61
                        fprintf(stdout, USAGE_TEXT);
 
62
                        return 0;
 
63
 
 
64
                case 'v':
 
65
                        verbose = 1;
 
66
                        break;
 
67
 
 
68
                default:
 
69
                        fprintf(stderr, USAGE_TEXT);
 
70
                        return 1;
 
71
                }
 
72
        }
 
73
 
 
74
        if (getenv("RUN_FROM_BUILD_FARM")) {
 
75
                verbose = 1;
 
76
        }
 
77
 
 
78
        testdir = format("testdir.%d", (int)getpid());
 
79
        cct_create_fresh_dir(testdir);
 
80
        dir_before = gnu_getcwd();
 
81
        cct_chdir(testdir);
 
82
        result = cct_run(suites, verbose);
 
83
        if (result == 0) {
 
84
                cct_chdir(dir_before);
 
85
                cct_wipe(testdir);
 
86
        }
 
87
        free(testdir);
 
88
        free(dir_before);
 
89
        return result;
 
90
}