forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing generate script with a new version
- Loading branch information
Zoe Slattery
committed
May 7, 2009
1 parent
903f306
commit cba448a
Showing
79 changed files
with
2,853 additions
and
1,148 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
|
||
<project name="generate" default="test" basedir="."> | ||
|
||
<property name="build.dir" value="_build" /> | ||
|
||
<target name="docs" description="Create API documentation."> | ||
<exec command="doxygen doxygen.conf" /> | ||
</target> | ||
|
||
<target name="test" description="Run all unit tests."> | ||
<exec command="phpunit --coverage-html coverage tests" passthru="true" /> | ||
</target> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* This creates a standalone phar file with all of the PHP source included. To run the | ||
* phar just type 'php generate-phpt.phar <options>' at the command line. | ||
*/ | ||
|
||
if (Phar::canWrite()) { | ||
echo "Writing phar archive\n"; | ||
} else { | ||
echo "Unable to write archive, check that phar.readonly is 0 in your php.ini\n"; | ||
exit(); | ||
} | ||
$thisDir = dirname(__FILE__); | ||
$pharPath = substr($thisDir, 0, -strlen('/generate-phpt')); | ||
|
||
$phar = new Phar($pharPath.'/generate-phpt.phar'); | ||
|
||
$phar->buildFromDirectory($thisDir.'/src'); | ||
|
||
$stub = <<<ENDSTUB | ||
<?php | ||
Phar::mapPhar('generate-phpt.phar'); | ||
require 'phar://generate-phpt.phar/generate-phpt.php'; | ||
__HALT_COMPILER(); | ||
ENDSTUB; | ||
|
||
$phar->setStub($stub); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
$index_array = array(1, 2, 3); | ||
$assoc_array = array(1 => 'one', 2 => 'two'); | ||
|
||
$variation_array = array( | ||
'empty array' => array(), | ||
'int indexed array' => $index_array, | ||
'associative array' => $assoc_array, | ||
'nested arrays' => array('foo', $index_array, $assoc_array), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$variation_array = array( | ||
'lowercase true' => true, | ||
'lowercase false' =>false, | ||
'uppercase TRUE' =>TRUE, | ||
'uppercase FALSE' =>FALSE, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** | ||
* |
11 changes: 11 additions & 0 deletions
11
scripts/dev/generate-phpt/src/codeSnippets/emptyUnsetUndefNull.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$unset_var = 10; | ||
unset($unset_var); | ||
|
||
$variation_array = array( | ||
'unset var' => @$unset_var, | ||
'undefined var' => @$undefined_var, | ||
'empty string DQ' => "", | ||
'empty string SQ' => '', | ||
'uppercase NULL' => NULL, | ||
'lowercase null' => null, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$variation_array = array( | ||
'float 10.5' => 10.5, | ||
'float -10.5' => -10.5, | ||
'float 12.3456789000e10' => 12.3456789000e10, | ||
'float -12.3456789000e10' => -12.3456789000e10, | ||
'float .5' => .5, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$variation_array = array ( | ||
'int 0' => 0, | ||
'int 1' => 1, | ||
'int 12345' => 12345, | ||
'int -12345' => -2345, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foreach ( $variation_array as $var ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { | ||
if (error_reporting() != 0) { | ||
// report non-silenced errors | ||
echo "Error: $err_no - $err_msg, $filename($linenum)\n"; | ||
} | ||
} | ||
set_error_handler('test_error_handler'); | ||
|
||
|
||
|
||
class classWithToString | ||
{ | ||
public function __toString() { | ||
return "Class A object"; | ||
} | ||
} | ||
|
||
class classWithoutToString | ||
{ | ||
} | ||
|
||
$variation_array = array( | ||
'instance of classWithToString' => new classWithToString(), | ||
'instance of classWithoutToString' => new classWithoutToString(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test is not for Windows platforms"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
$heredoc = <<<EOT | ||
hello world | ||
EOT; | ||
|
||
$variation_array = array( | ||
'string DQ' => "string", | ||
'string SQ' => 'string', | ||
'mixed case string' => "sTrInG", | ||
'heredoc' => $heredoc, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
/** | ||
* Main code for test case generation | ||
*/ | ||
|
||
require_once dirname(__FILE__) . '/gtAutoload.php'; | ||
|
||
//Version check. Will not run on less than PHP53; | ||
|
||
list($major, $minor, $bug) = explode(".", phpversion(), 3); | ||
if($major == 5) { | ||
if($minor < 3) { die("Sorry, you need PHP version 5.3 or greater to run this.\n"); } | ||
} | ||
if ($major < 5) { die ("Seriously, you need to upgrade you PHP level\n"); } | ||
|
||
|
||
$options = new gtCommandLineOptions(); | ||
$optionalSections = new gtOptionalSections(); | ||
|
||
try{ | ||
$options->parse($argv); | ||
} catch (exception $e) { | ||
echo $e->getMessage()."\n"; | ||
die(); | ||
} | ||
|
||
if($options->hasOption('h')) { | ||
die(gtText::get('help')); | ||
} | ||
|
||
try { | ||
$preConditions = new gtPreConditionList(); | ||
$preConditions->check($options); | ||
} catch (exception $e) { | ||
echo $e->getMessage()."\n"; | ||
die(); | ||
} | ||
|
||
if($options->hasOption('s')) { | ||
$optionalSections->setOptions($options); | ||
} | ||
|
||
|
||
|
||
if($options->hasOption('c')) { | ||
$name = $options->getOption('c')."_".$options->getOption('m'); | ||
$method = new gtMethod($options->getOption('c'), $options->getOption('m')); | ||
|
||
$method->setArgumentNames(); | ||
$method->setArgumentLists(); | ||
$method->setInitialisationStatements(); | ||
|
||
$method->setConstructorArgumentNames(); | ||
$method->setConstructorInitStatements(); | ||
$method->setConstructorArgumentList(); | ||
} | ||
|
||
if($options->hasOption('f')) { | ||
$name = $options->getOption('f'); | ||
$function = new gtFunction($name); | ||
$function->setArgumentNames(); | ||
$function->setArgumentLists(); | ||
$function->setInitialisationStatements(); | ||
} | ||
|
||
|
||
if($options->hasOption('b')) { | ||
if($options->hasOption('c')) { | ||
$testCase = gtBasicTestCase::getInstance($optionalSections, 'method'); | ||
$testCase->setMethod($method); | ||
} else { | ||
$testCase = gtBasicTestCase::getInstance($optionalSections); | ||
$testCase->setFunction($function); | ||
} | ||
|
||
$testCase->constructTestCase(); | ||
gtTestCaseWriter::write($name, $testCase->toString(), 'b'); | ||
} | ||
|
||
if($options->hasOption('e')) { | ||
if($options->hasOption('c')) { | ||
$testCase = gtErrorTestCase::getInstance($optionalSections, 'method'); | ||
$testCase->setMethod($method); | ||
} else { | ||
$testCase = gtErrorTestCase::getInstance($optionalSections); | ||
$testCase->setFunction($function); | ||
} | ||
|
||
$testCase->constructTestCase(); | ||
gtTestCaseWriter::write($name, $testCase->toString(), 'e'); | ||
} | ||
|
||
|
||
|
||
if($options->hasOption('v')) { | ||
if($options->hasOption('c')) { | ||
$testCaseContainer = gtVariationContainer::getInstance($optionalSections, 'method'); | ||
$testCaseContainer->setMethod($method); | ||
} else { | ||
$testCaseContainer = gtVariationContainer::getInstance ($optionalSections); | ||
$testCaseContainer->setFunction($function); | ||
} | ||
|
||
$testCaseContainer->constructAll(); | ||
|
||
$tests = $testCaseContainer->getVariationTests(); | ||
|
||
$count = 1; | ||
foreach($tests as $test) { | ||
gtTestCaseWriter::write($name, $test, 'v', $count); | ||
$count++; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
|
||
gtAutoload::init(); | ||
|
||
/** | ||
* Autoloader using a map file (gtClassMap.php) | ||
* defining the file to load each class from. | ||
*/ | ||
class gtAutoload | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static $classMap; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected static $classPath; | ||
|
||
|
||
/** | ||
* Initialize the autoloader | ||
* | ||
* @return null | ||
*/ | ||
public static function init() | ||
{ | ||
self::$classPath = dirname(__FILE__); | ||
|
||
if (substr(self::$classPath, -1) != '/') { | ||
self::$classPath .= '/'; | ||
} | ||
|
||
if (file_exists(self::$classPath . 'gtClassMap.php')) { | ||
include self::$classPath . 'gtClassMap.php'; | ||
self::$classMap = $gtClassMap; | ||
} | ||
|
||
if (function_exists('__autoload')) { | ||
spl_autoload_register('__autoload'); | ||
} | ||
|
||
spl_autoload_register(array('gtAutoload', 'autoload')); | ||
} | ||
|
||
|
||
/** | ||
* Autoload method | ||
* | ||
* @param string $class Class name to autoload | ||
* @return null | ||
*/ | ||
public static function autoload($class) | ||
{ | ||
if (isset(self::$classMap[$class])) { | ||
include self::$classPath . self::$classMap[$class]; | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
$gtClassMap = array( | ||
|
||
'gtCodeSnippet' => 'gtCodeSnippet.php', | ||
'gtTestSubject' => 'gtTestSubject.php', | ||
'gtFunction' => 'gtFunction.php', | ||
'gtMethod' => 'gtMethod.php', | ||
'gtTestCaseWriter' => 'gtTestCaseWriter.php', | ||
'gtText' => 'gtText.php', | ||
|
||
|
||
|
||
'gtCommandLineOptions' => 'setup/gtCommandLineOptions.php', | ||
'gtOptionalSections' => 'setup/gtOptionalSections.php', | ||
'gtMissingArgumentException' => 'setup/exceptions/gtMissingArgumentException.php', | ||
'gtUnknownOptionException' => 'setup/exceptions/gtUnknownOptionException.php', | ||
'gtUnknownSectionException' => 'setup/exceptions/gtUnknownSectionException.php', | ||
'gtMissingOptionsException' => 'setup/exceptions/gtMissingOptionsException.php', | ||
|
||
'gtPreCondition' => 'setup/gtPreCondition.php', | ||
'gtPreConditionList' => 'setup/gtPreConditionList.php', | ||
'gtIsSpecifiedTestType' => 'setup/preconditions/gtIsSpecifiedTestType.php', | ||
'gtIfClassHasMethod' => 'setup/preconditions/gtIfClassHasMethod.php', | ||
'gtIsSpecifiedFunctionOrMethod' => 'setup/preconditions/gtIsSpecifiedFunctionOrMethod.php', | ||
'gtIsValidClass' => 'setup/preconditions/gtIsValidClass.php', | ||
'gtIsValidMethod' => 'setup/preconditions/gtIsValidMethod.php', | ||
'gtIsValidFunction' => 'setup/preconditions/gtIsValidFunction.php', | ||
|
||
|
||
'gtTestCase' => 'testcase/gtTestCase.php', | ||
'gtVariationTestCase' => 'testcase/gtVariationTestCase.php', | ||
'gtVariationTestCaseFunction' => 'testcase/gtVariationTestCaseFunction.php', | ||
'gtVariationTestCaseMethod' => 'testcase/gtVariationTestCaseMethod.php', | ||
|
||
'gtBasicTestCase' => 'testcase/gtBasicTestCase.php', | ||
'gtBasicTestCaseFunction' => 'testcase/gtBasicTestCaseFunction.php', | ||
'gtBasicTestCaseMethod' => 'testcase/gtBasicTestCaseMethod.php', | ||
|
||
'gtErrorTestCase' => 'testcase/gtErrorTestCase.php', | ||
'gtErrorTestCaseFunction' => 'testcase/gtErrorTestCaseFunction.php', | ||
'gtErrorTestCaseMethod' => 'testcase/gtErrorTestCaseMethod.php', | ||
|
||
'gtVariationContainer' => 'testcase/gtVariationContainer.php', | ||
'gtVariationContainerMethod' => 'testcase/gtVariationContainerMethod.php', | ||
'gtVariationContainerFunction' => 'testcase/gtVariationContainerFunction.php', | ||
); | ||
?> |
Oops, something went wrong.