Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Side by Side Diff: utils/testrunner/utils.dart

Issue 10897016: Testrunner for 3rd parties. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Read the contents of a file.
6 List<String> getFileContents(String filename, bool errorIfNoFile) {
7 File f = new File(filename);
8 if (!f.existsSync()) {
9 if (errorIfNoFile) {
10 throw new Exception('Config file $filename not found.');
11 } else {
12 return new List();
13 }
14 }
15 return f.readAsLinesSync();
16 }
17
18 // Copy a file from one place to another.
19 void copyFile(String sourceName, String destName) {
20 var sourceFile = new File(sourceName);
21 var destFile = new File(destName);
22 var istream = sourceFile.openInputStream();
23 var ostream = destFile.openOutputStream(FileMode.WRITE);
24 istream.pipe(ostream);
25 // TODO - make sure both streams are closed.
26 }
27
28 // Write a file with some content.
29 void createFile(String fileName, String contents) {
30 var file = new File(fileName);
31 var ostream = file.openOutputStream(FileMode.WRITE);
32 ostream.writeString(contents);
33 ostream.close();
34 }
35
36 // Given a path, make it absolute if it is relative.
37 String makePathAbsolute(String path) {
38 var p = new Path(path).canonicalize();
39 if (p.isAbsolute) {
40 return p.toString();
41 } else {
42 var cwd = new Path((new Directory.current()).path);
43 return cwd.join(p).toString();
44 }
45 }
46
47 // Create the list of all the test files that we are going to
48 // execute. Once we have finished enumerating them all, we
49 // call [onComplete].
50 // Is there a better way to write this that isn't using the
51 // dircount hackiness?
52 int dirCount;
53 void buildFileList(List dirs, RegExp filePat, bool recurse,
54 Function onComplete) {
55 var files = new List();
56 dirCount = 1;
57 for (var i = 0; i < dirs.length; i++) {
58 var path = dirs[i];
59 // Is this a regular file?
60 File f = new File(path);
61 if (f.existsSync()) {
62 if (filePat.hasMatch(path)) {
63 files.add(path);
64 }
65 } else { // Try treat it as a directory.
66 Directory d = new Directory(path);
67 if (d.existsSync()) {
68 ++dirCount;
69 var lister = d.list(recursive: recurse);
70 lister.onFile = (file) {
71 if (filePat.hasMatch(file)) {
72 files.add(file);
73 }
74 };
75 lister.onDone = (complete) {
76 if (complete && --dirCount == 0) {
77 onComplete(files);
78 }
79 };
80 } else { // Does not exist.
81 print('$path does not exist.');
82 }
83 }
84 }
85 if (--dirCount == 0) {
86 onComplete(files);
87 }
88 }
OLDNEW
« utils/testrunner/testrunner.dart ('K') | « utils/testrunner/testrunner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698