Permalink
Browse files

Bugfix: autorun should set the exit status to 0 if tests pass.

  • Loading branch information...
1 parent 937fedc commit cfb4db4881cab3269a916e4773e0536fbd8c784f dgheath committed Jul 2, 2009
Showing with 37 additions and 6 deletions.
  1. +7 −4 autorun.php
  2. +12 −2 test/autorun_test.php
  3. +9 −0 test/support/failing_test.php
  4. +9 −0 test/support/passing_test.php
View
@@ -35,6 +35,9 @@ function simpletest_autorun() {
* run all recent test cases if no test has
* so far been run. Uses the DefaultReporter which can have
* it's output controlled with SimpleTest::prefer().
+ * @return boolean/null false if there were test failures, true if
+ * there were no failures, null if tests are
+ * already running
*/
function run_local_tests() {
try {
@@ -46,10 +49,10 @@ function run_local_tests() {
$suite = $loader->createSuiteFromClasses(
basename(initial_file()),
$loader->selectRunnableTests($candidates));
- $result = $suite->run(new DefaultReporter());
+ return $suite->run(new DefaultReporter());
} catch (Exception $stack_frame_fix) {
print $stack_frame_fix->getMessage();
- $result = false;
+ return false;
}
}
@@ -75,8 +78,8 @@ function initial_file() {
if (isset($_SERVER, $_SERVER['SCRIPT_FILENAME'])) {
$file = $_SERVER['SCRIPT_FILENAME'];
} else {
- $included_files = get_included_files();
- $file = reset($included_files);
+ $included_files = get_included_files();
+ $file = reset($included_files);
}
}
return $file;
View
@@ -2,12 +2,22 @@
require_once(dirname(__FILE__) . '/../autorun.php');
require_once(dirname(__FILE__) . '/support/test1.php');
-class LoadIfIncludedTestCase extends UnitTestCase {
+class TestOfAutorun extends UnitTestCase {
function test_load_if_included() {
- $tests = new TestSuite();
+ $tests = new TestSuite();
$tests->addFile(dirname(__FILE__) . '/support/test1.php');
$this->assertEqual($tests->getSize(), 1);
}
+
+ function test_exit_status_one_if_tests_fail() {
+ exec('php ' . dirname(__FILE__) . '/support/failing_test.php', $output, $exit_status);
+ $this->assertEqual($exit_status, 1);
+ }
+
+ function test_exit_status_zero_if_tests_fail() {
+ exec('php ' . dirname(__FILE__) . '/support/passing_test.php', $output, $exit_status);
+ $this->assertEqual($exit_status, 0);
+ }
}
?>
@@ -0,0 +1,9 @@
+<?php
+require_once(dirname(__FILE__) . '/../../autorun.php');
+
+class FailingTest extends UnitTestCase {
+ function test_fail() {
+ $this->assertEqual(1,2);
+ }
+}
+?>
@@ -0,0 +1,9 @@
+<?php
+require_once(dirname(__FILE__) . '/../../autorun.php');
+
+class PassingTest extends UnitTestCase {
+ function test_pass() {
+ $this->assertEqual(2,2);
+ }
+}
+?>

0 comments on commit cfb4db4

Please sign in to comment.