OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer_cli.test.utils; | 5 library analyzer_cli.test.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 } on AnalyzerErrorGroup catch (e) { | 33 } on AnalyzerErrorGroup catch (e) { |
34 return e.toString().replaceAllMapped( | 34 return e.toString().replaceAllMapped( |
35 new RegExp(r"^(Error on line \d+ of )((?:[A-Z]+:)?[^:]+): .*$", | 35 new RegExp(r"^(Error on line \d+ of )((?:[A-Z]+:)?[^:]+): .*$", |
36 multiLine: true), | 36 multiLine: true), |
37 (match) => match[1] + pathos.basename(match[2]) + ': ...'); | 37 (match) => match[1] + pathos.basename(match[2]) + ': ...'); |
38 } | 38 } |
39 return null; | 39 return null; |
40 }); | 40 }); |
41 } | 41 } |
42 | 42 |
| 43 /// Recursively copy the specified [src] directory (or file) |
| 44 /// to the specified destination path. |
| 45 Future<Null> recursiveCopy(FileSystemEntity src, String dstPath) async { |
| 46 if (src is Directory) { |
| 47 await (new Directory(dstPath)).create(recursive: true); |
| 48 for (FileSystemEntity entity in src.listSync()) { |
| 49 await recursiveCopy( |
| 50 entity, pathos.join(dstPath, pathos.basename(entity.path))); |
| 51 } |
| 52 } else if (src is File) { |
| 53 await src.copy(dstPath); |
| 54 } |
| 55 } |
| 56 |
43 /// Creates a temporary directory and passes its path to [fn]. Once [fn] | 57 /// Creates a temporary directory and passes its path to [fn]. Once [fn] |
44 /// completes, the temporary directory and all its contents will be deleted. | 58 /// completes, the temporary directory and all its contents will be deleted. |
45 /// | 59 /// |
46 /// Returns the return value of [fn]. | 60 /// Returns the return value of [fn]. |
47 dynamic withTempDir(fn(String path)) { | 61 dynamic withTempDir(fn(String path)) { |
48 var tempDir = Directory.systemTemp.createTempSync('analyzer_').path; | 62 var tempDir = Directory.systemTemp.createTempSync('analyzer_').path; |
49 try { | 63 try { |
50 return fn(tempDir); | 64 return fn(tempDir); |
51 } finally { | 65 } finally { |
52 new Directory(tempDir).deleteSync(recursive: true); | 66 new Directory(tempDir).deleteSync(recursive: true); |
53 } | 67 } |
54 } | 68 } |
55 | 69 |
56 /// Creates a temporary directory and passes its path to [fn]. Once [fn] | 70 /// Creates a temporary directory and passes its path to [fn]. Once [fn] |
57 /// completes, the temporary directory and all its contents will be deleted. | 71 /// completes, the temporary directory and all its contents will be deleted. |
58 /// | 72 /// |
59 /// Returns the return value of [fn]. | 73 /// Returns the return value of [fn]. |
60 Future<dynamic> withTempDirAsync(Future<dynamic> fn(String path)) async { | 74 Future<dynamic> withTempDirAsync(Future<dynamic> fn(String path)) async { |
61 var tempDir = (await Directory.systemTemp.createTemp('analyzer_')).path; | 75 var tempDir = (await Directory.systemTemp.createTemp('analyzer_')).path; |
62 try { | 76 try { |
63 return await fn(tempDir); | 77 return await fn(tempDir); |
64 } finally { | 78 } finally { |
65 await new Directory(tempDir).delete(recursive: true); | 79 await new Directory(tempDir).delete(recursive: true); |
66 } | 80 } |
67 } | 81 } |
68 | 82 |
69 /// Recursively copy the specified [src] directory (or file) | |
70 /// to the specified destination path. | |
71 Future<Null> recursiveCopy(FileSystemEntity src, String dstPath) async { | |
72 if (src is Directory) { | |
73 await (new Directory(dstPath)).create(recursive: true); | |
74 for (FileSystemEntity entity in src.listSync()) { | |
75 await recursiveCopy( | |
76 entity, pathos.join(dstPath, pathos.basename(entity.path))); | |
77 } | |
78 } else if (src is File) { | |
79 await src.copy(dstPath); | |
80 } | |
81 } | |
82 | |
83 class _TestUtils {} | 83 class _TestUtils {} |
OLD | NEW |