| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Utilities for creating unit tests of Barback transformers. | 5 /// Utilities for creating unit tests of Barback transformers. |
| 6 library code_transformers.src.test_harness; | 6 library code_transformers.src.test_harness; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 print(Trace.format(trace)); | 57 print(Trace.format(trace)); |
| 58 } | 58 } |
| 59 fail('error running barback: $e'); | 59 fail('error running barback: $e'); |
| 60 }); | 60 }); |
| 61 | 61 |
| 62 resultSubscription = barback.results.listen((result) { | 62 resultSubscription = barback.results.listen((result) { |
| 63 expect(result.succeeded, !errorSeen, reason: "${result.errors}"); | 63 expect(result.succeeded, !errorSeen, reason: "${result.errors}"); |
| 64 }); | 64 }); |
| 65 | 65 |
| 66 logSubscription = barback.log.listen((entry) { | 66 logSubscription = barback.log.listen((entry) { |
| 67 // Ignore info messages. | 67 // Ignore info and fine messages. |
| 68 if (entry.level == LogLevel.INFO) return; | 68 if (entry.level == LogLevel.INFO || entry.level == LogLevel.FINE) return; |
| 69 if (entry.level == LogLevel.ERROR) errorSeen = true; | 69 if (entry.level == LogLevel.ERROR) errorSeen = true; |
| 70 // We only check messages when an expectation is provided. | 70 // We only check messages when an expectation is provided. |
| 71 if (messages == null) return; | 71 if (messages == null) return; |
| 72 | 72 |
| 73 var msg = '${entry.level.name.toLowerCase()}: ${entry.message}'; | 73 var msg = '${entry.level.name.toLowerCase()}: ${entry.message}'; |
| 74 var span = entry.span; | 74 var span = entry.span; |
| 75 var spanInfo = span == null ? '' : | 75 var spanInfo = span == null ? '' : |
| 76 ' (${span.sourceUrl} ${span.start.line} ${span.start.column})'; | 76 ' (${span.sourceUrl} ${span.start.line} ${span.start.column})'; |
| 77 expect(messagesSeen, lessThan(messages.length), | 77 expect(messagesSeen, lessThan(messages.length), |
| 78 reason: 'more messages than expected.\nMessage seen: $msg$spanInfo'); | 78 reason: 'more messages than expected.\nMessage seen: $msg$spanInfo'); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 }); | 115 }); |
| 116 return Future.wait(futures); | 116 return Future.wait(futures); |
| 117 }).then((_) { | 117 }).then((_) { |
| 118 // We only check messages when an expectation is provided. | 118 // We only check messages when an expectation is provided. |
| 119 if (messages == null) return; | 119 if (messages == null) return; |
| 120 expect(messagesSeen, messages.length, | 120 expect(messagesSeen, messages.length, |
| 121 reason: 'less messages than expected'); | 121 reason: 'less messages than expected'); |
| 122 }); | 122 }); |
| 123 } | 123 } |
| 124 } | 124 } |
| OLD | NEW |