2008-08-31 05:56:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs tests against the PHP parser.
|
|
|
|
*/
|
|
|
|
|
2009-02-11 18:23:21 +00:00
|
|
|
require_once ( getenv('MW_INSTALL_PATH') !== false
|
|
|
|
? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc"
|
|
|
|
: dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
|
|
|
|
|
2008-08-31 05:56:49 +00:00
|
|
|
$tester = new AbuseFilterParser;
|
|
|
|
|
2009-02-11 01:41:51 +00:00
|
|
|
wfLoadExtensionMessages( 'AbuseFilter' );
|
|
|
|
|
2009-01-23 19:23:19 +00:00
|
|
|
$test_path = dirname( __FILE__ )."/tests";
|
2008-08-31 05:56:49 +00:00
|
|
|
$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 = ($cont = 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";
|
2009-02-11 01:41:51 +00:00
|
|
|
|
|
|
|
// export
|
|
|
|
$vars = var_export( $tester->mTokens, true );
|
|
|
|
file_put_contents( $test.'.parsed', $vars );
|
2008-08-31 05:56:49 +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 );
|
|
|
|
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";
|