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

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 8589020: Enable language and isolate tests using the dart test runner. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 #library("test_suite");
6
7 #import("status_file_parser.dart");
8 #import("test_runner.dart");
9
10 interface TestSuite {
11 void forEachTest(Function onTest, [Function onDone]);
12 }
13
14
15 class StandardTestSuite implements TestSuite {
16 Map configuration;
17 String directoryPath;
18 List<String> statusFilePaths;
19 Function doTest;
20 Function doDone;
21 String shellPath;
22 TestExpectations testExpectations;
23
24 StandardTestSuite(Map this.configuration,
25 String this.directoryPath,
26 List<String> this.statusFilePaths) {
27 shellPath = getDartShellFileName(configuration) ;
28 }
29
30
31 void isTestFile(String filename) => filename.endsWith("Test.dart");
32
33 void listRecursively() => false;
34
35 void complexStatusMatching() => false;
36
37 void forEachTest(Function onTest, [Function onDone = null]) {
38 doTest = onTest;
39 doDone = (ignore) => (onDone != null) ? onDone() : null;
40
41 // Read test expectations from status files.
42 testExpectations =
43 new TestExpectations(complexMatching: complexStatusMatching());
44 for (var statusFilePath in statusFilePaths) {
45 ReadTestExpectationsInto(testExpectations,
46 statusFilePath,
47 configuration);
48 }
49
50 processDirectory();
51 }
52
53 void processDirectory() {
54 directoryPath = getDirname(directoryPath);
55 Directory dir = new Directory(directoryPath);
56 dir.errorHandler = (s) {
57 throw s;
58 };
59 dir.fileHandler = processFile;
60 dir.doneHandler = doDone;
61 dir.list(recursive: listRecursively());
62 }
63
64 void processFile(String filename) {
65 if (!isTestFile(filename)) return;
66
67 // If patterns are given only list the files that match one of the
68 // patterns.
69 var patterns = configuration['patterns'];
70 if (!patterns.isEmpty() &&
71 !patterns.some((re) => re.hasMatch(filename))) {
72 return;
73 }
74
75 int start = filename.lastIndexOf('src' + new Platform().pathSeparator());
76 String testName = filename.substring(start + 4, filename.length - 5);
77 Set<String> expectations = testExpectations.expectations(testName);
78
79 if (expectations.contains(SKIP)) return;
80
81 var optionsFromFile = optionsFromFile(filename);
82 var argumentLists = argumentLists(filename, optionsFromFile);
83 for (var args in argumentLists) {
84 var timeout = configuration['timeout'];
85 var isNegative = optionsFromFile['isNegative'];
86 doTest(new TestCase(testName,
87 shellPath,
88 args,
89 timeout,
90 completeHandler,
91 expectations,
92 isNegative));
93 }
94 }
95
96 void completeHandler(TestCase testCase) {
97 }
98
99 List<List<String>> argumentLists(String filename, Map optionsFromFile) {
100 List args = ["--ignore-unrecognized-flags"];
101 if (configuration["checked"]) {
102 args.add("--enable_type_checks");
103 }
104 if (configuration["component"] == "leg") {
105 args.add("--enable_leg");
106 }
107 if (configuration["component"] == "dartc") {
108 if (configuration["mode"] == "release") {
109 args.add("--optimize");
110 }
111 }
112
113 List<String> dartOptions = optionsFromFile["dartOptions"];
114 args.addAll(dartOptions == null ? [filename] : dartOptions);
115
116 var result = new List<List<String>>();
117 List<List<String>> vmOptionsList = optionsFromFile["vmOptions"];
118 if (vmOptionsList.isEmpty()) {
119 result.add(args);
120 } else {
121 for (var vmOptions in vmOptionsList) {
122 vmOptions.addAll(args);
123 result.add(vmOptions);
124 }
125 }
126
127 return result;
128 }
129
130 Map optionsFromFile(String filename) {
131 RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)");
132 RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)");
133
134 // Read the entire file into a byte buffer and transform it to a
135 // String. This will treat the file as ascii but the only parts
136 // we are interested in will be ascii in any case.
137 File file = new File(filename);
138 file.openSync();
139 List chars = new List(file.lengthSync());
140 var offset = 0;
141 while (offset != chars.length) {
142 offset += file.readListSync(chars, offset, chars.length - offset);
143 }
144 file.closeSync();
145 String contents = new String.fromCharCodes(chars);
146 chars = null;
147
148 // Find the options in the file.
149 List<List> result = new List<List>();
150 List<String> dartOptions;
151 bool isNegative = false;
152
153 Iterable<Match> matches = testOptionsRegExp.allMatches(contents);
154 for (var match in matches) {
155 result.add(match[1].split(' ').filter((e) => e != ''));
156 }
157
158 matches = dartOptionsRegExp.allMatches(contents);
159 for (var match in matches) {
160 if (dartOptions != null) {
161 throw new Exception(
162 'More than one "// DartOptions=" line in test $filename');
163 }
164 dartOptions = match[1].split(' ').filter((e) => e != '');
165 }
166
167 if (contents.contains("@compile-error") ||
168 contents.contains("@runtime-error")) {
169 isNegative = true;
170 } else if (contents.contains("@dynamic-type-error") &&
171 configuration['checked']) {
172 isNegative = true;
173 }
174
175 return { "vmOptions": result,
176 "dartOptions": dartOptions,
177 "isNegative" : isNegative };
178 }
179 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698