Author: Marcin.Chylek
Date: 2010-04-21 16:29:25 +0200 (Wed, 21 Apr 2010)
New Revision: 29228
Modified:
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php
Log:
Add exit status to detect failed builds and explode assert functional tests
Modified:
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php
===================================================================
---
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php
2010-04-21 14:25:11 UTC (rev 29227)
+++
plugins/symfonyUnderControlPlugin/trunk/lib/SymfonyUnderControlTest.class.php
2010-04-21 14:29:25 UTC (rev 29228)
@@ -5,7 +5,7 @@
/**
* Class representing a single test file.
- *
+ *
* @package symfonyUnderControlPlugin
* @author Stefan Koopmanschap <[email protected]>
*
@@ -19,10 +19,10 @@
const RETURN_STATUS = 5;
const COMMENT = 6;
const UNKNOWN = 0;
-
+
const TEST_UNIT = 'Unit';
const TEST_FUNC = 'Functional';
-
+
protected $filename;
protected $lib_file;
protected $php_cli;
@@ -35,7 +35,7 @@
protected $time_spent;
protected $type;
protected $coverage;
-
+
/**
* Constructor for a test
*
@@ -47,7 +47,7 @@
$this->php_cli = $this->find_php_cli();
$this->type = $type;
}
-
+
/**
* Run this test
*
@@ -56,19 +56,23 @@
public function runTest($output)
{
$output->setTest($this);
-
+
ob_start();
$time_start = microtime(true);
passthru(sprintf('%s "%s" 2>&1', $this->php_cli, $this->filename),
$return);
$time_end = microtime(true);
$this->output = ob_get_contents();
ob_end_clean();
-
+
$this->time_spent = $time_end - $time_start;
-
+
$this->parseTestOutput();
+
+ // exit status helps to detect failed builds
+ if( strpos( $this->output, 'Failed test' ) !== false && strpos(
$this->output, 'not ok' ) !== false )
+ exit( 1 );
}
-
+
/**
* Run code coverage on this test
*
@@ -77,22 +81,22 @@
public function runCoverage($output)
{
$output->setTest($this);
-
+
$this->lib_file = $this->getLibraryFile();
// only run the test if the library file according to our logic exists
if (is_file($this->lib_file))
{
$test_command = sfConfig::get('sf_root_dir') . '/symfony test:coverage '
. $this->getRelativePath($this->filename) . ' ' .
$this->getRelativePath($this->lib_file);
-
+
ob_start();
passthru(sprintf('%s %s 2>&1', $this->php_cli, $test_command), $return);
$this->coverage_output = ob_get_contents();
ob_end_clean();
-
+
$this->parseCoverageOutput();
}
}
-
+
/**
* Getter for the test name
*
@@ -103,7 +107,7 @@
$pieces = explode('/', $this->filename);
return str_replace('.php', '', $pieces [count($pieces) - 1]);
}
-
+
/**
* Getter for the filename of this test
*
@@ -113,7 +117,7 @@
{
return $this->filename;
}
-
+
/**
* Get the number of assertions in this test
*
@@ -123,7 +127,7 @@
{
return count($this->asserts);
}
-
+
/**
* Get the number of failed assertions in this test
*
@@ -133,7 +137,7 @@
{
return $this->failed;
}
-
+
/**
* Get the assertion results
*
@@ -143,7 +147,7 @@
{
return $this->asserts;
}
-
+
/**
* Get the time spent to run the test
*
@@ -153,7 +157,7 @@
{
return $this->time_spent;
}
-
+
/**
* Get the type of test
*
@@ -163,7 +167,7 @@
{
return $this->type;
}
-
+
/**
* Get the coverage as gotten from the code coverage check
*
@@ -173,12 +177,12 @@
{
return $this->coverage;
}
-
+
public function getLibFile()
{
return $this->lib_file;
}
-
+
/**
* Parse the output of the test
*
@@ -191,7 +195,7 @@
$this->parseLine($line);
}
}
-
+
/**
* Parse the code coverage output of the test
*
@@ -208,7 +212,7 @@
}
}
}
-
+
/**
* Parse the specified line
*
@@ -230,7 +234,7 @@
$this->reportComment($line);
}
}
-
+
/**
* Fetch the assertion number from the given line
*
@@ -239,11 +243,17 @@
*/
protected function fetchAssertNumber($line)
{
- $line = trim($line);
- $last_space = strrpos($line, ' ');
- return (int) substr($line, $last_space + 1);
+ $line = trim($line);
+ $arrayLine = explode(' ', $line);
+
+ if($arrayLine[0] == 'ok')
+ $number = $arrayLine[1];
+ else
+ $number = $arrayLine[2];
+
+ return (int)$number;
}
-
+
/**
* Report a failed test into the assertion results
*
@@ -256,7 +266,7 @@
$this->asserts [$assert_number] ['status'] = false;
$this->failed ++;
}
-
+
/**
* Report a successful test into the assertion results
*
@@ -268,7 +278,7 @@
$this->asserts [$assert_number] = array();
$this->asserts [$assert_number] ['status'] = true;
}
-
+
/**
* Report a comment into the assertion results when necessary
*
@@ -285,12 +295,12 @@
$this->asserts [$this->current_assert] ['comment'] .= "\n" . $content;
}
}
-
+
/**
* Find the php CLI to use use for running the test
- *
+ *
* This method has been shamelessly copied from lime
- *
+ *
* @author Fabien Potencier <[email protected]>
* @return string
* @throws Exception
@@ -313,10 +323,10 @@
}
}
}
-
+
throw new Exception("Unable to find PHP executable.");
}
-
+
/**
* Get the library file path that is being tested (if existing)
*
@@ -332,7 +342,7 @@
return $result [0];
}
}
-
+
protected function getRelativePath($file)
{
return str_replace(sfConfig::get('sf_root_dir') . '/', '', $file);
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.