GeSHi 1.0.8.3 update
[dokuwiki/radio.git] / _test / lib / cli_reporter.php
blobe83911c732ed1c20190209d44e94802fce45725c
1 <?php // -*- fill-column: 80; tab-width: 4; c-basic-offset: 4 -*-
3 if (! defined('ST_FAILDETAIL_SEPARATOR')) {
4 define('ST_FAILDETAIL_SEPARATOR', "->");
7 if (! defined('ST_FAILS_RETURN_CODE')) {
8 define('ST_FAILS_RETURN_CODE', 1);
11 if (version_compare(phpversion(), '4.3.0', '<') ||
12 php_sapi_name() == 'cgi') {
13 define('STDOUT', fopen('php://stdout', 'w'));
14 define('STDERR', fopen('php://stderr', 'w'));
15 register_shutdown_function(
16 create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
19 /**
20 * Minimal command line test displayer. Writes fail details to STDERR. Returns 0
21 * to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails.
23 class CLIReporter extends SimpleReporter {
25 var $faildetail_separator = ST_FAILDETAIL_SEPARATOR;
26 var $_failinfo;
28 function CLIReporter($faildetail_separator = NULL) {
29 $this->SimpleReporter();
30 if (! is_null($faildetail_separator)) {
31 $this->setFailDetailSeparator($faildetail_separator);
35 function setFailDetailSeparator($separator) {
36 $this->faildetail_separator = $separator;
39 /**
40 * Return a formatted faildetail for printing.
42 function &_paintTestFailDetail(&$message) {
43 $buffer = '';
44 $faildetail = $this->getTestList();
45 array_shift($faildetail);
46 $buffer .= implode($this->faildetail_separator, $faildetail);
47 $buffer .= $this->faildetail_separator . "$message\n";
48 return $buffer;
51 /**
52 * Paint fail faildetail to STDERR.
54 function paintFail($message) {
55 parent::paintFail($message);
56 fwrite(STDERR, 'FAIL' . $this->faildetail_separator .
57 $this->_paintTestFailDetail($message));
58 if($this->_failinfo){
59 fwrite(STDERR, ' additional info was: '.$this->_failinfo."\n");
60 $this->_failinfo = '';
64 /**
65 * Paint exception faildetail to STDERR.
67 function paintException($message) {
68 parent::paintException($message);
69 fwrite(STDERR, 'EXCEPTION' . $this->faildetail_separator .
70 $this->_paintTestFailDetail($message));
73 /**
74 * Handle failinfo message
76 function paintSignal($type,$message) {
77 parent::paintSignal($type,$message);
78 if($type = 'failinfo') $this->_failinfo = $message;
83 /**
84 * Paint a footer with test case name, timestamp, counts of fails and
85 * exceptions.
87 function paintFooter($test_name) {
88 $buffer = $this->getTestCaseProgress() . '/' .
89 $this->getTestCaseCount() . ' test cases complete: ';
91 if (0 < ($this->getFailCount() + $this->getExceptionCount())) {
92 $buffer .= $this->getPassCount() . " passes";
93 if (0 < $this->getFailCount()) {
94 $buffer .= ", " . $this->getFailCount() . " fails";
96 if (0 < $this->getExceptionCount()) {
97 $buffer .= ", " . $this->getExceptionCount() . " exceptions";
99 $buffer .= ".\n";
100 fwrite(STDOUT, $buffer);
101 exit(ST_FAILS_RETURN_CODE);
102 } else {
103 fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n");