2008-08-31 05:56:49 +00:00
|
|
|
<?php
|
2009-10-07 13:57:06 +00:00
|
|
|
/**
|
2008-08-31 05:56:49 +00:00
|
|
|
* Runs tests against the PHP parser.
|
|
|
|
*/
|
|
|
|
|
2017-07-08 18:49:13 +00:00
|
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
2009-10-07 13:57:06 +00:00
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
|
2017-07-08 18:49:13 +00:00
|
|
|
: __DIR__ . '/../../../maintenance/commandLine.inc';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$tester = new AbuseFilterParser;
|
|
|
|
|
2013-07-02 01:43:18 +00:00
|
|
|
$test_path = __DIR__ . "/parserTests";
|
2009-10-07 13:57:06 +00:00
|
|
|
$tests = glob( $test_path . "/*.t" );
|
2008-08-31 05:56:49 +00:00
|
|
|
|
|
|
|
$check = 0;
|
|
|
|
$pass = 0;
|
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $tests as $test ) {
|
2013-07-02 01:43:18 +00:00
|
|
|
$result = substr( $test, 0, -2 ) . ".r";
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$rule = trim( file_get_contents( $test ) );
|
2013-07-02 01:43:18 +00:00
|
|
|
$output = trim( file_get_contents( $result ) ) == 'MATCH';
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$testname = basename( $test );
|
2008-08-31 05:56:49 +00:00
|
|
|
|
|
|
|
print "Trying test $testname...\n";
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
try {
|
|
|
|
$check++;
|
2009-10-07 13:57:06 +00:00
|
|
|
$actual = intval( $tester->parse( $rule ) );
|
|
|
|
|
|
|
|
if ( $actual == $output ) {
|
2008-08-31 05:56:49 +00:00
|
|
|
print "-PASSED.\n";
|
|
|
|
$pass++;
|
|
|
|
} else {
|
|
|
|
print "-FAILED - expected output $output, actual output $actual.\n";
|
|
|
|
print "-Expression: $rule\n";
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
// export
|
|
|
|
$vars = var_export( $tester->mTokens, true );
|
2009-10-07 13:57:06 +00:00
|
|
|
file_put_contents( $test . '.parsed', $vars );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
} catch ( AFPException $excep ) {
|
|
|
|
print "-FAILED - exception " . $excep->getMessage() . " with input $rule\n";
|
|
|
|
|
2009-02-11 18:23:21 +00:00
|
|
|
// export
|
|
|
|
$vars = var_export( $tester->mTokens, true );
|
2009-10-07 13:57:06 +00:00
|
|
|
file_put_contents( $test . '.parsed', $vars );
|
2008-08-31 05:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
print "$pass tests passed out of $check\n";
|