Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library watcher.stat; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 typedef DateTime MockTimeCallback(String path); | |
|
nweiz
2013/07/11 00:25:01
Document this.
Bob Nystrom
2013/07/11 18:33:20
Done.
| |
| 11 | |
| 12 MockTimeCallback _mockTimeCallback; | |
| 13 | |
| 14 /// Overrided the default behavior for accessing a file's modification time with | |
|
nweiz
2013/07/11 00:25:01
"Overrided" -> "Override"
Bob Nystrom
2013/07/11 18:33:20
"Overrides". Done.
| |
| 15 /// [callback]. | |
| 16 /// | |
| 17 /// The OS file modification time has pretty rough granularity (like a few | |
| 18 /// seconds) which can make for slow tests that rely on modtime. This lets you | |
| 19 /// replace it with something you control. | |
| 20 void mockGetModificationTime(MockTimeCallback callback) { | |
| 21 _mockTimeCallback = callback; | |
| 22 } | |
| 23 | |
| 24 /// Gets the modification time for the file at [path]. | |
| 25 Future<DateTime> getModificationTime(String path) { | |
| 26 if (_mockTimeCallback != null) { | |
| 27 return new Future.value(_mockTimeCallback(path)); | |
| 28 } | |
| 29 | |
| 30 return FileStat.stat(path).then((stat) => stat.modified); | |
| 31 } | |
| OLD | NEW |