summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gallery_unit_test/controllers/gallery_unit_test.php11
-rw-r--r--modules/unit_test/libraries/Unit_Test.php8
2 files changed, 17 insertions, 2 deletions
diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php
index 67d006b3..55d0abc1 100644
--- a/modules/gallery_unit_test/controllers/gallery_unit_test.php
+++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php
@@ -27,6 +27,9 @@ class Gallery_Unit_Test_Controller extends Controller {
ini_set("display_errors", true);
error_reporting(-1);
+ // Track whether all tests pass so we can return an appropriate code to the CLI
+ $all_tests_passed = false;
+
// Jump through some hoops to satisfy the way that we check for the site_domain in
// config.php. We structure this such that the code in config will leave us with a
// site_domain of "." (for historical reasons)
@@ -132,7 +135,7 @@ class Gallery_Unit_Test_Controller extends Controller {
graphics::choose_default_toolkit();
$filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null;
- print new Unit_Test($modules, $filter);
+ print new Unit_Test($modules, $filter, $all_tests_passed);
} catch (ORM_Validation_Exception $e) {
print "Validation Exception: {$e->getMessage()}\n";
print $e->getTraceAsString() . "\n";
@@ -143,5 +146,11 @@ class Gallery_Unit_Test_Controller extends Controller {
print "Exception: {$e->getMessage()}\n";
print $e->getTraceAsString() . "\n";
}
+
+ // Let the CLI caller know whether all tests passed or not,
+ // to allow usage of continuous integration servers.
+ if (PHP_SAPI == 'cli') {
+ exit($all_tests_passed ? 0 : 1);
+ }
}
}
diff --git a/modules/unit_test/libraries/Unit_Test.php b/modules/unit_test/libraries/Unit_Test.php
index 253d6fb6..15306f7e 100644
--- a/modules/unit_test/libraries/Unit_Test.php
+++ b/modules/unit_test/libraries/Unit_Test.php
@@ -67,9 +67,10 @@ class Unit_Test_Core {
*
* @param array test path(s)
* @param string filter (regular expression)
+ * @param boolean will be set to true if all tests pass
* @return void
*/
- public function __construct($extra_paths=array(), $filter=null)
+ public function __construct($extra_paths=array(), $filter=null, $all_passed=null)
{
// Merge possible default test path(s) from config with the rest
$paths = array_merge($extra_paths, Kohana::config('unit_test.paths', FALSE, FALSE));
@@ -83,6 +84,9 @@ class Unit_Test_Core {
// Take out duplicate test paths after normalization
$this->paths = array_unique($paths);
+ // Assume all tests will pass
+ $all_passed = true;
+
// Loop over each given test path
foreach ($this->paths as $path)
{
@@ -216,6 +220,7 @@ class Unit_Test_Core {
// Test failed
$this->results[$class][$method_name] = $e;
$this->stats[$class]['failed']++;
+ $all_passed = false;
}
catch (Exception $e)
{
@@ -224,6 +229,7 @@ class Unit_Test_Core {
// Test error
$this->results[$class][$method_name] = $e;
$this->stats[$class]['errors']++;
+ $all_passed = false;
}
// Calculate score