Permalink
Browse files

Redirect tests implementaion

  • Loading branch information...
zoe slattery
zoe slattery committed Oct 3, 2012
1 parent ca7438d commit 2a000e34b920604b6633d5a96950d30fdd9285d0
@@ -0,0 +1,8 @@
+--TEST--
+Try a sample test
+--FILE--
+<?php
+ echo "Hello world\n";
+?>
+--EXPECT--
+Hello world
@@ -8,6 +8,6 @@ return array(
'ENV' => array(
'PDOTEST_DSN' => 'sqlite::memory:'
),
- 'TESTS' => 'ext/pdo/tests'
+ 'TESTS' => 'phpt-tests/redirected/tests'
);
@@ -0,0 +1,41 @@
+--TEST--
+Test to check that the warnings generated by running the INI section don't stop SKIPIF fprocessing
+--INI--
+session.upload_progress.freq=200%
+error_log=
+--SKIPIF--
+<?php
+if (!extension_loaded("session") && ini_get("enable_dl")) {
+ $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
+ @dl("session$dlext");
+}
+if (!extension_loaded("session")) {
+ die("skip Session module not loaded");
+}
+$save_path = ini_get("session.save_path");
+if ($save_path) {
+ if (!file_exists($save_path)) {
+ die("skip Session save_path doesn't exist");
+ }
+
+ if ($save_path && !@is_writable($save_path)) {
+ if (($p = strpos($save_path, ';')) !== false) {
+ $save_path = substr($save_path, ++$p);
+ }
+ if (!@is_writable($save_path)) {
+ die("skip session.save_path $save_path is not writable\n");
+ }
+ }
+}
+if(substr(PHP_OS, 0, 3) != "WIN")
+ die("skip windows only test");
+?>
+--FILE--
+<?php
+var_dump(ini_get("session.upload_progress.freq"));
+?>
+--EXPECTF--
+Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s
+string(2) "1%"
+PHP Warning: PHP Startup: session.upload_progress.freq cannot be over 100% in %s
+
View
@@ -60,8 +60,8 @@ public static function parseDir($path)
{
$list = array();
$found = false;
-
foreach (scandir($path) as $file) {
+
if (substr($file, 0, 1) != '.' && $file != 'CVS') {
@@ -18,7 +18,7 @@ class rtTaskScheduler
protected $taskList = array(); // the list of the tasks to be executed
protected $resultList = array(); // list of results
protected $processCount = 0; // the number of processes
- protected $reportStatus = 0; // reprort-status
+ protected $reportStatus = 0; // the level of repoerting as tests atr run (0, 1, 2)
protected $redirectedTestCases = array();
@@ -16,12 +16,14 @@ class rtTaskTestGroup extends rtTask implements rtTaskInterface
protected $runConfiguration;
protected $subDirectory;
protected $redirectedTestCases = array();
+ protected $groupConfig;
- public function __construct($runConfiguration, $subDirectory)
+ public function __construct($runConfiguration, $subDirectory, $groupConfig)
{
$this->runConfiguration = $runConfiguration;
$this->subDirectory = $subDirectory;
+ $this->groupConfig = $groupConfig;
}
@@ -31,7 +33,7 @@ public function __construct($runConfiguration, $subDirectory)
*/
public function run()
{
- $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory);
+ $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory, $this->groupConfig);
$testGroup->run();
$this->result = $testGroup->getResults();
return true;
View
@@ -24,11 +24,13 @@ class rtPhpTest
protected $fileSection;
protected $expectSection;
protected $sectionHeadings;
+ protected $redirectFromID = null;
- public function __construct(array $contents, $testName, $sectionHeadings, $runConfiguration, $testStatus)
+ public function __construct(array $contents, $testName, $sectionHeadings, $runConfiguration, $testStatus, $redirectFromID=null)
{
$this->contents = $contents;
$this->testName = $testName;
+ $this->redirectFromID = $redirectFromID;
$this->sectionHeadings = $sectionHeadings;
$this->testStatus = $testStatus;
$this->parse();
@@ -79,11 +81,16 @@ public function parse()
//Identify the file and expect section types
$this->fileSection = $this->setFileSection();
$this->expectSection = $this->setExpectSection();
+
+ //If the test is being run as a result of being redirected from somewhere else, update the TEST section with an identifier
+ if($this->redirectFromID != null) {
+ $this->sections['TEST']->addString(' Redirected ' . $this->redirectFromID . ' test');
+ }
}
/**
- * Initialises the configuration for this test. Uses the configuration sections from teh test case
+ * Initialises the configuration for this test. Uses the configuration sections from the test case
*
* @param rtRunTEstsConfiuration $runConfiguration
*
@@ -106,12 +113,12 @@ public function executeTest(rtRuntestsConfiguration $runConfiguration)
$this->testStatus = $this->sections['SKIPIF']->run($this, $runConfiguration);
$this->testStatus->setExecutedPhpCommand($this->sections['SKIPIF']->getPhpCommand());
}
- //TODO: D'oh - what is this meant to be?
- if (!$this->testStatus->getValue('skip') && !$this->testStatus->getValue('skip')) {
+
+ if (!$this->testStatus->getValue('skip')) {
$this->testStatus = $this->fileSection->run($this, $runConfiguration);
$this->testStatus->setExecutedPhpCommand($this->fileSection->getPhpCommand());
- //The test can be skipped by file sections if the CGI executable is not available
+ //The test status can also be set to 'skip' if the PHP CGI is missing, so we need to check it again here.
if(!$this->testStatus->getValue('skip')) {
$this->output = $this->fileSection->getOutput();
$this->compareOutput();
@@ -92,15 +92,18 @@ protected function setEnvironmentVariables(rtRuntestsConfiguration $runConfigura
protected function setPhpCommandLineArguments(rtRuntestsConfiguration $runConfiguration, $sections, $fileSection)
{
//Use different arguments for running SKIPIF and so on. The INI settings may be designed to
- //produce an error whaich will inetrfere with SKIPIF processing.
- $this->phpNonFileSectionCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments');
+ //produce an error which will interfere with SKIPIF processing.
+ //TODO: But in some cases the INI section is required for SKIPIF so we need another way to deal with this.
+ //$this->phpNonFileSectionCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments');
$this->phpCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments');
if (array_key_exists('INI', $sections)) {
$sections['INI']->substitutePWD($fileSection->getFileName());
$additionalArguments = $sections['INI']->getCommandLineArguments();
$args = new rtIniAsCommandLineArgs();
$this->phpCommandLineArguments = $args->settingsToArguments($additionalArguments, $this->phpCommandLineArguments);
}
+ //For SKIPIF sections - supress the error reporting which interferes with skip and warn processing
+ $this->phpNonFileSectionCommandLineArguments = preg_replace('/error_reporting=32767/', 'error_reporting=0', $this->phpCommandLineArguments);
}
protected function setTestCommandLineArguments($sections)
@@ -98,21 +98,27 @@ public function write($filename=null)
* @param integer $processCount
* @return string
*/
- public function getOverview($groups=NULL, $processCount=NULL)
+ public function getOverview($parallelGroups = 0, $serialGroups= 0, $processCount= 1)
{
// if the overview was already created retun it
if (!is_null($this->overview)) {
return $this->overview;
}
+ /*
+ * Most of the code uses processCount = 0 to indicate serial runs. Clearly there must always be one process,
+ * so it is set to 1 here to make the output make sense.
+ */
+ if($processCount == 0) {
+ $processCount ++;
+ }
+
// collect data
$state = array();
$count = 0;
- foreach ($this->resultList as $testGroupResults) {
-
- foreach ($testGroupResults as $testResult) {
-
+ foreach ($this->resultList as $groupResult) {
+ foreach($groupResult as $testResult) {
$s = $testResult->getStatus()->__toString();
if (!isset($state[$s])) {
@@ -121,40 +127,48 @@ public function getOverview($groups=NULL, $processCount=NULL)
$state[$s]++;
$count++;
- }
+ }
}
// create the output-string
+ $secondColPosition = 30;
$str = '';
$str .= "\n\n----------------------------------------\n";
- $str .= "Tests:\t\t$count\n";
+ $str .= "Tests:";
+ $blanks = 30 - strlen("Tests:") - strlen($count);
+ $str = $this->writeBlanks($str, $blanks);
+ $str .= "$count\n";
- if (is_numeric($groups)) {
+ if (is_numeric($parallelGroups)) {
- $str .= "Groups:\t\t";
- $blanks = strlen($count)-strlen($groups);
- for ($b=0; $b<$blanks; $b++) {
- $str .= ' ';
- }
- $str .= $groups."\n";
+ $str .= "Parallel Groups:";
+ $blanks = 30 - strlen("Parallel Groups:") - strlen($parallelGroups);
+ $str = $this->writeBlanks($str, $blanks);
+ $str .= $parallelGroups."\n";
+ }
+
+ if (is_numeric($serialGroups)) {
+
+ $str .= "Serial Groups:";
+ $blanks = 30 - strlen("Serial Groups:") - strlen($serialGroups);
+ $str = $this->writeBlanks($str, $blanks);
+ $str .= $serialGroups."\n";
}
if (is_numeric($processCount)) {
- $str .= "Processes:\t";
- $blanks = strlen($count)-strlen($processCount);
- for ($b=0; $b<$blanks; $b++) {
- $str .= ' ';
- }
+ $str .= "Processes:";
+ $blanks = 30 -strlen("Processes:") - strlen($processCount);
+ $str = $this->writeBlanks($str, $blanks);
$str .= $processCount."\n";
}
$str .= "----------------------------------------\n";
-
+
foreach ($state as $k => $v) {
- $str .= strtoupper($k).":\t";
+ $str .= substr(strtoupper($k), 0, 5).":\t";
$blanks = strlen($count)-strlen($v);
for ($b=0; $b<$blanks; $b++) {
@@ -289,6 +303,12 @@ public static function flushResult(array $results, $state=0, $cid=NULL)
flush();
}
+ public function writeBlanks($str, $n) {
+ for ($b=0; $b<$n; $b++) {
+ $str .= ' ';
+ }
+ return $str;
+ }
}
?>
@@ -34,7 +34,7 @@ public function __construct(rtPhpTest $testCase = null, rtTestStatus $testStatus
public function init(rtPhpTest $testCase = null, rtTestStatus $testStatus = null)
{
if ($testCase != null) {
- $this->title = implode('',$testCase->getSection('TEST')->getContents());
+ $this->title = $testCase->getSection('TEST')->getHeader();
$this->testStatus = $testCase->getStatus();
$this->testName = $testCase->getName();
if($testStatus == 'redirected') {
@@ -109,7 +109,7 @@ protected function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfi
if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) {
$testCase->getSection('CLEAN')->deleteFile();
} else {
- $this->savedFileNames['clean'] = $this->testName. ".clean";
+ $this->savedFileNames['clean'] = $this->testName. ".clean.php";
}
}
@@ -148,11 +148,11 @@ protected function onFail(rtPhpTest $testCase)
//Note: if there are clean and skipif files they will not be deleted if the test fails
if ($testCase->hasSection('CLEAN')) {
- $this->savedFileNames['clean'] = $this->testName. 'clean.php';
+ $this->savedFileNames['clean'] = $this->testName. '.clean.php';
}
if ($testCase->hasSection('SKIPIF')) {
- $this->savedFileNames['skipif'] = $this->testName. 'skipif.php';
+ $this->savedFileNames['skipif'] = $this->testName. '.skipif.php';
}
if($testCase->getStatus()->getValue('leak') == true) {
@@ -163,19 +163,10 @@ protected function onFail(rtPhpTest $testCase)
protected function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration)
{
if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) {
- $this->savedFileNames['skipif'] = $this->testName. 'skipif.php';
+ $this->savedFileNames['skipif'] = $this->testName. '.skipif.php';
} else if($testCase->hasSection('SKIPIF')) {
$testCase->getSection('SKIPIF')->deleteFile();
}
-
- //TODO I think this can go? Have since updated code to BORK on finding blank sections
- //It may seem odd to check for an XFAIL if we are skipping the test, on the other hand I found
- //a few windows tests with blank XFAIL sections and wanted to know about those.
-
- if ($testCase->hasSection('XFAIL')) {
- $this->testStatus->setTrue('xfail');
- $this->testStatus->setMessage('xfail',$testCase->getSection('XFAIL')->getReason());
- }
}
@@ -40,7 +40,7 @@ public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfigurati
$phpCommand .= ' -f '.$this->fileName;
$this->phpCommand = $phpCommand;
-
+
$PhpRunner = new rtPhpRunner($phpCommand,
$runConfiguration->getEnvironmentVariables(),
$runConfiguration->getSetting('WorkingDirectory')
@@ -26,5 +26,9 @@ public function getHeader()
{
return $this->testHeader;
}
+
+ public function addString($string) {
+ $this->testHeader .= $string;
+ }
}
?>
Oops, something went wrong.

0 comments on commit 2a000e3

Please sign in to comment.