OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 import 'dart:io'; |
| 6 |
| 7 import 'package:path/path.dart' as p; |
| 8 |
| 9 /// True if the file system should be left untouched. |
| 10 bool dryRun = false; |
| 11 |
| 12 final String sdkRoot = |
| 13 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), '../../../')); |
| 14 |
| 15 final String testRoot = p.join(sdkRoot, "tests"); |
| 16 |
| 17 /// Moves the file from [from] to [to], which are both assumed to be relative |
| 18 /// paths inside "tests". |
| 19 void moveFile(String from, String to) { |
| 20 if (dryRun) { |
| 21 print(" Dry run: move $from to $to"); |
| 22 return; |
| 23 } |
| 24 |
| 25 // Create the directory if needed. |
| 26 new Directory(p.dirname(p.join(testRoot, to))).createSync(recursive: true); |
| 27 |
| 28 new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to)); |
| 29 } |
| 30 |
| 31 /// Reads the contents of the file at [path], which is assumed to be relative |
| 32 /// within "tests". |
| 33 String readFile(String path) { |
| 34 return new File(p.join(testRoot, path)).readAsStringSync(); |
| 35 } |
| 36 |
| 37 /// Deletes the file at [path], which is assumed to be relative within "tests". |
| 38 void deleteFile(String path) { |
| 39 if (dryRun) { |
| 40 print(" Dry run: delete $path"); |
| 41 return; |
| 42 } |
| 43 |
| 44 new File(p.join(testRoot, path)).deleteSync(); |
| 45 } |
| 46 |
| 47 /// Returns a list of the paths to all files within [dir], which is |
| 48 /// assumed to be relative to the SDK's "tests" directory and having file |
| 49 /// [extension]. |
| 50 Iterable<String> listFiles(String dir, {String extension = ".dart"}) { |
| 51 return new Directory(p.join(testRoot, dir)) |
| 52 .listSync(recursive: true) |
| 53 .map((entry) { |
| 54 if (!entry.path.endsWith(extension)) return null; |
| 55 |
| 56 return entry.path; |
| 57 }).where((path) => path != null); |
| 58 } |
OLD | NEW |