| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of testrunner; | |
| 6 | |
| 7 /** Create a file [fileName] and populate it with [contents]. */ | |
| 8 void writeFile(String fileName, String contents) { | |
| 9 var file = new File(fileName); | |
| 10 file.writeAsStringSync(contents); | |
| 11 } | |
| 12 | |
| 13 /** | |
| 14 * Read the contents of a file [fileName] into a [List] of [String]s. | |
| 15 * If the file does not exist and [errorIfNoFile] is true, throw an | |
| 16 * exception, else return an empty list. | |
| 17 */ | |
| 18 List<String> getFileContents(String filename, bool errorIfNoFile) { | |
| 19 File f = new File(filename); | |
| 20 if (!f.existsSync()) { | |
| 21 if (errorIfNoFile) { | |
| 22 throw new Exception('Config file $filename not found.'); | |
| 23 } else { | |
| 24 return new List(); | |
| 25 } | |
| 26 } | |
| 27 return f.readAsLinesSync(); | |
| 28 } | |
| 29 | |
| 30 /** | |
| 31 * Given a file path [path], make it absolute if it is relative, | |
| 32 * and return the result. | |
| 33 */ | |
| 34 String makePathAbsolute(String path) { | |
| 35 var p = new Path(path).canonicalize(); | |
| 36 if (p.isAbsolute) { | |
| 37 return p.toNativePath(); | |
| 38 } else { | |
| 39 var cwd = new Path(Directory.current.path); | |
| 40 return cwd.join(p).toNativePath(); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 /** | |
| 45 * Create the list of all the files in a set of directories | |
| 46 * ([dirs]) whose names match [filePat]. If [recurse] is true | |
| 47 * look at subdirectories too. An optional [excludePat] can be supplied | |
| 48 * and files or directories that match that will be excluded. | |
| 49 * [includeSymLinks] controls whether or not to include files that | |
| 50 * have symlinks in the traversed tree. | |
| 51 */ | |
| 52 List buildFileList(List dirs, RegExp filePat, bool recurse, | |
| 53 [RegExp excludePat, bool includeSymLinks = false]) { | |
| 54 var files = new List(); | |
| 55 for (var i = 0; i < dirs.length; i++) { | |
| 56 var path = dirs[i]; | |
| 57 if (excludePat != null && excludePat.hasMatch(path)) { | |
| 58 continue; | |
| 59 } | |
| 60 // Is this a regular file? | |
| 61 File f = new File(path); | |
| 62 if (f.existsSync()) { | |
| 63 if (filePat.hasMatch(path)) { | |
| 64 files.add(path); | |
| 65 } | |
| 66 } else { // Try treat it as a directory. | |
| 67 path = makePathAbsolute(path); | |
| 68 Directory d = new Directory(path); | |
| 69 if (d.existsSync()) { | |
| 70 var contents = d.listSync(recursive: recurse, | |
| 71 followLinks: includeSymLinks); | |
| 72 for (var entity in contents) { | |
| 73 if (entity is File) { | |
| 74 var file = entity.path; | |
| 75 if (filePat.hasMatch(file)) { | |
| 76 if (excludePat == null || !excludePat.hasMatch(file)) { | |
| 77 files.add(file); | |
| 78 } | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 } else { // Does not exist. | |
| 83 print('$path does not exist.'); | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 return files; | |
| 88 } | |
| 89 | |
| 90 /** | |
| 91 * Get the directory that testrunner lives in; we need it to import | |
| 92 * support files into the generated scripts. | |
| 93 */ | |
| 94 | |
| 95 String get runnerDirectory { | |
| 96 var libDirectory = makePathAbsolute(new Platform.script); | |
| 97 return libDirectory.substring(0, | |
| 98 libDirectory.lastIndexOf(Platform.pathSeparator)); | |
| 99 } | |
| 100 | |
| 101 /* | |
| 102 * Run an external process [cmd] with command line arguments [args]. | |
| 103 * Returns a [Future] for when the process terminates. | |
| 104 */ | |
| 105 Future _processHelper(String command, List<String> args, | |
| 106 {String workingDir}) { | |
| 107 var options = null; | |
| 108 if (workingDir != null) { | |
| 109 options = new ProcessOptions(); | |
| 110 options.workingDirectory = workingDir; | |
| 111 } | |
| 112 return Process.run(command, args, options) | |
| 113 .then((result) => result.exitCode) | |
| 114 .catchError((e) { | |
| 115 print("$command ${args.join(' ')}: ${e.toString()}"); | |
| 116 }); | |
| 117 } | |
| 118 | |
| OLD | NEW |