/
test.php
69 lines (59 loc) · 2 KB
/
test.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
<?php
function echocolor($text,$color="normal",$back=0)
{
$colors = array('light_red' => "[1;31m", 'light_green' => "[1;32m", 'yellow' => "[1;33m",
'light_blue' => "[1;34m", 'magenta' => "[1;35m", 'light_cyan' => "[1;36m",
'white' => "[1;37m", 'normal' => "[0m", 'black' => "[0;30m",
'red' => "[0;31m", 'green' => "[0;32m", 'brown' => "[0;33m",
'blue' => "[0;34m", 'cyan' => "[0;36m", 'bold' => "[1m",
'underscore' => "[4m", 'reverse' => "[7m" );
$out = $colors["$color"];
$ech = chr(27)."$out"."$text".chr(27)."[0m";
if($back)
{
return $ech;
}
else
{
echo $ech;
}
}
require 'source/ppp.php';
$parser = new PPP_Parser();
$samples = opendir($sample_dir = dirname(__FILE__).'/samples');
$output = opendir($output_dir = dirname(__FILE__).'/output');
$failures = 0;
$lines = 0;
while ($path = readdir($samples)) {
if ($path[0] == '.') {
continue;
}
list($name, $ext) = explode('.', $path);
$cur_sample = file_get_contents($sample_dir.'/'.$path);
$cur_output = file_get_contents($output_dir.'/'.$name.'.php');
$parsed = $parser->parse($cur_sample);
$output_lines = explode("\n", $cur_output);
$parsed_lines = explode("\n", $parsed);
$line = 0;
foreach ($parsed_lines as $p_line) {
$lines++;
$line++;
$o_line = array_shift($output_lines);
if (trim($p_line) != trim($o_line)) {
$failures++;
echocolor(">>>>> FAILURE!! #$failures <<<<<< \n", 'red');
echocolor($line, 'cyan');
echo '. '.$p_line;
echocolor("\n-------------\n", 'yellow');
echocolor($line, 'cyan');
echo '. '.$o_line;
echocolor("\n^^^^^^^^^^^^^^", 'yellow');
}
}
}
echo "... Parsed $lines lines!\n";
if (!$failures) {
echocolor("All tests pass!\n", 'green');
exit(0);
}
exit(1);