blob: c3055c155896ef8da0d034ebfbfec47d70e51830 (
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
|
<?php
/**
* Runs tests against the PHP parser.
*/
require_once getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
: __DIR__ . '/../../../maintenance/commandLine.inc';
$tester = new AbuseFilterParser;
$test_path = __DIR__ . "/parserTests";
$tests = glob( $test_path . "/*.t" );
$check = 0;
$pass = 0;
foreach ( $tests as $test ) {
$result = substr( $test, 0, -2 ) . ".r";
$rule = trim( file_get_contents( $test ) );
$output = trim( file_get_contents( $result ) ) == 'MATCH';
$testname = basename( $test );
print "Trying test $testname...\n";
try {
$check++;
$actual = intval( $tester->parse( $rule ) );
if ( $actual == $output ) {
print "-PASSED.\n";
$pass++;
} else {
print "-FAILED - expected output $output, actual output $actual.\n";
print "-Expression: $rule\n";
// export
$vars = var_export( $tester->mTokens, true );
file_put_contents( $test . '.parsed', $vars );
}
} catch ( AFPException $excep ) {
print "-FAILED - exception " . $excep->getMessage() . " with input $rule\n";
// export
$vars = var_export( $tester->mTokens, true );
file_put_contents( $test . '.parsed', $vars );
}
}
print "$pass tests passed out of $check\n";
|