]> projects.mako.cc - scuttle/blob - includes/utf8/tests/cli_reporter.php
updated readme with information on a series of bugs I know exist
[scuttle] / includes / utf8 / tests / cli_reporter.php
1 <?php
2 /**
3 * Swiped from the WACT test suite
4 * @author Jon Bangoid
5 * @see http://www.phpwact.org
6 * @version $Id: cli_reporter.php,v 1.1.1.1 2005/07/04 22:30:11 harryf Exp $
7 */
8 if (! defined('ST_FAILDETAIL_SEPARATOR')) {
9     define('ST_FAILDETAIL_SEPARATOR', "->");
10 }
11
12 if (! defined('ST_FAILS_RETURN_CODE')) {
13     define('ST_FAILS_RETURN_CODE', 1);
14 }
15
16 if (version_compare(phpversion(), '4.3.0', '<') ||
17     php_sapi_name() == 'cgi') {
18     define('STDOUT', fopen('php://stdout', 'w'));
19     define('STDERR', fopen('php://stderr', 'w'));
20     register_shutdown_function(
21         create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
22 }
23
24 /**
25  * Minimal command line test displayer. Writes fail details to STDERR. Returns 0
26  * to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
27  */
28 class CLIReporter extends SimpleReporter {
29
30     var $faildetail_separator = ST_FAILDETAIL_SEPARATOR;
31
32     function CLIReporter($faildetail_separator = NULL) {
33         $this->SimpleReporter();
34         if (! is_null($faildetail_separator)) {
35             $this->setFailDetailSeparator($faildetail_separator);
36         }
37     }
38
39     function setFailDetailSeparator($separator) {
40         $this->faildetail_separator = $separator;
41     }
42
43     /**
44      * Return a formatted faildetail for printing.
45      */
46     function &_paintTestFailDetail(&$message) {
47         $buffer = '';
48         $faildetail = $this->getTestList();
49         array_shift($faildetail);
50         $buffer .= implode($this->faildetail_separator, $faildetail);
51         $buffer .= $this->faildetail_separator . "$message\n";
52         return $buffer;
53     }
54
55     /**
56      * Paint fail faildetail to STDERR.
57      */
58     function paintFail($message) {
59         parent::paintFail($message);
60         fwrite(STDERR, 'FAIL' . $this->faildetail_separator .
61                $this->_paintTestFailDetail($message));
62     }
63
64     /**
65      * Paint exception faildetail to STDERR.
66      */
67     function paintException($message) {
68         parent::paintException($message);
69         fwrite(STDERR, 'EXCEPTION' . $this->faildetail_separator .
70                $this->_paintTestFailDetail($message));
71     }
72
73     /**
74      * Paint a footer with test case name, timestamp, counts of fails and
75      * exceptions.
76      */
77     function paintFooter($test_name) {
78         $buffer = $this->getTestCaseProgress() . '/' .
79             $this->getTestCaseCount() . ' test cases complete: ';
80
81         if (0 < ($this->getFailCount() + $this->getExceptionCount())) {
82             $buffer .= $this->getPassCount() . " passes";
83             if (0 < $this->getFailCount()) {
84                 $buffer .= ", " . $this->getFailCount() . " fails";
85             }
86             if (0 < $this->getExceptionCount()) {
87                 $buffer .= ", " . $this->getExceptionCount() . " exceptions";
88             }
89             $buffer .= ".\n";
90             fwrite(STDOUT, $buffer);
91             exit(ST_FAILS_RETURN_CODE);
92         } else {
93             fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n");
94         }
95     }
96 }

Benjamin Mako Hill || Want to submit a patch?