| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library watcher.test.utils; | 5 library watcher.test.utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 return _watcher; | 103 return _watcher; |
| 104 } | 104 } |
| 105 | 105 |
| 106 /// Expects that the next set of events will all be changes of [type] on | 106 /// Expects that the next set of events will all be changes of [type] on |
| 107 /// [paths]. | 107 /// [paths]. |
| 108 /// | 108 /// |
| 109 /// Validates that events are delivered for all paths in [paths], but allows | 109 /// Validates that events are delivered for all paths in [paths], but allows |
| 110 /// them in any order. | 110 /// them in any order. |
| 111 void expectEvents(ChangeType type, Iterable<String> paths) { | 111 void expectEvents(ChangeType type, Iterable<String> paths) { |
| 112 var pathSet = paths.map((path) => p.join(_sandboxDir, path)).toSet(); | 112 var pathSet = paths |
| 113 .map((path) => p.join(_sandboxDir, path)) |
| 114 .map(p.normalize) |
| 115 .toSet(); |
| 113 | 116 |
| 114 // Create an expectation for as many paths as we have. | 117 // Create an expectation for as many paths as we have. |
| 115 var futures = []; | 118 var futures = []; |
| 116 | 119 |
| 117 for (var i = 0; i < paths.length; i++) { | 120 for (var i = 0; i < paths.length; i++) { |
| 118 // Immediately create the futures. This ensures we don't register too | 121 // Immediately create the futures. This ensures we don't register too |
| 119 // late and drop the event before we receive it. | 122 // late and drop the event before we receive it. |
| 120 var future = _watcher.events.elementAt(_nextEvent++).then((event) { | 123 var future = _watcher.events.elementAt(_nextEvent++).then((event) { |
| 121 expect(event.type, equals(type)); | 124 expect(event.type, equals(type)); |
| 122 expect(pathSet, contains(event.path)); | 125 expect(pathSet, contains(event.path)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 219 |
| 217 Description describe(Description description) { | 220 Description describe(Description description) { |
| 218 description.add("$type $path"); | 221 description.add("$type $path"); |
| 219 } | 222 } |
| 220 | 223 |
| 221 bool matches(item, Map matchState) => | 224 bool matches(item, Map matchState) => |
| 222 item is WatchEvent && | 225 item is WatchEvent && |
| 223 item.type == type && | 226 item.type == type && |
| 224 p.normalize(item.path) == p.normalize(path); | 227 p.normalize(item.path) == p.normalize(path); |
| 225 } | 228 } |
| OLD | NEW |