forked from pear/pear-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-modified.php
152 lines (136 loc) · 4.07 KB
/
test-modified.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
<?php
namespace {
$norender = $force = $path = false;
if (isset($_SERVER['argv'][1])) {
$arg = $_SERVER['argv'][1];
if ($arg === '--force') {
$force = true;
if (!isset($_SERVER['argv'][2])) {
goto skippy;
}
// check if we only want to rebuild the coverage db
if ($_SERVER['argv'][2] === '--norender') {
$norender = true;
if (!isset($_SERVER['argv'][3])) {
goto skippy;
}
$arg = $_SERVER['argv'][3];
} else {
$arg = $_SERVER['argv'][2];
}
} elseif ($arg === '--norender') {
$norender = true;
if (!isset($_SERVER['argv'][2])) {
goto skippy;
}
if ($_SERVER['argv'][2] === '--force') {
$force = true;
if (!isset($_SERVER['argv'][3])) {
goto skippy;
}
$arg = $_SERVER['argv'][3];
} else {
$arg = $_SERVER['argv'][2];
}
}
$realpath = realpath($arg);
if ($realpath) {
$path = realpath($realpath . '/Pyrus_Developer/src/Pyrus/Developer/CoverageAnalyzer');
}
if ($realpath && !$path) {
$path = realpath($realpath . '/Pyrus_Developer/trunk/src/Pyrus/Developer/CoverageAnalyzer');
}
}
skippy:
if (!$path) {
$path = realpath(__DIR__ . '/../all/Pyrus_Developer/src/Pyrus/Developer/CoverageAnalyzer');
}
if (!$path) {
die("Usage:
php test-modified.php [--force] [--norender] [/path/to/all]
--force:
Generate coverage even if no changes or failed tests
--norender:
Do not generate coverage html files, just rebuild the database
/path/to/all:
Pass in path to checkout of http://svn.pear.php.net/PEAR2/all,
by default, we assume ../all
");
}
function __autoload($c)
{
$c = str_replace(array('PEAR2\Pyrus\Developer\CoverageAnalyzer\\',
'\\'), array('', '/'), $c);
include $GLOBALS['path'] . '/' . $c . '.php';
}
$e = error_reporting();
error_reporting(0);
$olddir = getcwd();
$testpath = realpath(__DIR__ . '/tests');
chdir($testpath);
$pear = @fopen('PEAR.php', 'r', 1);
if (!$pear) {
die("Install PEAR before attempting to run the tests\n");
}
fclose($pear);
foreach (explode(PATH_SEPARATOR, get_include_path()) as $includepath) {
if (file_exists($includepath . DIRECTORY_SEPARATOR . 'PEAR.php')) {
$codepath = $includepath;
break;
}
}
if (!isset($codepath)) {
die("Something is wrong - PEAR.php exists, but was not within include_path\n");
}
require_once 'PEAR/Command/Test.php';
require_once 'PEAR/Frontend/CLI.php';
require_once 'PEAR/Config.php';
$cli = new PEAR_Frontend_CLI;
$config = @PEAR_Config::singleton();
$test = new PEAR_Command_Test($cli, $config);
error_reporting($e);
chdir($olddir);
}
namespace PEAR2\Pyrus\Developer\CoverageAnalyzer {
$sqlite = new Sqlite($testpath . '/pear2coverage.db', $codepath, $testpath);
$modified = $sqlite->getModifiedTests();
if (!$force && !count($modified)) {
echo "No changes to coverage needed. Bye!\n";
exit;
}
if (!count($modified) && $force) {
goto norunnie;
}
chdir($testpath);
$e = error_reporting();
error_reporting(0);
$test->doRunTests('run-tests', array('coverage' => true), $modified);
error_reporting($e);
chdir($olddir);
if (!$force && file_exists($testpath . '/run-tests.log')) {
// tests failed
echo "Tests failed - not regenerating coverage data\n";
exit;
}
norunnie:
$a = new Aggregator($testpath,
$codepath,
$testpath . '/pear2coverage.db');
if ($norender) {
exit;
}
if (file_exists(__DIR__ . '/coverage')) {
echo "Removing old coverage HTML...";
foreach (new \DirectoryIterator(__DIR__ . '/coverage') as $file) {
if ($file->isDot()) continue;
unlink($file->getPathName());
}
echo "done\n";
} else {
mkdir(__DIR__ . '/coverage');
}
echo "Rendering\n";
$a->render(__DIR__ . '/coverage');
echo "Done rendering\n";
}
?>