diff options
Diffstat (limited to 'buildscripts')
7 files changed, 318 insertions, 64 deletions
diff --git a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestFormatterElement.php b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestFormatterElement.php index fab27315..82bf5776 100644 --- a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestFormatterElement.php +++ b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestFormatterElement.php @@ -21,7 +21,7 @@ require_once 'phing/tasks/ext/simpletest/SimpleTestPlainResultFormatter.php';
require_once 'phing/tasks/ext/simpletest/SimpleTestSummaryResultFormatter.php';
-require_once 'phing/tasks/ext/phpunit2/FormatterElement.php';
+require_once 'phing/tasks/ext/simpletest/SimpleTestXmlResultFormatter.php';
/**
* Child class of "FormatterElement", overrides setType to provide other
@@ -32,16 +32,26 @@ require_once 'phing/tasks/ext/phpunit2/FormatterElement.php'; * @package phing.tasks.ext.simpletest
* @since 2.2.0
*/
-class SimpleTestFormatterElement extends FormatterElement
+class SimpleTestFormatterElement
{
+ protected $formatter = NULL;
+
+ protected $type = "";
+
+ protected $useFile = true;
+
+ protected $toDir = ".";
+
+ protected $outfile = "";
+
function setType($type)
{
$this->type = $type;
if ($this->type == "xml")
{
- $destFile = new PhingFile($this->toDir, 'testsuites.xml');
- //$this->formatter = new SimpleTestXmlResultFormatter();
+ //$destFile = new PhingFile($this->toDir, 'testsuites.xml');
+ $this->formatter = new SimpleTestXmlResultFormatter();
}
else
if ($this->type == "plain")
@@ -58,5 +68,59 @@ class SimpleTestFormatterElement extends FormatterElement throw new BuildException("Formatter '" . $this->type . "' not implemented");
}
}
+
+ function setClassName($className)
+ {
+ $classNameNoDot = Phing::import($className);
+
+ $this->formatter = new $classNameNoDot();
+ }
+
+ function setUseFile($useFile)
+ {
+ $this->useFile = $useFile;
+ }
+
+ function getUseFile()
+ {
+ return $this->useFile;
+ }
+
+ function setToDir($toDir)
+ {
+ $this->toDir = $toDir;
+ }
+
+ function getToDir()
+ {
+ return $this->toDir;
+ }
+
+ function setOutfile($outfile)
+ {
+ $this->outfile = $outfile;
+ }
+
+ function getOutfile()
+ {
+ if ($this->outfile)
+ {
+ return $this->outfile;
+ }
+ else
+ {
+ return $this->formatter->getPreferredOutfile() . $this->getExtension();
+ }
+ }
+
+ function getExtension()
+ {
+ return $this->formatter->getExtension();
+ }
+
+ function getFormatter()
+ {
+ return $this->formatter;
+ }
}
?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestPlainResultFormatter.php b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestPlainResultFormatter.php index f84ca815..688e2fe6 100644 --- a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestPlainResultFormatter.php +++ b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestPlainResultFormatter.php @@ -32,12 +32,12 @@ require_once 'phing/tasks/ext/simpletest/SimpleTestResultFormatter.php'; class SimpleTestPlainResultFormatter extends SimpleTestResultFormatter
{
private $inner = "";
-
+
function getExtension()
{
return ".txt";
}
-
+
function getPreferredOutfile()
{
return "testresults";
@@ -46,18 +46,18 @@ class SimpleTestPlainResultFormatter extends SimpleTestResultFormatter function paintCaseStart($test_name)
{
parent::paintCaseStart($test_name);
-
+
$this->inner = "";
}
-
+
function paintCaseEnd($test_name)
{
parent::paintCaseEnd($test_name);
-
+
/* Only count suites where more than one test was run */
if ($this->getRunCount())
{
- $sb.= "Testsuite: $test_name\n";
+ $sb = "Testsuite: $test_name\n";
$sb.= "Tests run: " . $this->getRunCount();
$sb.= ", Failures: " . $this->getFailureCount();
$sb.= ", Errors: " . $this->getErrorCount();
@@ -75,21 +75,21 @@ class SimpleTestPlainResultFormatter extends SimpleTestResultFormatter function paintError($message)
{
parent::paintError($message);
-
+
$this->formatError("ERROR", $message);
}
function paintFail($message)
{
parent::paintFail($message);
-
+
$this->formatError("FAILED", $message);
}
private function formatError($type, $message)
{
$this->inner.= $this->getTestName() . " " . $type . "\n";
- $this->inner.= $message . "\n";
+ $this->inner.= $message . "\n";
}
}
?>
\ No newline at end of file diff --git a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestResultFormatter.php b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestResultFormatter.php index 7f94892f..4583cf27 100644 --- a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestResultFormatter.php +++ b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestResultFormatter.php @@ -19,7 +19,7 @@ * <http://phing.info>.
*/
-require_once 'simpletest/scorer.php';
+//require_once 'simpletest/scorer.php';
require_once 'phing/system/io/Writer.php';
@@ -34,25 +34,25 @@ require_once 'phing/system/io/Writer.php'; abstract class SimpleTestResultFormatter extends SimpleReporter
{
protected $out = NULL;
-
+
protected $project = NULL;
-
+
private $timer = NULL;
private $runCount = 0;
-
+
private $failureCount = 0;
-
- private $errorCount = 0;
+
+ private $errorCount = 0;
private $currentTest = "";
-
+
/**
* Sets the writer the formatter is supposed to write its results to.
*/
function setOutput(Writer $out)
{
- $this->out = $out;
+ $this->out = $out;
}
/**
@@ -74,56 +74,56 @@ abstract class SimpleTestResultFormatter extends SimpleReporter {
$this->project = $project;
}
-
+
function getPreferredOutfile()
{
return "";
}
-
+
function paintMethodStart($test_name)
{
parent::paintMethodStart($test_name);
-
+
$this->currentTest = $test_name;
}
-
+
function paintMethodEnd($test_name)
{
parent::paintMethodEnd($test_name);
-
+
$this->runCount++;
}
-
+
function paintCaseStart($test_name)
{
parent::paintCaseStart($test_name);
-
+
$this->runCount = 0;
$this->failureCount = 0;
$this->errorCount = 0;
-
+
$this->timer = new Timer();
$this->timer->start();
}
-
+
function paintCaseEnd($test_name)
{
parent::paintCaseEnd($test_name);
-
+
$this->timer->stop();
}
function paintError($message)
{
parent::paintError($message);
-
+
$this->errorCount++;
}
function paintFail($message)
{
parent::paintFail($message);
-
+
$this->failureCount++;
}
@@ -131,22 +131,22 @@ abstract class SimpleTestResultFormatter extends SimpleReporter {
return $this->runCount;
}
-
+
function getFailureCount()
{
return $this->failureCount;
}
-
+
function getErrorCount()
{
return $this->errorCount;
}
-
+
function getTestName()
{
return $this->currentTest;
}
-
+
function getElapsedTime()
{
if ($this->timer)
diff --git a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestSummaryResultFormatter.php b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestSummaryResultFormatter.php index 79494bc9..bd691374 100644 --- a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestSummaryResultFormatter.php +++ b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestSummaryResultFormatter.php @@ -34,11 +34,11 @@ class SimpleTestSummaryResultFormatter extends SimpleTestResultFormatter function paintCaseEnd($test_name)
{
parent::paintCaseEnd($test_name);
-
+
/* Only count suites where more than one test was run */
if ($this->getRunCount())
{
- $sb.= "Tests run: " . $this->getRunCount();
+ $sb= "Tests run: " . $this->getRunCount();
$sb.= ", Failures: " . $this->getFailureCount();
$sb.= ", Errors: " . $this->getErrorCount();
$sb.= ", Time elapsed: " . $this->getElapsedTime();
diff --git a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestTask.php b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestTask.php index 6aede68f..e32c31c6 100644 --- a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestTask.php +++ b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestTask.php @@ -41,6 +41,7 @@ class SimpleTestTask extends Task private $errorproperty; private $printsummary = false; private $testfailed = false; + private $filesets=array(); /** * Initialize Task. @@ -49,29 +50,24 @@ class SimpleTestTask extends Task * because we may want this class to be loaded w/o triggering an error. */ function init() { - @include_once 'simpletest/scorer.php'; - + if (!class_exists('SimpleReporter')) { throw new BuildException("SimpleTestTask depends on SimpleTest package being installed.", $this->getLocation()); } - - require_once 'simpletest/reporter.php'; - require_once 'simpletest/xml.php'; - require_once 'simpletest/test_case.php'; require_once 'phing/tasks/ext/simpletest/SimpleTestCountResultFormatter.php'; require_once 'phing/tasks/ext/simpletest/SimpleTestFormatterElement.php'; } - + function setFailureproperty($value) { $this->failureproperty = $value; } - + function setErrorproperty($value) { $this->errorproperty = $value; } - + function setHaltonerror($value) { $this->haltonerror = $value; @@ -86,7 +82,7 @@ class SimpleTestTask extends Task { $this->printsummary = $printsummary; } - + /** * Add a new formatter to all tests of this task. * @@ -144,14 +140,14 @@ class SimpleTestTask extends Task function main() { $group = new GroupTest(); - + $filenames = $this->getFilenames(); - + foreach ($filenames as $testfile) { $group->addTestFile($testfile); } - + if ($this->printsummary) { $fe = new SimpleTestFormatterElement(); @@ -159,7 +155,7 @@ class SimpleTestTask extends Task $fe->setUseFile(false); $this->formatters[] = $fe; } - + foreach ($this->formatters as $fe) { $formatter = $fe->getFormatter(); @@ -168,7 +164,7 @@ class SimpleTestTask extends Task if ($fe->getUseFile()) { $destFile = new PhingFile($fe->getToDir(), $fe->getOutfile()); - + $writer = new FileWriter($destFile->getAbsolutePath()); $formatter->setOutput($writer); @@ -178,39 +174,39 @@ class SimpleTestTask extends Task $formatter->setOutput($this->getDefaultOutput()); } } - + $this->execute($group); - + if ($this->testfailed) { throw new BuildException("One or more tests failed"); } } - + private function execute($suite) { $counter = new SimpleTestCountResultFormatter(); $reporter = new MultipleReporter(); $reporter->attachReporter($counter); - + foreach ($this->formatters as $fe) { $formatter = $fe->getFormatter(); $reporter->attachReporter($formatter); - } - + } + $suite->run($reporter); - + $retcode = $counter->getRetCode(); - + if ($retcode == SimpleTestCountResultFormatter::ERRORS) { if ($this->errorproperty) { $this->project->setNewProperty($this->errorproperty, true); } - + if ($this->haltonerror) { $this->testfailed = true; @@ -222,7 +218,7 @@ class SimpleTestTask extends Task { $this->project->setNewProperty($this->failureproperty, true); } - + if ($this->haltonfailure) { $this->testfailed = true; diff --git a/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestXmlResultFormatter.php b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestXmlResultFormatter.php new file mode 100644 index 00000000..66c4ccd8 --- /dev/null +++ b/buildscripts/phing/classes/phing/tasks/ext/simpletest/SimpleTestXmlResultFormatter.php @@ -0,0 +1,154 @@ +<?php +/** + * $Id: SimpleTestPlainResultFormatter.php 59 2006-04-28 14:49:47Z mrook $ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information please see + * <http://phing.info>. + */ + +require_once 'phing/tasks/ext/simpletest/SimpleTestResultFormatter.php'; + +/** + * Prints plain text output of the test to a specified Writer. + * + * @author Michiel Rook <michiel@trendserver.nl> + * @version $Id: SimpleTestPlainResultFormatter.php 59 2006-04-28 14:49:47Z mrook $ + * @package phing.tasks.ext.simpletest + * @since 2.2.0 + */ +class SimpleTestXmlResultFormatter extends SimpleTestResultFormatter +{ + private $results=array(); + private $currentSuite; + private $currentTest; + private $methodCounts=0; + private $methodTime=0; + + function paintFooter($test_name) + { + if($test_name=='GroupTest') + $this->printXml($test_name); + } + + protected function printXml($test_name) + { + $suites = $this->printXmlSuites($this->results); +$content = <<<EOD +<?xml version="1.0" encoding="UTF-8"?> +<testsuites total="{$this->getRunCount()}" name="{$test_name}"> +$suites +</testsuites> +EOD; + $this->out->write($content); + } + + protected function printXmlSuites($results) + { + $contents = ''; + foreach($results as $suiteName => $suite) + { + $tests = $this->printXmlTests($suite['tests'],$suiteName); +$contents .= <<<EOD +<testsuite name="{$suiteName}" tests="{$suite['total']}" failures="{$suite['failures']}" errors="{$suite['errors']}" time="{$suite['time']}"> + $tests +</testsuite> +EOD; + } + return $contents; + } + + protected function printXmlTests($tests,$suiteName) + { + $contents = ''; + foreach($tests as $name => $result) + { + if(count($result['results'])==0) + { + $contents .= <<<EOD +<testcase name="{$name}" class="{$suiteName}" result="success" time="{$result['time']}"/> +EOD; + } + else + { + $type = strtolower($result['results']['type']); + $message = htmlspecialchars($result['results']['message']); +$contents .= <<<EOD +<testcase name="{$name}" class="{$suiteName}" result="{$type}" time="{$result['time']}"> + <{$type}>$message</{$type}> +</testcase> +EOD; + } + } + return $contents; + } + + function paintCaseStart($test_name) + { + parent::paintCaseStart($test_name); + $this->results[$test_name] = array('tests'=>array()); + $this->currentSuite=$test_name; + $this->methodCounts=0; + } + + function paintCaseEnd($test_name) + { + parent::paintCaseEnd($test_name); + $details = array( + 'total' => $this->methodCounts, + 'failures' => $this->getFailureCount(), + 'errors' => $this->getErrorCount(), + 'time' => $this->getElapsedTime()); + + $this->results[$test_name] = array_merge($this->results[$test_name],$details); + } + + function paintMethodStart($test_name) + { + $this->currentTest=$test_name; + parent::paintMethodStart($test_name); + $this->results[$this->currentSuite]['tests'][$test_name]['results'] = array(); + $this->methodCounts++; + $this->methodTime = new Timer(); + $this->methodTime->start(); + } + + function paintMethodEnd($test_name) + { + parent::paintMethodEnd($test_name); + $this->methodTime->stop(); + $this->results[$this->currentSuite]['tests'][$test_name]['time'] = $this->methodTime->getElapsedTime(); + } + + function paintError($message) + { + parent::paintError($message); + $this->formatError("ERROR", $message); + } + + function paintFail($message) + { + parent::paintFail($message); + $this->formatError("FAILED", $message); + } + + private function formatError($type, $message) + { + $result = array('type'=>$type, 'message' => $message); + $this->results[$this->currentSuite]['tests'][$this->currentTest]['results'] = + $result; + } +} +?>
\ No newline at end of file diff --git a/buildscripts/phing/tasks/PradoSimpleTestTask.php b/buildscripts/phing/tasks/PradoSimpleTestTask.php new file mode 100644 index 00000000..4d6317b5 --- /dev/null +++ b/buildscripts/phing/tasks/PradoSimpleTestTask.php @@ -0,0 +1,40 @@ +<?php
+require_once 'phing/Task.php';
+require_once 'phing/tasks/ext/simpletest/SimpleTestTask.php';
+
+/**
+ * Task to run PRADO unit tests
+ */
+class PradoSimpleTestTask extends SimpleTestTask
+{
+ private $_appdir;
+
+ public function setAppdir($value)
+ {
+ $this->_appdir=$value;
+ }
+
+ function init()
+ {
+ $tools= realpath(dirname(__FILE__).'/../../../tests/test_tools/');
+ include_once "$tools/unit_tests.php";
+
+ if (!class_exists('SimpleReporter',false))
+ throw new BuildException("SimpleTestTask depends on SimpleTest package being installed.", $this->getLocation());
+
+ require_once 'phing/tasks/ext/simpletest/SimpleTestCountResultFormatter.php';
+ require_once 'phing/tasks/ext/simpletest/SimpleTestFormatterElement.php';
+ }
+
+ function main()
+ {
+ if($this->_appdir)
+ {
+ $app = new TShellApplication($this->_appdir);
+ $app->run();
+ }
+ parent::main();
+ }
+}
+
+?>
\ No newline at end of file |