-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathruntests.php
executable file
·166 lines (146 loc) · 3.61 KB
/
runtests.php
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
#!/usr/bin/env php
<?php
set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path());
date_default_timezone_set('Europe/Moscow');
ini_set('memory_limit', '256M');
define('LIMB_PATH', dirname(__FILE__));
require_once(LIMB_PATH . '/tests_runner/common.inc.php');
require_once(LIMB_PATH . '/tests_runner/src/lmbTestRunner.class.php');
require_once(LIMB_PATH . '/tests_runner/src/lmbTestTreeFilePathNode.class.php');
require_once(LIMB_PATH . '/tests_runner/src/lmbTestTreeGlobNode.class.php');
$fork = true;
$quiet = false;
$tests = array();
$cover = false;
$skipped = array();
function out($msg)
{
global $quiet;
if(!$quiet)
echo $msg;
}
function process_argv(&$argv, &$defines = array())
{
global $quiet;
global $fork;
global $cover;
global $skipped;
$new_argv = array();
$selected_option = '';
$next_is_def = false;
foreach($argv as $arg)
{
// control arguments
switch($arg)
{
case '-C':
case '--cover':
$cover = true;
$defines[] = $arg;
break;
case '-D':
$next_is_def = true;
break;
case '-q':
$quiet = true;
break;
case '--no-fork':
$fork = false;
break;
case '--include-path':
case '--skip':
$selected_option = $arg;
break;
case '--':
$selected_option = '';
break;
default:
if($next_is_def)
{
list($dn,$dv) = explode('=', $arg);
$defines[] = "-D \"$dn=$dv\"";
echo "Defining $dn=$dv\n";
define("$dn", $dv);
$next_is_def = false;
break;
}
// value arguments
switch($selected_option)
{
case '--skip':
$skipped[] = $arg;
break;
case '--include-path':
set_include_path(dirname(__FILE__) . '/' . $arg . PATH_SEPARATOR . get_include_path());
$selected_option = '';
break;
default:
$new_argv[] = $arg;
break;
}
}
}
$argv = $new_argv;
}
function get_php_bin()
{
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_contents();
ob_end_clean();
if(isset($_ENV["_"]) && basename($_ENV["_"]) != basename(__FILE__))
$php_bin = $_ENV["_"];
else
$php_bin = "php";//any better way to guess it otherwise?
$php_ini = "";
$lines = explode("\n", $info);
foreach($lines as $line)
{
if(preg_match('~^Loaded Configuration File\s*=>\s*(.*)$~', $line, $m))
{
if(file_exists($m[1]))
$php_ini = "-c " . $m[1];
}
}
return $php_bin . " " . $php_ini;
}
$defines = array();
process_argv($argv, $defines);
if(sizeof($argv) > 1)
$tests = array_splice($argv, 1);
if(!$tests)
$tests = glob("*", GLOB_ONLYDIR);
$tests = array_diff($tests, $skipped);
if($fork)
{
$php_bin = get_php_bin();
out("=========== Forking processes for each test path(PHP cmdline '$php_bin') ===========\n");
}
$res = true;
foreach($tests as $test)
{
if(file_exists($test) || is_dir($test))
{
if($fork)
{
system($php_bin . " " . __FILE__ . " -q --no-fork " . implode(" ", $defines) . " $test", $ret);
if($ret != 0)
$res = false;
}
else
{
$runner = new lmbTestRunner();
if($cover)
$runner->useCoverage($test . '/src', '', '');
if(!$runner->run(new lmbTestTreeFilePathNode($test)))
$res = false;
}
}
else
out("=========== Test path '$test' is not valid, skipping ==========\n");
}
if(!$res)
out("=========== TESTS HAD ERRORS(see above) ===========\n");
else
out("=========== ALL TESTS PASSED ===========\n");
exit($res ? 0 : 1);