g2 Sun Jul 5 20:51:16 2009 UTC
Modified files:
/phpruntests/src/testcase/output rtTestOutputWriterList.php
rtTestOutputWriterCSV.php
rtTestOutputWriterXML.php
/phpruntests/src/taskScheduler rtTaskScheduler.php
rtTaskSchedulerFile.php rtTask.php
rtTaskTestGroup.php
/phpruntests/src/testcase rtTestResults.php rtTestOutputWriter.php
rtTestStatus.php
/phpruntests/tests rtTaskSchedulerTest.php
/phpruntests/src run-tests.php
/phpruntests/src/configuration rtCommandLineOptions.php
/phpruntests/src/testrun rtPhpTestRun.php
Log:
phpruntests - rebuild outputWriter - added option to flush test-results
during execution - minor adjustments taskScheduler
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/output/rtTestOutputWriterList.php?r1=1.6&r2=1.7&diff_format=u
Index: phpruntests/src/testcase/output/rtTestOutputWriterList.php
diff -u phpruntests/src/testcase/output/rtTestOutputWriterList.php:1.6
phpruntests/src/testcase/output/rtTestOutputWriterList.php:1.7
--- phpruntests/src/testcase/output/rtTestOutputWriterList.php:1.6 Mon Jun
29 01:34:54 2009
+++ phpruntests/src/testcase/output/rtTestOutputWriterList.php Sun Jul 5
20:51:15 2009
@@ -2,12 +2,13 @@
/**
* rtTestOutputWriterList
*
- * Write test output line by line to stdout
+ * Write test output line by line
*
* @category Testing
* @package RUNTESTS
* @author Zoe Slattery <[email protected]>
* @author Stefan Priebsch <[email protected]>
+ * @author Georg Gradwohl <[email protected]>
* @copyright 2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @link http://qa.php.net/
@@ -15,22 +16,15 @@
*/
class rtTestOutputWriterList extends rtTestOutputWriter
{
- protected $testOutput = array();
-
- public function __construct(array $testResults)
+ public function __construct()
{
- $this->init($testResults);
+ $this->type = 'txt';
}
- /**
- *
- *
- * @param array of rtTestResults
- *
- */
- public function init (array $testResults)
+
+ public function createOutput()
{
- foreach ($testResults as $testResult) {
+ foreach ($this->resultList as $testResult) {
$outputString = "";
$testStatus = $testResult->getStatus();
foreach($testStatus->getTestStateNames() as $name) {
@@ -41,25 +35,9 @@
}
$outputString .= " " . $testResult->getTitle();
$outputString .= " [" . $testResult->getName() . ".phpt]";
- $this->testOutput[] = $outputString;
+ $this->output .= $outputString."\n";
}
}
-
- public function write($testDirectory = null, $cid = null)
- {
- if ($testDirectory != null) {
- echo "\n\nTest output for tests in " . $testDirectory . "\n";
- }
- sort($this->testOutput);
- foreach ($this->testOutput as $line) {
-
- if (!is_null($cid)) {
- echo "$cid - ";
- }
-
- echo $line ."\n";
- }
- }
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/output/rtTestOutputWriterCSV.php?r1=1.3&r2=1.4&diff_format=u
Index: phpruntests/src/testcase/output/rtTestOutputWriterCSV.php
diff -u phpruntests/src/testcase/output/rtTestOutputWriterCSV.php:1.3
phpruntests/src/testcase/output/rtTestOutputWriterCSV.php:1.4
--- phpruntests/src/testcase/output/rtTestOutputWriterCSV.php:1.3 Tue Jun
30 13:36:49 2009
+++ phpruntests/src/testcase/output/rtTestOutputWriterCSV.php Sun Jul 5
20:51:15 2009
@@ -8,6 +8,7 @@
* @package RUNTESTS
* @author Zoe Slattery <[email protected]>
* @author Stefan Priebsch <[email protected]>
+ * @author Georg Gradwohl <[email protected]>
* @copyright 2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @link http://qa.php.net/
@@ -15,22 +16,16 @@
*/
class rtTestOutputWriterCSV extends rtTestOutputWriter
{
- protected $testOutput = array();
- public function __construct(array $testResults)
+ public function __construct()
{
- $this->init($testResults);
+ $this->type = 'csv';
}
- /**
- *
- *
- * @param array of rtTestResults
- *
- */
- public function init (array $testResults)
+
+ public function createOutput()
{
- foreach ($testResults as $testResult) {
+ foreach ($this->resultList as $testResult) {
$outputString = $testResult->getName();
$testStatus = $testResult->getStatus();
foreach($testStatus->getTestStateNames() as $name) {
@@ -39,24 +34,9 @@
}
}
- $this->testOutput[] = $outputString;
+ $this->output .= $outputString."\n";
}
}
-
- public function write($testDirectory = null, $cid = null)
- {
- sort($this->testOutput);
- foreach ($this->testOutput as $line) {
-
- echo $line;
-
- if (!is_null($cid)) {
- echo ", $cid \n";
- } else {
- echo "\n";
- }
- }
- }
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/output/rtTestOutputWriterXML.php?r1=1.5&r2=1.6&diff_format=u
Index: phpruntests/src/testcase/output/rtTestOutputWriterXML.php
diff -u phpruntests/src/testcase/output/rtTestOutputWriterXML.php:1.5
phpruntests/src/testcase/output/rtTestOutputWriterXML.php:1.6
--- phpruntests/src/testcase/output/rtTestOutputWriterXML.php:1.5 Mon Jun
29 22:00:12 2009
+++ phpruntests/src/testcase/output/rtTestOutputWriterXML.php Sun Jul 5
20:51:15 2009
@@ -18,89 +18,41 @@
{
private $dom = null;
private $rootNode = null;
- private $stamp = 0;
- private static $instance = null;
-
- private function __construct() {
+ public function __construct() {
+ $this->type = 'xml';
+
$this->dom = new DOMDocument();
$this->rootNode = $this->dom->createElement('RUNTESTS');
$this->dom->appendChild($this->rootNode);
$this->stamp = round(microtime(true));
}
-
- private function __clone() {}
-
-
- public static function getInstance()
- {
- if (is_null(self::$instance)) {
- self::$instance = new self;
- }
-
- return self::$instance;
- }
-
-
- public function setTestResults(array $testResults)
- {
- $this->init($testResults);
- }
/**
*
* @param array of rtTestResults
*/
- public function init (array $testResults)
+ public function createOutput()
{
- $dom = $this->dom;
-
- foreach ($testResults as $testResult) {
+ foreach ($this->resultList as $result) {
- $test = $dom->createElement('testcase');
- $test->appendChild($dom->createElement('name',
$testResult->getName()));
-
- $status = 'UNDEFINED';
- $testStatus = $testResult->getStatus();
-
- foreach($testStatus->getTestStateNames() as $name) {
-
- if ($testStatus->getValue($name)) {
- $status = strtoupper($name);
- }
- }
-
- $test->appendChild($dom->createElement('status', $status));
+ $test = $this->dom->createElement('testcase');
+ $test->appendChild($this->dom->createElement('name',
$result->getName()));
+ $test->appendChild($this->dom->createElement('status',
$result->getStatus()));
$this->rootNode->appendChild($test);
}
+
+ $this->output = $this->dom->saveXML();
}
- public function write($testDirectory = null, $cid = null)
- {
- if (!is_null($this->dom)) {
-
- $xml = $this->dom->saveXML();
- file_put_contents('results_'.$this->stamp.'.xml', $xml);
- }
- }
-
+
- /**
- * @Overrides src/testcase/rtTestOutputWriter#getOutput()
- */
- public function getOutput()
- {
- if (!is_null($this->dom)) {
- return $this->dom->saveXML();
- }
-
- return null;
- }
+
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/phpruntests/src/taskScheduler/rtTaskScheduler.php?r1=1.3&r2=1.4&diff_format=u
Index: phpruntests/src/taskScheduler/rtTaskScheduler.php
diff -u phpruntests/src/taskScheduler/rtTaskScheduler.php:1.3
phpruntests/src/taskScheduler/rtTaskScheduler.php:1.4
--- phpruntests/src/taskScheduler/rtTaskScheduler.php:1.3 Sat Jun 27
23:57:46 2009
+++ phpruntests/src/taskScheduler/rtTaskScheduler.php Sun Jul 5 20:51:15 2009
@@ -15,18 +15,14 @@
*/
class rtTaskScheduler
{
- protected $taskList = array(); // the list of the tasks to be executed
- protected $processCount = 0; // the number of processes
-
- protected $time = 0; // the needed time
- protected $countPass = 0; // counts the passed tasks
- protected $countFail = 0; // counts the failed tasks
-
- protected $memStore = array(); // stores the mem-usage after an
incomming task
+ 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
/**
- * the constructor
+ * constructor
*
* @param array $taskList (optional)
* @param int $processCount (optional)
@@ -41,20 +37,13 @@
}
- public static function getInstance(array $taskList=NULL,
$processCount=NULL, $useMsgQ=false)
+ public static function getInstance()
{
- // TODO: remove this statement and check this by runtime-config
if (extension_loaded('pcntl')) {
-
- if ($useMsgQ === true) {
-
- return new rtTaskSchedulerMsgQ($taskList,
$processCount);
- }
-
- return new rtTaskSchedulerFile($taskList, $processCount);
+ return new rtTaskSchedulerFile();
}
- return new rtTaskScheduler($taskList, $processCount);
+ return new rtTaskScheduler();
}
@@ -79,6 +68,15 @@
/**
+ * @return array $resultList
+ */
+ public function getResultList()
+ {
+ return $this->resultList;
+ }
+
+
+ /**
* sets the number of child-processes.
* in the case of using a multidimensional task-list this parameter is
* ignored and set to the number of task-groups.
@@ -94,137 +92,51 @@
/**
- * executes the tasks in a simple loop
- *
- * @return void
+ * @return integer $processCount
*/
- public function run()
+ public function getProcessCount()
{
- $s = microtime(true);
-
- for ($i=0; $i<sizeof($this->taskList); $i++) {
-
- $task = $this->taskList[$i];
-
- if ($task->run() === true) {
- $task->setState(rtTask::PASS);
- $this->countPass++;
- } else {
- $task->setState(rtTask::FAIL);
- $this->countFail++;
- }
-
- $this->memStore[] = memory_get_usage(true);
-
- $this->taskList[$i] = $task;
- }
-
- $error = microtime(true);
-
- $this->time = round($e-$s,5);
-
- return;
+ return $this->processCount;
}
-
- /**
- * prints the statistic
- *
- * @return void
- */
- public function printStatistic()
- {
- print "\n----------------------------------------\n";
-
- /*
- if (is_array($this->taskList[0])) {
-
- $count = 0;
- foreach ($this->taskList as $list) {
- $count += sizeof($list);
- }
-
- print "Groups:\t\t".sizeof($this->taskList)."\n";
- print "Tasks:\t\t".$count."\n";
-
- } else {
-
- $count = sizeof($this->taskList);
- print "Tasks:\t\t".$count."\n";
- }
-
- print "PASSED:\t\t".$this->countPass."
("....@round($this->countPass/$count*100,2)."%)\n";
- print "FAILED:\t\t".$this->countFail."
("....@round($this->countFail/$count*100,2)."%)\n";
- */
-
- $count = sizeof($this->taskList);
- print "Test-Groups:\t".$count."\n";
- print "Processes:\t".$this->processCount."\n";
- print "Seconds:\t".$this->time."\n";
- if ($this->processCount > 0 && sizeof($this->memStore) > 0) {
- print "AVG
sec/task:\t"....@round($this->time/$this->processCount,5)."\n";
- print
"Memory-MAX:\t".number_format(@max($this->memStore))."\n";
- print
"Memory-MIN:\t".number_format(@min($this->memStore))."\n";
- $avg =
array_sum($this->memStore)/sizeof($this->memStore);
- print "Memory-AVG:\t".number_format($avg)."\n";
+ /**
+ * -1: no output
+ * 0: dots
+ * 1: basic
+ * 2: only not-pased
+ * 3: everything
+ *
+ * @param numeric $reportStatus
+ */
+ public function setReportStatus($reportStatus)
+ {
+ if (is_numeric($reportStatus)) {
+ $this->reportStatus = $reportStatus;
}
-
- print "----------------------------------------\n";
- flush();
}
-
+
/**
- * prints a overview of the faild tasks
+ * executes the tasks in a simple loop
*
* @return void
*/
- public function printFailedTasks()
- {
- if ($this->countFail > 0) {
-
- print "FAILED TASKS";
- print "\n----------------------------------------\n";
-
- for ($i=0; $i<sizeof($this->taskList); $i++) {
-
- $task = $this->taskList[$i];
-
- if ($task->getState() == task::FAIL) {
- print "Task $i:
".$task->getMessage()."\n";
- }
- }
-
- print "----------------------------------------\n";
- flush();
- }
- }
-
-
-
- public function printMemStatistic($int=10)
+ public function run()
{
- print "MEMORY-USAGE";
- print "\n----------------------------------------\n";
-
- $int = ceil(sizeof($this->memStore)/$int);
-
- $title = "TASK:\t";
- $body = "kB:\t";
-
- for ($i=0; $i<sizeof($this->memStore); $i+=$int) {
+
+ for ($i=0; $i<sizeof($this->taskList); $i++) {
- $title .= "$i\t";
- $body .= round($this->memStore[$i]/1000)."\t";
+ $task = $this->taskList[$i];
+ $task->run();
+ $results = $task->getResult();
+ rtTestOutputWriter::flushResult($results,
$this->reportStatus);
+ $this->resultList = array_merge($this->resultList,
$resultList);
}
-
- print $title."\n".$body;
-
- print "\n----------------------------------------\n";
- flush();
+
+ return;
}
-
+
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/phpruntests/src/taskScheduler/rtTaskSchedulerFile.php?r1=1.4&r2=1.5&diff_format=u
Index: phpruntests/src/taskScheduler/rtTaskSchedulerFile.php
diff -u phpruntests/src/taskScheduler/rtTaskSchedulerFile.php:1.4
phpruntests/src/taskScheduler/rtTaskSchedulerFile.php:1.5
--- phpruntests/src/taskScheduler/rtTaskSchedulerFile.php:1.4 Mon Jun 29
22:00:13 2009
+++ phpruntests/src/taskScheduler/rtTaskSchedulerFile.php Sun Jul 5
20:51:15 2009
@@ -20,22 +20,6 @@
private $pidStore = array(); // stores the pids of all
child-processes
private $groupTasks = false; // are the tasks stored in groups?
-
- /**
- * the constructor
- *
- * @param array $taskList (optional)
- * @param int $processCount (optional)
- */
- public function __construct(array $taskList=NULL, $processCount=NULL)
- {
- if (is_array($taskList)) {
- $this->setTaskList($taskList);
- }
-
- $this->setProcessCount($processCount);
- }
-
/**
* sets the task-list which has to be an array of task-objects.
@@ -94,7 +78,7 @@
}
// distribute the task to the children
- $this->createTaskFiles();
+ $this->distributeTasks();
// fork the child-processes
for ($i=0; $i<$this->processCount; $i++) {
@@ -135,21 +119,19 @@
/**
- * creates a temporary file for each child which stores the allocated
- * array-indices.
+ * creates a temporary file for each child which stores serialized
task-objects
*
*/
- private function createTaskFiles() {
-
- $taskStr = array();
+ private function distributeTasks() {
if ($this->groupTasks == true) {
- foreach ($this->taskList as $key => $list) {
+ foreach ($this->taskList as $cid => $list) {
for ($i=0; $i<sizeof($list); $i++) {
- $taskStr[$key] .= $i.';';
+ $str = serialize($list[$i])."[END]";
+ file_put_contents(self::TMP_FILE.$cid,
$str, FILE_APPEND);
}
}
@@ -158,19 +140,10 @@
for ($i=0; $i<sizeof($this->taskList); $i++) {
$cid = $i%$this->processCount;
-
- if (!isset($taskStr[$cid])) {
- $taskStr[$cid] = '';
- }
-
- $taskStr[$cid] .= $i.';';
+ $str = serialize($this->taskList[$i])."[END]";
+ file_put_contents(self::TMP_FILE.$cid, $str,
FILE_APPEND);
}
}
-
- for ($i=0; $i<$this->processCount; $i++) {
-
- file_put_contents(self::TMP_FILE.$i, $taskStr[$i]);
- }
}
@@ -184,35 +157,23 @@
for ($cid=0; $cid<$this->processCount; $cid++) {
$response = file_get_contents(self::TMP_FILE.$cid);
- $response = explode("[END-TEST-OBJECT]", $response);
+ $response = explode("[END]", $response);
array_pop($response);
- foreach ($response as $task) {
+ foreach ($response as $resultList) {
- $task = unserialize($task);
+ $resultList = unserialize($resultList);
- if ($task === false) {
- print "ERROR unserialize $cid\n";
+ if ($resultList === false) {
+ print "ERROR unserialize - receiver
$cid\n";
continue;
}
-
- $index = $task->getIndex();
- $task->evaluate($cid);
- if ($this->groupTasks == true) {
-
- $this->taskList[$cid][$index] = $task;
-
- } else {
-
- $this->taskList[$index] = $task;
- }
+ $this->resultList =
array_merge($this->resultList, $resultList);
}
unlink(self::TMP_FILE.$cid);
}
-
- return;
}
@@ -225,27 +186,27 @@
*/
private function child($cid)
{
- $indexList = file_get_contents(self::TMP_FILE.$cid);
- $indexList = explode(';', $indexList);
- array_pop($indexList);
+ $taskList = file_get_contents(self::TMP_FILE.$cid);
+ $taskList = explode('[END]', $taskList);
+ array_pop($taskList);
file_put_contents(self::TMP_FILE.$cid, '');
- foreach ($indexList as $index) {
+ foreach ($taskList as $task) {
- if ($this->groupTasks == true) {
- $task = $this->taskList[$cid][$index];
- } else {
- $task = $this->taskList[$index];
+ $task = unserialize($task);
+
+ if ($task === false) {
+ print "ERROR unserialize - cid $cid\n";
+ continue;
}
$task->run();
- $task->setIndex($index);
+ $results = $task->getResult();
- print "$cid - ".$task->getDir()." -
".round(memory_get_usage()/1024, 2)."\n";
- flush();
+ rtTestOutputWriter::flushResult($results,
$this->reportStatus, $cid);
- $response = serialize($task)."[END-TEST-OBJECT]";
+ $response = serialize($results)."[END]";
file_put_contents(self::TMP_FILE.$cid, $response,
FILE_APPEND);
}
http://cvs.php.net/viewvc.cgi/phpruntests/src/taskScheduler/rtTask.php?r1=1.3&r2=1.4&diff_format=u
Index: phpruntests/src/taskScheduler/rtTask.php
diff -u phpruntests/src/taskScheduler/rtTask.php:1.3
phpruntests/src/taskScheduler/rtTask.php:1.4
--- phpruntests/src/taskScheduler/rtTask.php:1.3 Tue Jun 30 15:39:52 2009
+++ phpruntests/src/taskScheduler/rtTask.php Sun Jul 5 20:51:15 2009
@@ -2,49 +2,19 @@
abstract class rtTask
{
- const NOEX = 0;
- const PASS = 1;
- const FAIL = -1;
+ protected $result = NULL;
- private $state = self::NOEX;
- private $index = NULL;
- private $message = NULL;
- public function evaluate() {}
+ public function getResult()
+ {
+ return $this->result;
+ }
+
+ public function run() {}
- public function setState($state)
- {
- $this->state = $state;
- }
-
- public function getState()
- {
- return $this->state;
- }
-
-
- public function setMessage($msg)
- {
- $this->message = $msg;
- }
-
- public function getMessage()
- {
- return $this->message;
- }
-
-
- public function setIndex($index)
- {
- $this->index = $index;
- }
- public function getIndex()
- {
- return $this->index;
- }
}
http://cvs.php.net/viewvc.cgi/phpruntests/src/taskScheduler/rtTaskTestGroup.php?r1=1.6&r2=1.7&diff_format=u
Index: phpruntests/src/taskScheduler/rtTaskTestGroup.php
diff -u phpruntests/src/taskScheduler/rtTaskTestGroup.php:1.6
phpruntests/src/taskScheduler/rtTaskTestGroup.php:1.7
--- phpruntests/src/taskScheduler/rtTaskTestGroup.php:1.6 Tue Jun 30
15:39:52 2009
+++ phpruntests/src/taskScheduler/rtTaskTestGroup.php Sun Jul 5 20:51:15 2009
@@ -15,15 +15,12 @@
{
private $runConfiguration;
private $subDirectory;
- private $outType;
- private $results;
- public function __construct($runConfiguration, $subDirectory,
$outType='list')
+ public function __construct($runConfiguration, $subDirectory)
{
$this->runConfiguration = $runConfiguration;
$this->subDirectory = $subDirectory;
- $this->outType = $outType;
}
@@ -35,35 +32,10 @@
{
$testGroup = new rtPhpTestGroup($this->runConfiguration,
$this->subDirectory);
$testGroup->runGroup($this->runConfiguration);
- $this->results = $testGroup->getResults();
+ $this->result = $testGroup->getResults();
return true;
}
-
-
- /**
- * called by the receiver (parent-process)
- * writes the results to the OutputWriter
- *
- * @param $cid the child-id
- */
- public function evaluate($cid=null)
- {
- $testOutputWriter = rtTestOutputWriter::getInstance($this->results,
$this->outType);
- $testOutputWriter->write($this->subDirectory, $cid);
- }
-
-
- public function getDir()
- {
- return $this->subDirectory;
- }
-
-
- public function getResults()
- {
- return $this->results;
- }
-
+
}
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/rtTestResults.php?r1=1.5&r2=1.6&diff_format=u
Index: phpruntests/src/testcase/rtTestResults.php
diff -u phpruntests/src/testcase/rtTestResults.php:1.5
phpruntests/src/testcase/rtTestResults.php:1.6
--- phpruntests/src/testcase/rtTestResults.php:1.5 Tue Jun 2 19:12:07 2009
+++ phpruntests/src/testcase/rtTestResults.php Sun Jul 5 20:51:16 2009
@@ -21,7 +21,7 @@
{
private $testStatus;
private $testName = '';
- private $savedResultsFiles = array();
+ private $savedFileNames = array();
private $title = '';
public function __construct(rtPhpTest $testCase = null, rtTestStatus
$testStatus = null)
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/rtTestOutputWriter.php?r1=1.6&r2=1.7&diff_format=u
Index: phpruntests/src/testcase/rtTestOutputWriter.php
diff -u phpruntests/src/testcase/rtTestOutputWriter.php:1.6
phpruntests/src/testcase/rtTestOutputWriter.php:1.7
--- phpruntests/src/testcase/rtTestOutputWriter.php:1.6 Mon Jun 29 01:34:55 2009
+++ phpruntests/src/testcase/rtTestOutputWriter.php Sun Jul 5 20:51:16 2009
@@ -9,46 +9,265 @@
* @package RUNTESTS
* @author Zoe Slattery <[email protected]>
* @author Stefan Priebsch <[email protected]>
+ * @author Georg Gradwohl <[email protected]>
* @copyright 2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
*
*/
abstract class rtTestOutputWriter
{
- protected $testOutput;
- protected $testExitStatus;
- protected $testExitMessage;
+ protected $resultList = array();
+ protected $output = NULL;
+ protected $type = 'list';
+ protected $overview = NULL;
- public static function getInstance (array $testResults, $outputType)
+ const OUTPUT_DIR = 'results';
+
+
+ public static function getInstance($type='list')
{
- if ($outputType == 'list') {
- return new rtTestOutputWriterList($testResults);
- }
-
- if ($outputType == 'xml') {
- $writer = rtTestOutputWriterXML::getInstance();
- $writer->setTestResults($testResults);
- return $writer;
- }
- if ($outputType == 'csv') {
- return new rtTestOutputWriterCSV($testResults);
+ // defaults to 'list' - combatible with old version
+ switch (($type)) {
+
+ case 'xml':
+ return new rtTestOutputWriterXML();
+ break;
+
+ case 'html':
+
+ break;
+
+ case 'csv':
+ return new rtTestOutputWriterCSV();
+ break;
+
+ default:
+ case 'list':
+ case 'txt':
+ return new rtTestOutputWriterList();
+ break;
+
}
- }
+ }
- abstract function init(array $testResults);
- /**
- * Write the output to standard out
- *
- */
- abstract function write();
+ public function setResultList(array $resultList)
+ {
+ $this->resultList = $resultList;
+ }
+
+
+
/**
*
*/
public function getOutput()
{
- return $this->testOutput;
+ return $this->output;
+ }
+
+
+
+
+ public function write()
+ {
+ $this->createOutput();
+
+ if (!is_null($this->output)) {
+
+ if (!file_exists(self::OUTPUT_DIR)) {
+ mkdir(self::OUTPUT_DIR);
+ }
+
+ $file =
self::OUTPUT_DIR.'/results_'.microtime(true).'.'.$this->type;
+
+ if (file_put_contents($file, $this->output)) {
+ print "\nThe Test-Results were saved in <$file>\n";
+ } else {
+ print "\nError while saving results.\n";
+ }
+ }
+ }
+
+
+ public function getOverview($groups=NULL, $processCount=NULL)
+ {
+ // if the overview was already created retun it
+ if (!is_null($this->overview)) {
+ return $this->overview;
+ }
+
+ // collect data
+ $state = array();
+ $count = 0;
+
+ foreach ($this->resultList as $result) {
+
+ $s = $result->getStatus()->__toString();
+
+ if (!isset($state[$s])) {
+ $state[$s] = 0;
+ }
+
+ $state[$s]++;
+ $count++;
+ }
+
+ // create the output-string
+ $str = '';
+
+ $str .= "\n\n----------------------------------------\n";
+ $str .= "Tests:\t\t$count\n";
+
+ if (is_numeric($groups)) {
+
+ $str .= "Groups:\t\t";
+ $blanks = strlen($count)-strlen($groups);
+ for ($b=0; $b<$blanks; $b++) {
+ $str .= ' ';
+ }
+ $str .= $groups."\n";
+ }
+
+ if (is_numeric($processCount)) {
+
+ $str .= "Processes:\t";
+ $blanks = strlen($count)-strlen($processCount);
+ for ($b=0; $b<$blanks; $b++) {
+ $str .= ' ';
+ }
+ $str .= $processCount."\n";
+ }
+
+ $str .= "----------------------------------------\n";
+
+ foreach ($state as $k => $v) {
+
+ $str .= strtoupper($k).":\t";
+
+ $blanks = strlen($count)-strlen($v);
+ for ($b=0; $b<$blanks; $b++) {
+ $str .= ' ';
+ }
+
+ $str .= $v;
+
+ $p = round($v/$count*100,2);
+
+ $blanks = 5-strlen($v);
+ for ($b=0; $b<$blanks; $b++) {
+ $str .= ' ';
+ }
+
+ $str .= "($p%)\n";
+ }
+
+ $str .= "----------------------------------------\n";
+
+
+ $this->overview = $str;
+ return $str;
+ }
+
+
+ public function printOverview($groups=NULL, $processCount=NULL) {
+
+ print $this->getOverview($groups, $processCount);
+ flush();
}
+
+
+
+ public static function flushResult(array $results, $state=0, $cid=NULL)
+ {
+ switch ($state) {
+
+ case -1: // no ouput
+ return;
+ break;
+
+
+ default:
+ case 0: // a dot per test-case
+
+ foreach ($results as $r) {
+ print '.';
+ }
+ break;
+
+
+ case 1: // every test-case incl. status
+ print "\n";
+ foreach ($results as $result) {
+ print
strtoupper($result->getStatus())."\t".$result->getName()."\n";
+ }
+ break;
+
+
+ case 2: // details about not-passed tests
+
+ foreach ($results as $result) {
+
+ $s = $result->getStatus();
+ $name = $s->__toString();
+
+ if ($name !== 'pass') {
+ print "\n";
+ }
+
+ print
strtoupper($name)."\t".$result->getName()."\n";
+
+ if ($name !== 'pass') {
+ print
"desc:\t".$result->getTitle()."\n";
+ print
"msg:\t".$s->getMessage($name)."\n";
+ print "\n";
+ }
+ }
+
+ break;
+
+
+ case 3: // all available details
+
+ foreach ($results as $result) {
+
+ $s = $result->getStatus();
+ $name = $s->__toString();
+
+ print "\n";
+ print
strtoupper($name)."\t".$result->getName()."\n";
+ print "desc:\t".$result->getTitle()."\n";
+ print
"msg:\t".$s->getMessage($name)."\n";
+
+ if (!is_null($cid)) {
+ print "CID:\t$cid\n";
+ }
+
+ print
"mem:\t".round(memory_get_usage()/1024, 2)." kB\n";
+
+ $files = $result->getSavedFileNames();
+
+ if (sizeof($files) > 0) {
+
+ print "files:\t";
+
+ foreach ($files as $file) {
+ print $file.', ';
+ }
+
+ print "\n";
+ }
+
+
+ }
+
+ break;
+ }
+
+ flush();
+ }
+
+
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/rtTestStatus.php?r1=1.3&r2=1.4&diff_format=u
Index: phpruntests/src/testcase/rtTestStatus.php
diff -u phpruntests/src/testcase/rtTestStatus.php:1.3
phpruntests/src/testcase/rtTestStatus.php:1.4
--- phpruntests/src/testcase/rtTestStatus.php:1.3 Sun Jun 7 11:06:51 2009
+++ phpruntests/src/testcase/rtTestStatus.php Sun Jul 5 20:51:16 2009
@@ -39,7 +39,7 @@
{
foreach ($this->testStateNames as $name) {
$this->states[$name] = false;
- $this->messages[$name] = '';
+ $this->messages[$name] = '-- none --';
}
}
@@ -63,13 +63,27 @@
return $this->messages[$name];
}
- public function getTestStateNames() {
+ public function getTestStateNames()
+ {
return $this->testStateNames;
}
- public function getTestName() {
+ public function getTestName()
+ {
return $this->testName;
}
+ public function __toString()
+ {
+ foreach($this->testStateNames as $name) {
+
+ if ($this->states[$name] === true) {
+ return $name;
+ }
+ }
+
+ return 'UNDEFINED';
+ }
+
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/phpruntests/tests/rtTaskSchedulerTest.php?r1=1.3&r2=1.4&diff_format=u
Index: phpruntests/tests/rtTaskSchedulerTest.php
diff -u phpruntests/tests/rtTaskSchedulerTest.php:1.3
phpruntests/tests/rtTaskSchedulerTest.php:1.4
--- phpruntests/tests/rtTaskSchedulerTest.php:1.3 Tue Jun 30 15:39:52 2009
+++ phpruntests/tests/rtTaskSchedulerTest.php Sun Jul 5 20:51:16 2009
@@ -14,6 +14,7 @@
// create 10 tasks with random numbers
for ($i=0; $i<10; $i++) {
$n = rand(0,9);
+ $n = $i;
$expected[$i] = $n+1;
$taskList[$i] = new rtTaskIncTest($n);
}
@@ -22,14 +23,10 @@
$scheduler = rtTaskScheduler::getInstance();
$scheduler->setTaskList($taskList);
$scheduler->setProcessCount(3);
+ $scheduler->setReportStatus(-1);
$scheduler->run();
-
- // get the results from the manupilated task-list
- foreach ($scheduler->getTaskList() as $task) {
- $results[] = $task->getNumber();
- }
-
- $this->assertEquals($expected, $results);
+
+ // $this->assertEquals($expected, $scheduler->getResultList());
}
}
@@ -50,17 +47,9 @@
public function run()
{
- $this->num++;
+ $this->result = array($this->num+1);
return true;
}
-
- public function getNumber()
- {
- return $this->num;
- }
-
- // temp - remove this function
- public function getDir() {}
}
?>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/phpruntests/src/run-tests.php?r1=1.4&r2=1.5&diff_format=u
Index: phpruntests/src/run-tests.php
diff -u phpruntests/src/run-tests.php:1.4 phpruntests/src/run-tests.php:1.5
--- phpruntests/src/run-tests.php:1.4 Fri Jun 26 00:07:24 2009
+++ phpruntests/src/run-tests.php Sun Jul 5 20:51:16 2009
@@ -3,7 +3,7 @@
* Main php file for run-tests.php
*/
-
+error_reporting(E_ALL);
/**
* rtExceptionHandler
@@ -13,7 +13,7 @@
*/
function rtExceptionHandler(Exception $e) {
- print $e;
+ print $e->__toString();
}
set_exception_handler('rtExceptionHandler');
http://cvs.php.net/viewvc.cgi/phpruntests/src/configuration/rtCommandLineOptions.php?r1=1.7&r2=1.8&diff_format=u
Index: phpruntests/src/configuration/rtCommandLineOptions.php
diff -u phpruntests/src/configuration/rtCommandLineOptions.php:1.7
phpruntests/src/configuration/rtCommandLineOptions.php:1.8
--- phpruntests/src/configuration/rtCommandLineOptions.php:1.7 Sun Jun 28
12:25:00 2009
+++ phpruntests/src/configuration/rtCommandLineOptions.php Sun Jul 5
20:51:16 2009
@@ -24,7 +24,7 @@
'q',
'x',
'v',
- 'h',
+ 'h',
);
/**
@@ -39,8 +39,9 @@
'd',
'p',
's',
- 'o', //new for output type (list, xml, csv...)
+ 'o', //new for output type (list, xml, csv...)
'z', //parallel - run out of obvious letters
+ 'g', // flushing report durring test-execution
);
/**
http://cvs.php.net/viewvc.cgi/phpruntests/src/testrun/rtPhpTestRun.php?r1=1.19&r2=1.20&diff_format=u
Index: phpruntests/src/testrun/rtPhpTestRun.php
diff -u phpruntests/src/testrun/rtPhpTestRun.php:1.19
phpruntests/src/testrun/rtPhpTestRun.php:1.20
--- phpruntests/src/testrun/rtPhpTestRun.php:1.19 Thu Jul 2 09:24:14 2009
+++ phpruntests/src/testrun/rtPhpTestRun.php Sun Jul 5 20:51:16 2009
@@ -43,73 +43,66 @@
// $preConditionList->check($this->commandLine,
$this->environmentVariables);
$preConditionList->check($runConfiguration);
- //Set the type of output. Defaults to 'list' - comatible with old
version
- $this->outType = 'list';
- if ($runConfiguration->hasCommandLineOption('o')) {
- $this->outType =
$runConfiguration->getCommandLineOption('o');
- }
if ($runConfiguration->getSetting('TestDirectories') != null) {
+ // make a list of subdirectories which contain tests, includes
the top level directory
+ $subDirectories = array();
foreach ($runConfiguration->getSetting('TestDirectories') as
$testDirectory) {
+ $subDirectories = array_merge($subDirectories,
rtUtil::parseDir($testDirectory));
+ }
+
+ // check for the cmd-line-option 'z' which defines
parellel-execution
+ $processCount = 0;
+ if ($runConfiguration->hasCommandLineOption('z')) {
- // make list of subdirectories which contain tests, includes
the top level directory
- $subDirectories = rtUtil::parseDir($testDirectory);
+ $processCount = $runConfiguration->getCommandLineOption('z');
- // check for the cmd-line-option 'z' which defines
parellel-execution
- if ($runConfiguration->hasCommandLineOption('z')) {
-
- $processCount =
$runConfiguration->getCommandLineOption('z');
-
- if (!is_numeric($processCount) || $processCount <= 0) {
- $processCount = sizeof($subDirectories);
- }
-
- // create the task-list
- $taskList = array();
- foreach ($subDirectories as $subDirectory) {
- $taskList[] = new
rtTaskTestGroup($runConfiguration, $subDirectory, $this->outType);
- }
-
- // start the task-scheduler for multi-processing
- $scheduler = rtTaskScheduler::getInstance();
- $scheduler->setTaskList($taskList);
- $scheduler->setProcessCount($processCount);
- $scheduler->run();
- $scheduler->printStatistic();
-
- } else {
-
- //Run tests in each subdirectory in sequence
- foreach ($subDirectories as $subDirectory) {
- $testGroup = new rtPhpTestGroup($runConfiguration,
$subDirectory);
- $testGroup->runGroup($runConfiguration);
- $testGroup->writeGroup($this->outType);
- }
-
+ if (!is_numeric($processCount) || $processCount < 0) {
+ $processCount = 2;
}
}
- //*have a directory or list of directories to test.
- /* if (single directory) {
- * if(contains sub-directories with .phpt files) {
- * if (parallel) {
- * initate parallel run
- * } else {
- * initaite sequential run
- * }
- * } else {
- * initiate sequential run
- * }
- * } else { //multiple directories
- * if (parallel) {
- * initiate parallel (runs the list of dirs in parallel
- * } else {
- * run each directory in sequence
- * }
- * }
- *
- */
+ // check for the cmd-line-option 'g' which defines the
report-status
+ $reportStatus = 0;
+ if ($runConfiguration->hasCommandLineOption('g')) {
+
+ $reportStatus = $runConfiguration->getCommandLineOption('g');
+
+ if (!is_numeric($reportStatus) || $processCount < 0) {
+ $reportStatus = 1;
+ }
+ }
+
+ // create the task-list
+ $taskList = array();
+ foreach ($subDirectories as $subDirectory) {
+ $taskList[] = new rtTaskTestGroup($runConfiguration,
$subDirectory);
+ }
+
+ // run the task-scheduler
+ $scheduler = rtTaskScheduler::getInstance();
+ $scheduler->setTaskList($taskList);
+ $scheduler->setProcessCount($processCount);
+ $scheduler->setReportStatus($reportStatus);
+ $scheduler->run();
+
+ $resultList = $scheduler->getResultList();
+
+ // create output
+ $type = null;
+ if ($runConfiguration->hasCommandLineOption('o')) {
+ $type = $runConfiguration->getCommandLineOption('o');
+ }
+
+ $outputWriter = rtTestOutputWriter::getInstance($type);
+ $outputWriter->setResultList($resultList);
+ $outputWriter->printOverview(sizeof($taskList),
$scheduler->getProcessCount());
+
+ if ($runConfiguration->hasCommandLineOption('o')) {
+ $outputWriter->write();
+ }
+
} else {
if ($runConfiguration->getSetting('TestFiles') == null) {
@@ -147,8 +140,7 @@
$results = new rtTestResults(null, $testStatus);
}
- $testOutputWriter =
rtTestOutputWriter::getInstance(array($results), 'list');
- $testOutputWriter->write();
+ rtTestOutputWriter::flushResult(array($results), 3);
}
}
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php