OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// A test configuration that generates a compact 1-line progress bar. The bar | 5 /// A test configuration that generates a compact 1-line progress bar. The bar |
6 /// is updated in-place before and after each test is executed. If all tests | 6 /// is updated in-place before and after each test is executed. If all tests |
7 /// pass, only a couple of lines are printed in the terminal. If a test fails, | 7 /// pass, only a couple of lines are printed in the terminal. If a test fails, |
8 /// the failure is shown and the progress bar continues to be updated below it. | 8 /// the failure is shown and the progress bar continues to be updated below it. |
9 library unittest.compact_vm_config; | 9 library unittest.compact_vm_config; |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 buffer.write(' -'); | 127 buffer.write(' -'); |
128 buffer.write(_fail); | 128 buffer.write(_fail); |
129 buffer.write(_NONE); | 129 buffer.write(_NONE); |
130 } | 130 } |
131 buffer.write(': '); | 131 buffer.write(': '); |
132 buffer.write(color); | 132 buffer.write(color); |
133 | 133 |
134 // Ensure the line fits under MAX_LINE. [buffer] includes the color escape | 134 // Ensure the line fits under MAX_LINE. [buffer] includes the color escape |
135 // sequences too. Because these sequences are not visible characters, we | 135 // sequences too. Because these sequences are not visible characters, we |
136 // make sure they are not counted towards the limit. | 136 // make sure they are not counted towards the limit. |
137 int nonVisible = _nonVisiblePrefix + color.length + | 137 int nonVisible = _nonVisiblePrefix + |
| 138 color.length + |
138 (_fail != 0 ? (_RED.length + _NONE.length) : 0); | 139 (_fail != 0 ? (_RED.length + _NONE.length) : 0); |
139 int len = buffer.length - nonVisible; | 140 int len = buffer.length - nonVisible; |
140 var mx = MAX_LINE - len; | 141 var mx = MAX_LINE - len; |
141 buffer.write(_snippet(message, MAX_LINE - len)); | 142 buffer.write(_snippet(message, MAX_LINE - len)); |
142 buffer.write(_NONE); | 143 buffer.write(_NONE); |
143 | 144 |
144 // Pad the rest of the line so that it looks erased. | 145 // Pad the rest of the line so that it looks erased. |
145 len = buffer.length - nonVisible - _NONE.length; | 146 len = buffer.length - nonVisible - _NONE.length; |
146 if (len > _lastLength) { | 147 if (len > _lastLength) { |
147 _lastLength = len; | 148 _lastLength = len; |
148 } else { | 149 } else { |
149 while (len < _lastLength) { | 150 while (len < _lastLength) { |
150 buffer.write(' '); | 151 buffer.write(' '); |
151 _lastLength--; | 152 _lastLength--; |
152 } | 153 } |
153 } | 154 } |
154 stdout.write(buffer.toString()); | 155 stdout.write(buffer.toString()); |
155 } | 156 } |
156 | 157 |
157 String _padTime(int time) => | 158 String _padTime(int time) => |
158 (time == 0) ? '00' : ((time < 10) ? '0$time' : '$time'); | 159 (time == 0) ? '00' : ((time < 10) ? '0$time' : '$time'); |
159 | 160 |
160 String _timeString(Duration duration) { | 161 String _timeString(Duration duration) { |
161 var min = duration.inMinutes; | 162 var min = duration.inMinutes; |
162 var sec = duration.inSeconds % 60; | 163 var sec = duration.inSeconds % 60; |
163 return '${_padTime(min)}:${_padTime(sec)}'; | 164 return '${_padTime(min)}:${_padTime(sec)}'; |
164 } | 165 } |
165 | 166 |
166 String _snippet(String text, int maxLength) { | 167 String _snippet(String text, int maxLength) { |
167 // Return the full message if it fits | 168 // Return the full message if it fits |
168 if (text.length <= maxLength) return text; | 169 if (text.length <= maxLength) return text; |
169 | 170 |
170 // If we can fit the first and last three words, do so. | 171 // If we can fit the first and last three words, do so. |
171 var words = text.split(' '); | 172 var words = text.split(' '); |
172 if (words.length > 1) { | 173 if (words.length > 1) { |
173 int i = words.length; | 174 int i = words.length; |
174 var len = words.first.length + 4; | 175 var len = words.first.length + 4; |
175 do { | 176 do { |
176 len += 1 + words[--i].length; | 177 len += 1 + words[--i].length; |
177 } while (len <= maxLength && i > 0); | 178 } while (len <= maxLength && i > 0); |
178 if (len > maxLength || i == 0) i++; | 179 if (len > maxLength || i == 0) i++; |
179 if (i < words.length - 4) { | 180 if (i < words.length - 4) { |
180 // Require at least 3 words at the end. | 181 // Require at least 3 words at the end. |
181 var buffer = new StringBuffer(); | 182 var buffer = new StringBuffer(); |
182 buffer.write(words.first); | 183 buffer.write(words.first); |
183 buffer.write(' ...'); | 184 buffer.write(' ...'); |
184 for (; i < words.length; i++) { | 185 for ( ; i < words.length; i++) { |
185 buffer.write(' '); | 186 buffer.write(' '); |
186 buffer.write(words[i]); | 187 buffer.write(words[i]); |
187 } | 188 } |
188 return buffer.toString(); | 189 return buffer.toString(); |
189 } | 190 } |
190 } | 191 } |
191 | 192 |
192 // Otherwise truncate to return the trailing text, but attempt to start at | 193 // Otherwise truncate to return the trailing text, but attempt to start at |
193 // the beginning of a word. | 194 // the beginning of a word. |
194 var res = text.substring(text.length - maxLength + 4); | 195 var res = text.substring(text.length - maxLength + 4); |
(...skipping 12 matching lines...) Expand all Loading... |
207 // If the test is running on the Dart buildbots, we don't want to use this | 208 // If the test is running on the Dart buildbots, we don't want to use this |
208 // config since it's output may not be what the bots expect. | 209 // config since it's output may not be what the bots expect. |
209 if (Platform.environment['LOGNAME'] == 'chrome-bot') { | 210 if (Platform.environment['LOGNAME'] == 'chrome-bot') { |
210 return; | 211 return; |
211 } | 212 } |
212 | 213 |
213 unittestConfiguration = _singleton; | 214 unittestConfiguration = _singleton; |
214 } | 215 } |
215 | 216 |
216 final _singleton = new CompactVMConfiguration(); | 217 final _singleton = new CompactVMConfiguration(); |
OLD | NEW |