summaryrefslogtreecommitdiff
path: root/_test/runtests.php
blob: 8b93efec3d8183c2d3354a05a8d666637a78d70a (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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/php -q
<?php
ini_set('memory_limit','128M');
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
define('DOKU_UNITTEST',true);

require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/events.php');

define('TEST_ROOT', dirname(__FILE__));
define('TMPL_FILESCHEME_PATH', TEST_ROOT . '/filescheme/');

require_once 'lib/testmanager.php';
TestManager::setup();

function usage() {
    $usage = <<<EOD
Usage: ./runtests.php [OPTION]...
Run the Dokuwiki unit tests. If ALL of the test cases pass a count of total
passes is printed on STDOUT. If ANY of the test cases fail (or raise
errors) details are printed on STDERR and this script returns a non-zero
exit code.
  -c  --case=NAME         specify a test case by it's ID (see -i for list)
  --pcase=NAME            specify a plugin test case by it's ID 
                          (see --plugincaselist for list)
  -f  --file=NAME         specify a test case file (full or relative path)
  -g  --group=NAME        specify a grouptest. If no grouptest is
                          specified, all test cases will be run.
  --pgroup=NAME           specify a plugin grouptest. If no grouptest is
                          specified, all test cases will be run.
  -i  --caselist          list individual test cases by their ID
  -l  --grouplist         list available grouptests
  --plugincaselist        list all individual plugin test cases by their ID
  --plugingrouplist       list avialable plugin grouptests
  -s, --separator=SEP     set the character(s) used to separate fail
                          details to SEP
  -p, --path              path to SimpleTest installation
  -h, --help              display this help and exit

EOD;
    echo $usage;
    exit(0);
}

/* test options */
$opt_separator = '->';
$opt_caselist = FALSE;
$opt_grouplist = FALSE;
$opt_plugincaselist = FALSE;
$opt_plugingrouplist = FALSE;
$opt_caseid = FALSE;
$top_plugincaseid = FALSE;
$opt_casefile = FALSE;
$opt_groupfile = FALSE;
$opt_plugingroupfile = FALSE;

include_once(DOKU_INC.'inc/cliopts.php');

$short_opts = "c:f:g:hils:p:";
$long_opts  = array("case=","pcase=","caselist","help", "file=", "group=", "pgroup=", "grouplist", "plugincaselist", "plugingrouplist", "separator=", "path=");
$OPTS = Doku_Cli_Opts::getOptions(__FILE__,$short_opts,$long_opts);
if ( $OPTS->isError() ) {
    fwrite( STDERR, $OPTS->getMessage() . "\n");
    usage($available_grouptests);
    exit(1);
}

foreach ($OPTS->options as $key => $val) {
    switch ($key) {
        case 'c':
        case 'case':
            $opt_caseid = $val;
            break;
        case 'pcase':
            $opt_plugincaseid = $val;
            break;
        case 'h':
        case 'help':
            usage();
            break;
        case 'f':
        case 'file':
            $opt_casefile = $val;
            break;
        case 'g':
        case 'group':
            $opt_groupfile = $val;
            break;
        case 'pgroup':
            $opt_plugingroupfile = $val;
            break;
        case 'i':
        case 'caselist':
            $opt_caselist = TRUE;
            break;
        case 'l':
        case 'grouplist':
            $opt_grouplist = TRUE;
            break;
        case 'plugincaselist':
            $opt_plugincaselist = TRUE;
            break;
        case 'plugingrouplist':
            $opt_plugingrouplist = TRUE;
            break;
        case 's':
        case 'separator':
            $opt_separator = $val;
            break;
        case 'p':
        case 'path':
            if (file_exists($val)) {
                define('SIMPLE_TEST', $val);
            }
            break;
   }
}

if (!@include_once SIMPLE_TEST . 'reporter.php') {
    die("Where's Simple Test ?!? Not at ".SIMPLE_TEST);
}

require_once 'lib/cli_reporter.php';

/* list grouptests */
if ($opt_grouplist) {
    echo CLITestManager::getGroupTestList(TEST_GROUPS);
}

/* list test cases */
if ($opt_caselist) {
    echo CLITestManager::getTestCaseList(TEST_CASES);
}

/* list plugin test cases */
if ($opt_plugincaselist) {
    echo CLITestManager::getPluginTestCaseList(TEST_PLUGINS);
}

/* list plugin group tests */
if($opt_plugingrouplist) {
    echo CLITestManager::getPluginGroupTestList(TEST_PLUGINS);
}

/* exit if we've displayed a list */
if ( $opt_grouplist || $opt_caselist || $opt_plugincaselist || $opt_plugingrouplist ) {
    exit(0);
}

/* run a test case */
if ($opt_casefile) {
    TestManager::runTestFile($opt_casefile, new CLIReporter($opt_separator));
    exit(0);
}

/* run a test case by id */
if ($opt_caseid) {
    TestManager::runTestCase($opt_caseid, TEST_CASES, new CLIReporter($opt_separator));
    exit(0);
}

/* run a plugin test by case id */
if ($opt_plugincaseid) {
    TestManager::runTestCase($opt_plugincaseid, TEST_PLUGINS, new CLIReporter($opt_separator));
    exit(0);
}

/* run a grouptest */
if ($opt_groupfile) {
    TestManager::runGroupTest($opt_groupfile, TEST_GROUPS,
                              new CLIReporter($opt_separator));
    exit(0);
}

/* run a plugin grouptest */
if ($opt_plugingroupfile) {
    TestManager::runGroupTest($opt_plugingroupfile, TEST_PLUGINS,
                              new CLIReporter($opt_separator));
    exit(0);
}

/* run a plugin group test */
//FIXME
/* run all tests */
TestManager::runAllTests(new CLIReporter($opt_separator));
exit(0);
?>