summaryrefslogtreecommitdiff
path: root/_test/lib/cli_reporter.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-10-15 13:45:45 +0200
committerAndreas Gohr <andi@splitbrain.org>2005-10-15 13:45:45 +0200
commitb73cc7dccaa01778de20ade004e0c3bde2e2e36a (patch)
treea082fedea2f4a7e99b5cc6352c35e9b192b145ec /_test/lib/cli_reporter.php
parent5e35ae2a19fba9e79a1b71d951d7f322b864c001 (diff)
downloadrpg-b73cc7dccaa01778de20ade004e0c3bde2e2e36a.tar.gz
rpg-b73cc7dccaa01778de20ade004e0c3bde2e2e36a.tar.bz2
renamed test directory
darcs-hash:20051015114545-7ad00-561552ce7e519d81146b5cb2d28203aee7c6d2ad.gz
Diffstat (limited to '_test/lib/cli_reporter.php')
-rw-r--r--_test/lib/cli_reporter.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/_test/lib/cli_reporter.php b/_test/lib/cli_reporter.php
new file mode 100644
index 000000000..a65112a34
--- /dev/null
+++ b/_test/lib/cli_reporter.php
@@ -0,0 +1,91 @@
+<?php // -*- fill-column: 80; tab-width: 4; c-basic-offset: 4 -*-
+
+if (! defined('ST_FAILDETAIL_SEPARATOR')) {
+ define('ST_FAILDETAIL_SEPARATOR', "->");
+}
+
+if (! defined('ST_FAILS_RETURN_CODE')) {
+ define('ST_FAILS_RETURN_CODE', 1);
+}
+
+if (version_compare(phpversion(), '4.3.0', '<') ||
+ php_sapi_name() == 'cgi') {
+ define('STDOUT', fopen('php://stdout', 'w'));
+ define('STDERR', fopen('php://stderr', 'w'));
+ register_shutdown_function(
+ create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
+}
+
+/**
+ * Minimal command line test displayer. Writes fail details to STDERR. Returns 0
+ * to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
+ */
+class CLIReporter extends SimpleReporter {
+
+ var $faildetail_separator = ST_FAILDETAIL_SEPARATOR;
+
+ function CLIReporter($faildetail_separator = NULL) {
+ $this->SimpleReporter();
+ if (! is_null($faildetail_separator)) {
+ $this->setFailDetailSeparator($faildetail_separator);
+ }
+ }
+
+ function setFailDetailSeparator($separator) {
+ $this->faildetail_separator = $separator;
+ }
+
+ /**
+ * Return a formatted faildetail for printing.
+ */
+ function &_paintTestFailDetail(&$message) {
+ $buffer = '';
+ $faildetail = $this->getTestList();
+ array_shift($faildetail);
+ $buffer .= implode($this->faildetail_separator, $faildetail);
+ $buffer .= $this->faildetail_separator . "$message\n";
+ return $buffer;
+ }
+
+ /**
+ * Paint fail faildetail to STDERR.
+ */
+ function paintFail($message) {
+ parent::paintFail($message);
+ fwrite(STDERR, 'FAIL' . $this->faildetail_separator .
+ $this->_paintTestFailDetail($message));
+ }
+
+ /**
+ * Paint exception faildetail to STDERR.
+ */
+ function paintException($message) {
+ parent::paintException($message);
+ fwrite(STDERR, 'EXCEPTION' . $this->faildetail_separator .
+ $this->_paintTestFailDetail($message));
+ }
+
+ /**
+ * Paint a footer with test case name, timestamp, counts of fails and
+ * exceptions.
+ */
+ function paintFooter($test_name) {
+ $buffer = $this->getTestCaseProgress() . '/' .
+ $this->getTestCaseCount() . ' test cases complete: ';
+
+ if (0 < ($this->getFailCount() + $this->getExceptionCount())) {
+ $buffer .= $this->getPassCount() . " passes";
+ if (0 < $this->getFailCount()) {
+ $buffer .= ", " . $this->getFailCount() . " fails";
+ }
+ if (0 < $this->getExceptionCount()) {
+ $buffer .= ", " . $this->getExceptionCount() . " exceptions";
+ }
+ $buffer .= ".\n";
+ fwrite(STDOUT, $buffer);
+ exit(ST_FAILS_RETURN_CODE);
+ } else {
+ fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n");
+ }
+ }
+}