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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« utils/testrunner/options.dart ('K') | « utils/testrunner/testrunner.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/testrunner/utils.dart
===================================================================
--- utils/testrunner/utils.dart (revision 0)
+++ utils/testrunner/utils.dart (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Read the contents of a file.
+List<String> getFileContents(String filename, bool errorIfNoFile) {
+ File f = new File(filename);
+ if (!f.existsSync()) {
+ if (errorIfNoFile) {
+ throw new Exception('Config file $filename not found.');
+ } else {
+ return new List();
+ }
+ }
+ return f.readAsLinesSync();
+}
+
+// Copy a file from one place to another.
+void copyFile(String sourceName, String destName) {
+ var sourceFile = new File(sourceName);
+ var destFile = new File(destName);
+ var istream = sourceFile.openInputStream();
+ var ostream = destFile.openOutputStream(FileMode.WRITE);
+ istream.pipe(ostream);
+ // TODO - make sure both streams are closed.
+}
+
+// Write a file with some content.
+void createFile(String fileName, String contents) {
+ var file = new File(fileName);
+ var ostream = file.openOutputStream(FileMode.WRITE);
+ ostream.writeString(contents);
+ ostream.close();
+}
+
+// Given a path, make it absolute if it is relative.
+String makePathAbsolute(String path) {
+ var p = new Path(path).canonicalize();
+ if (p.isAbsolute) {
+ return p.toString();
+ } else {
+ var cwd = new Path((new Directory.current()).path);
+ return cwd.join(p).toString();
+ }
+}
+
+// Create the list of all the test files that we are going to
Siggi Cherem (dart-lang) 2012/08/29 01:05:55 nit: make into dartdoc (probably needs to be moved
gram 2012/08/29 20:12:26 Done.
+// execute. Once we have finished enumerating them all, we
+// call [onComplete].
+// Is there a better way to write this that isn't using the
+// dircount hackiness?
Siggi Cherem (dart-lang) 2012/08/29 01:05:55 another way is to use Futures.wait: var futures
gram 2012/08/29 20:12:26 Interesting.
+int dirCount;
Siggi Cherem (dart-lang) 2012/08/29 01:05:55 if you continue with dirCount, I think you can mak
gram 2012/08/29 20:12:26 Done.
+void buildFileList(List dirs, RegExp filePat, bool recurse,
+ Function onComplete) {
+ var files = new List();
+ dirCount = 1;
+ for (var i = 0; i < dirs.length; i++) {
+ var path = dirs[i];
+ // Is this a regular file?
+ File f = new File(path);
+ if (f.existsSync()) {
+ if (filePat.hasMatch(path)) {
+ files.add(path);
+ }
+ } else { // Try treat it as a directory.
+ Directory d = new Directory(path);
+ if (d.existsSync()) {
+ ++dirCount;
+ var lister = d.list(recursive: recurse);
+ lister.onFile = (file) {
+ if (filePat.hasMatch(file)) {
+ files.add(file);
+ }
+ };
+ lister.onDone = (complete) {
+ if (complete && --dirCount == 0) {
+ onComplete(files);
+ }
+ };
+ } else { // Does not exist.
+ print('$path does not exist.');
+ }
+ }
+ }
+ if (--dirCount == 0) {
+ onComplete(files);
+ }
+}
« utils/testrunner/options.dart ('K') | « utils/testrunner/testrunner.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698