Changeset 21244
- Timestamp:
- 08/18/09 23:14:30 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/lime/branches/2.0-experimental/lib/output/LimeOutputConsoleSummary.php
r21239 r21244 22 22 $failedTests = 0, 23 23 $expected = array(), 24 $actual = array(), 24 25 $passed = array(), 25 26 $failed = array(), … … 35 36 'base_dir' => null, 36 37 'processes' => 1, 38 'verbose' => false, 37 39 ), $options); 38 40 } … … 51 53 $this->line[$file] = count($this->line); 52 54 $this->expected[$file] = 0; 55 $this->actual[$file] = 0; 53 56 $this->passed[$file] = 0; 54 $this->failed[$file] = 0;55 $this->errors[$file] = 0;56 $this->warnings[$file] = 0;57 $this->failed[$file] = array(); 58 $this->errors[$file] = array(); 59 $this->warnings[$file] = array(); 57 60 } 58 61 } … … 66 69 $this->failedTests += $this->getFailed(); 67 70 68 $path = $this-> getTruncatedFile();71 $path = $this->truncate($this->file); 69 72 70 73 if (strlen($path) > 71) … … 103 106 } 104 107 108 105 109 if ($this->getErrors() || $this->getWarnings() || $this->getFailed() || $incomplete) 106 110 { … … 114 118 } 115 119 } 120 121 if ($this->options['verbose']) 122 { 123 if ($this->getFailed()) 124 { 125 $this->printer->printLine(' Failed Tests:', LimePrinter::COMMENT); 126 127 foreach ($this->failed[$this->file] as $number => $failed) 128 { 129 $this->printer->printLine(' not ok '.$number.' - '.$failed[0]); 130 $this->printer->printText(' (in '); 131 $this->printer->printText($this->truncate($failed[1]), LimePrinter::TRACE); 132 $this->printer->printText(' on line '); 133 $this->printer->printText($failed[2], LimePrinter::TRACE); 134 $this->printer->printLine(')'); 135 } 136 } 137 138 if ($this->getWarnings()) 139 { 140 $this->printer->printLine(' Warnings:', LimePrinter::COMMENT); 141 142 foreach ($this->warnings[$this->file] as $warning) 143 { 144 $this->printer->printLine(' '.$warning[0]); 145 $this->printer->printText(' (in '); 146 $this->printer->printText($this->truncate($warning[1]), LimePrinter::TRACE); 147 $this->printer->printText(' on line '); 148 $this->printer->printText($warning[2], LimePrinter::TRACE); 149 $this->printer->printLine(')'); 150 } 151 } 152 153 if ($this->getErrors()) 154 { 155 $this->printer->printLine(' Errors:', LimePrinter::COMMENT); 156 157 foreach ($this->errors[$this->file] as $error) 158 { 159 $this->printer->printLine(' '.$error->getMessage()); 160 $this->printer->printText(' (in '); 161 $this->printer->printText($this->truncate($error->getFile()), LimePrinter::TRACE); 162 $this->printer->printText(' on line '); 163 $this->printer->printText($error->getLine(), LimePrinter::TRACE); 164 $this->printer->printLine(')'); 165 } 166 } 167 } 116 168 } 117 169 } … … 124 176 protected function getActual() 125 177 { 126 return $this-> getPassed() + $this->getFailed();178 return $this->actual[$this->file]; 127 179 } 128 180 … … 134 186 protected function getFailed() 135 187 { 136 return $this->failed[$this->file];188 return count($this->failed[$this->file]); 137 189 } 138 190 139 191 protected function getErrors() 140 192 { 141 return $this->errors[$this->file];193 return count($this->errors[$this->file]); 142 194 } 143 195 144 196 protected function getWarnings() 145 197 { 146 return $this->warnings[$this->file]; 147 } 148 149 protected function setCursor() 150 { 151 for ($i = count($this->line); $i > $this->line[$this->file]; --$i) 152 { 153 $this->printer->previousLine(); 154 } 155 } 156 157 protected function resetCursor() 158 { 159 for ($i = $this->line[$this->file]; $i < count($this->line); ++$i) 160 { 161 $this->printer->nextLine(); 162 } 198 return count($this->warnings[$this->file]); 163 199 } 164 200 … … 171 207 { 172 208 $this->passed[$this->file]++; 209 $this->actual[$this->file]++; 173 210 } 174 211 175 212 public function fail($message, $file, $line, $error = null) 176 213 { 177 $this->failed[$this->file]++; 214 $this->actual[$this->file]++; 215 $this->failed[$this->file][$this->actual[$this->file]] = array($message, $file, $line); 178 216 } 179 217 180 218 public function skip($message, $file, $line) {} 181 219 182 public function todo($message, $file, $line) 183 { 184 } 220 public function todo($message, $file, $line) {} 185 221 186 222 public function warning($message, $file, $line) 187 223 { 188 $this->warnings[$this->file] ++;224 $this->warnings[$this->file][] = array($message, $file, $line); 189 225 } 190 226 191 227 public function error(Exception $exception) 192 228 { 193 $this->errors[$this->file] ++;229 $this->errors[$this->file][] = $exception; 194 230 } 195 231 … … 217 253 } 218 254 219 protected function getTruncatedFile()220 { 221 if (!is_null($this->options ))222 { 223 return str_replace($this->options['base_dir'], '', $ this->file);255 protected function truncate($file) 256 { 257 if (!is_null($this->options['base_dir'])) 258 { 259 return str_replace($this->options['base_dir'], '', $file); 224 260 } 225 261 else 226 262 { 227 return $ this->file;263 return $file; 228 264 } 229 265 } tools/lime/branches/2.0-experimental/test/unit/output/LimeOutputConsoleSummaryTest.php
r21239 r21244 14 14 LimeAnnotationSupport::enable(); 15 15 16 $t = new LimeTest( 39);16 $t = new LimeTest(76); 17 17 18 18 … … 137 137 138 138 139 // @Test: When close() is called and the option "verbose" is set, all failure and error messages are listed 140 141 // fixtures 142 $printer->any('printText'); 143 $printer->any('printLine'); 144 $printer->any('printText'); 145 $printer->any('printLine')->times(3); 146 $printer->printLine(' Failed Tests:', LimePrinter::COMMENT); 147 $printer->printLine(' not ok 2 - A failed test'); 148 $printer->printText(' (in '); 149 $printer->printText('/test/script', LimePrinter::TRACE); 150 $printer->printText(' on line '); 151 $printer->printText('11', LimePrinter::TRACE); 152 $printer->printLine(')'); 153 $printer->printLine(' not ok 3 - A failed test'); 154 $printer->printText(' (in '); 155 $printer->printText('/test/script', LimePrinter::TRACE); 156 $printer->printText(' on line '); 157 $printer->printText('11', LimePrinter::TRACE); 158 $printer->printLine(')'); 159 $printer->printLine(' Warnings:', LimePrinter::COMMENT); 160 $printer->printLine(' A warning'); 161 $printer->printText(' (in '); 162 $printer->printText('/test/script', LimePrinter::TRACE); 163 $printer->printText(' on line '); 164 $printer->printText('11', LimePrinter::TRACE); 165 $printer->printLine(')'); 166 $printer->printLine(' Errors:', LimePrinter::COMMENT); 167 $printer->printLine(' An error'); 168 $printer->printText(' (in '); 169 $printer->printText('/test/script', LimePrinter::TRACE); 170 $printer->printText(' on line '); 171 $printer->printText('11', LimePrinter::TRACE); 172 $printer->printLine(')'); 173 $printer->printLine(' An error'); 174 $printer->printText(' (in '); 175 $printer->printText('/test/script', LimePrinter::TRACE); 176 $printer->printText(' on line '); 177 $printer->printText('11', LimePrinter::TRACE); 178 $printer->printLine(')'); 179 $printer->replay(); 180 $output = new LimeOutputConsoleSummary($printer, array('verbose' => true)); 181 // test 182 $output->focus('/test/script'); 183 $output->pass('A passed test', '/test/script', 11); 184 $output->fail('A failed test', '/test/script', 11); 185 $output->fail('A failed test', '/test/script', 11); 186 $output->warning('A warning', '/test/script', 11); 187 $output->error(new LimeError('An error', '/test/script', 11)); 188 $output->error(new LimeError('An error', '/test/script', 11)); 189 $output->close(); 190 // assertions 191 $printer->verify(); 192 193 139 194 // @Test: flush() prints a summary of all files if failures occured 140 195