From 4fe07c6b0a341b0b99ee1b051f7c0bdfda572e04 Mon Sep 17 00:00:00 2001 From: Jozef Selesi Date: Mon, 4 Mar 2013 21:37:38 +0100 Subject: Return "1" to CLI if not all unit tests pass. --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'modules/gallery_unit_test') 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); + } } } -- cgit v1.2.3 From d136a035e38e920f294aa71acce23a28fc6f5796 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 6 Mar 2013 16:13:49 -0500 Subject: Explicitly print out the exit status to see if I can narrow down failures on Travis. --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/gallery_unit_test') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 55d0abc1..cf2f7c99 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -150,7 +150,9 @@ class Gallery_Unit_Test_Controller extends Controller { // 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); + $exit_status = $all_tests_passed ? 0 : 1; + print "Exit: $exit_status\n"; + exit($exit_status); } } } -- cgit v1.2.3 From feed100337e2222c4656901d11c2f80a0e667002 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 6 Mar 2013 16:38:38 -0500 Subject: Revert "Return "1" to CLI if not all unit tests pass.". We're not successfully passing back $all_passed because the function doesn't take it by reference. Which is my fault because I gave Jozefs bad advice. But I don't think it's necessary anyway so I'm going to try a different approach. This reverts commit 4fe07c6b0a341b0b99ee1b051f7c0bdfda572e04. Conflicts: modules/gallery_unit_test/controllers/gallery_unit_test.php --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 13 +------------ modules/unit_test/libraries/Unit_Test.php | 8 +------- 2 files changed, 2 insertions(+), 19 deletions(-) (limited to 'modules/gallery_unit_test') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index cf2f7c99..67d006b3 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -27,9 +27,6 @@ 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) @@ -135,7 +132,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, $all_tests_passed); + print new Unit_Test($modules, $filter); } catch (ORM_Validation_Exception $e) { print "Validation Exception: {$e->getMessage()}\n"; print $e->getTraceAsString() . "\n"; @@ -146,13 +143,5 @@ 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_status = $all_tests_passed ? 0 : 1; - print "Exit: $exit_status\n"; - exit($exit_status); - } } } diff --git a/modules/unit_test/libraries/Unit_Test.php b/modules/unit_test/libraries/Unit_Test.php index 15306f7e..253d6fb6 100644 --- a/modules/unit_test/libraries/Unit_Test.php +++ b/modules/unit_test/libraries/Unit_Test.php @@ -67,10 +67,9 @@ 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, $all_passed=null) + public function __construct($extra_paths=array(), $filter=null) { // Merge possible default test path(s) from config with the rest $paths = array_merge($extra_paths, Kohana::config('unit_test.paths', FALSE, FALSE)); @@ -84,9 +83,6 @@ 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) { @@ -220,7 +216,6 @@ class Unit_Test_Core { // Test failed $this->results[$class][$method_name] = $e; $this->stats[$class]['failed']++; - $all_passed = false; } catch (Exception $e) { @@ -229,7 +224,6 @@ class Unit_Test_Core { // Test error $this->results[$class][$method_name] = $e; $this->stats[$class]['errors']++; - $all_passed = false; } // Calculate score -- cgit v1.2.3 From f0064643c20d66a4b4abb3b6450afe6c48e27da1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 6 Mar 2013 16:45:38 -0500 Subject: Set exit status to the number of failed tests. This should fix issues with Travis. --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'modules/gallery_unit_test') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 67d006b3..5dd086b9 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -132,7 +132,8 @@ 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); + $unit_test = new Unit_Test($modules, $filter); + print $unit_test; } catch (ORM_Validation_Exception $e) { print "Validation Exception: {$e->getMessage()}\n"; print $e->getTraceAsString() . "\n"; @@ -143,5 +144,13 @@ class Gallery_Unit_Test_Controller extends Controller { print "Exception: {$e->getMessage()}\n"; print $e->getTraceAsString() . "\n"; } + + $failed = 0; + foreach ($unit_test->stats as $class => $stats) { + $failed += $stats["failed"]; + } + if (PHP_SAPI == 'cli') { + exit($failed); + } } } -- cgit v1.2.3 From 59ea4a6a312d2891bb51bd2670635637924f7dcf Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 6 Mar 2013 17:04:54 -0500 Subject: Follow-on fix: count errors as well as test failures. --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery_unit_test') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 5dd086b9..3275d741 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -147,7 +147,7 @@ class Gallery_Unit_Test_Controller extends Controller { $failed = 0; foreach ($unit_test->stats as $class => $stats) { - $failed += $stats["failed"]; + $failed += ($stats["failed"] + $stats["errors"]); } if (PHP_SAPI == 'cli') { exit($failed); -- cgit v1.2.3 From b036b8acc0835126e76814abdd76da4d80d4b0fc Mon Sep 17 00:00:00 2001 From: shadlaws Date: Sun, 10 Mar 2013 11:27:10 +0100 Subject: Follow-on fix: if tests throw an exception, don't throw another by calling an undefined variable. --- modules/gallery_unit_test/controllers/gallery_unit_test.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'modules/gallery_unit_test') diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index 3275d741..6b2bf479 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -145,9 +145,14 @@ class Gallery_Unit_Test_Controller extends Controller { print $e->getTraceAsString() . "\n"; } - $failed = 0; - foreach ($unit_test->stats as $class => $stats) { - $failed += ($stats["failed"] + $stats["errors"]); + if (!isset($unit_test)) { + // If an exception is thrown, it's possible that $unit_test was never set. + $failed = 1; + } else { + $failed = 0; + foreach ($unit_test->stats as $class => $stats) { + $failed += ($stats["failed"] + $stats["errors"]); + } } if (PHP_SAPI == 'cli') { exit($failed); -- cgit v1.2.3