-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathregress.php
151 lines (139 loc) · 4.36 KB
/
regress.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
<html>
<head>
<title>Shield Regression Test Page</title></head>
<body>
<h1>Shield Regression Test V0.1</h1>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Diffs</th>
</tr>
<?php /* Copyright 2010 Karl R. Wilcox
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
include_once "Text/Diff.php";
include_once "Text/Diff/Renderer.php";
function formatXML($xmlArray) {
$xmlText = '';
foreach ($xmlArray as $line) {
$len = strlen($line);
$xmlText .= $line{0};
for ($i = 1; $i < $len; $i++ ) {
$ch = $line{$i};
switch ($ch) {
case '<':
$xmlText .= "\n<";
break;
case "\n":
break;
default:
$xmlText .= $ch;
break;
}
}
$xmlText .= "\n";
}
return $xmlText;
}
function writeFile($outfile, $output) {
$fh = fopen( $outfile, 'wb' );
fwrite($fh,formatXML($output));
fclose($fh);
}
function runTest($data) {
global $rebuild;
if ( array_key_exists('format',$data) )
$output = file('http://server1/include/shield/drawshield?format=' . $data['format'] . '&blazon=' . urlencode($data['blazon']));
else
$output = file('http://server1/include/shield/drawshield?blazon=' . urlencode($data['blazon']));
$outfile = 'regress\\' . $data['name'] . '.out';
$difffile = 'regress\\' . $data['name'] . '.diff';
if ( !$rebuild and file_exists ( $outfile )) {
$output = explode("\n",rtrim(formatXML($output)));
$previous = file( $outfile );
$diff = &new Text_Diff($output, $previous);
$renderer = &new Text_Diff_Renderer();
$diffString = $renderer->render($diff);
if ( $diffString ) {
$back = 'red';
$diffCell = '<pre>' . htmlentities($diffString) . '</pre>';
} else {
$back = 'green';
$diffCell = 'No changes';
}
} else {
$back = 'yellow';
$diffCell = 'Output created';
writeFile( $outfile, $output );
}
echo '<tr>';
echo '<td style="background-color:' . $back . '">' . $data['name'] . '</td>';
echo '<td>' . $data['desc'] . '</td>';
echo '<td>' . $diffCell . '</td>';
echo '</tr>';
return !( $back == 'red' );
}
function readTests($filename) {
$lines = file($filename);
$firstline = trim($lines[0]);
if ($firstline{0} == '#' )
echo '<tr><th colspan="3">' . $firstline . '</th></tr>';
$testData = array( 'fatal' => false, 'desc' => '(not given)', 'blazon' => '' );
$firstTest = true;
$multi = false;
foreach ( $lines as $line ) {
$line = trim($line);
if ( $line == '' or $line{0} == '#' ) continue;
$keyValue = explode(':',$line);
$key = $keyValue[0];
$value = count($keyValue) > 1 ? $keyValue[1] : '';
if ( $multi ) {
if ( $value == '' ) {
$testData['blazon'] .= " $key";
continue;
} else
$multi = false;
}
if ( $key == 'blazon' and $value == '' ) {
$multi = true;
continue;
}
if ( $key == 'name' ) {
if ( $firstTest ) {
$success = true;
$firstTest = false;
} else
$success = runTest($testData);
if ( !$success and array_key_exists('fatal',$testData) and $testData['fatal'] == 'true' ) return false;
$testData = array( 'name' => $value, 'fatal' => false, 'desc' => '(not given)', 'blazon' => '' );
} else
$testData[$key] = $value;
}
if ( !$firstTest ) runTest($testData);
return true;
}
$rebuild = false;
$group = '';
if (isset($_GET['rebuild'])) $rebuild = true;
if (isset($_GET['group'])) $group = $_GET['group'];
// Read in the test scripts
$dir = opendir('regress');
$success = true;
while ( $success and ($file = readdir($dir)) != false ) {
if ( substr($file,-5) == '.test' ) {
if ( $group == '' or strpos($file,$group) !== false )
$success = readTests("regress/$file");
}
}
?>
</table>
</body>
</html>