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

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

Issue 8872064: Cache the tests across configurations in the test scripts. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library("multitest"); 5 #library("multitest");
6 6
7 // Multitests are Dart test scripts containing lines of the form 7 // Multitests are Dart test scripts containing lines of the form
8 // " [some dart code] /// [key]: [error type]" 8 // " [some dart code] /// [key]: [error type]"
9 // 9 //
10 // For each key in the file, a new test file is made containing all 10 // For each key in the file, a new test file is made containing all
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 // Copy all the tests into the output map tests, as multiline strings. 109 // Copy all the tests into the output map tests, as multiline strings.
110 for (String key in testsAsLines.getKeys()) { 110 for (String key in testsAsLines.getKeys()) {
111 tests[key] = 111 tests[key] =
112 Strings.join(testsAsLines[key], line_separator) + line_separator; 112 Strings.join(testsAsLines[key], line_separator) + line_separator;
113 } 113 }
114 } 114 }
115 115
116 116
117 void DoMultitest(String filename, 117 void DoMultitest(String filename,
118 String buildDir, 118 String outputDir,
119 String testDir, 119 String testDir,
120 bool supportsFatalTypeErrors,
121 Function doTest(String filename, 120 Function doTest(String filename,
122 bool isNegative, 121 bool isNegative,
123 [bool isNegativeIfChecked]), 122 [bool isNegativeIfChecked]),
124 Function multitestDone) { 123 Function multitestDone) {
125 // Each new test is a single String value in the Map tests. 124 // Each new test is a single String value in the Map tests.
126 Map<String, String> tests = new Map<String, String>(); 125 Map<String, String> tests = new Map<String, String>();
127 Map<String, String> outcomes = new Map<String, String>(); 126 Map<String, String> outcomes = new Map<String, String>();
128 ExtractTestsFromMultitest(filename, tests, outcomes); 127 ExtractTestsFromMultitest(filename, tests, outcomes);
129 128
130 String directory = CreateMultitestDirectory(buildDir, testDir); 129 String directory = CreateMultitestDirectory(outputDir, testDir);
131 String pathSeparator = new Platform().pathSeparator(); 130 String pathSeparator = new Platform().pathSeparator();
132 int start = filename.lastIndexOf(pathSeparator) + 1; 131 int start = filename.lastIndexOf(pathSeparator) + 1;
133 int end = filename.indexOf('.dart', start); 132 int end = filename.indexOf('.dart', start);
134 String baseFilename = filename.substring(start, end); 133 String baseFilename = filename.substring(start, end);
135 Iterator currentKey = tests.getKeys().iterator(); 134 Iterator currentKey = tests.getKeys().iterator();
136 WriteMultitestToFileAndQueueIt(tests, 135 WriteMultitestToFileAndQueueIt(tests,
137 outcomes, 136 outcomes,
138 supportsFatalTypeErrors,
139 currentKey, 137 currentKey,
140 '$directory$pathSeparator$baseFilename', 138 '$directory$pathSeparator$baseFilename',
141 doTest, 139 doTest,
142 multitestDone); 140 multitestDone);
143 } 141 }
144 142
145 143
146 // Write multiple tests to files, using tail recursion in a callback 144 // Write multiple tests to files, using tail recursion in a callback
147 // to serialize the file operations, rather than opening all files at once. 145 // to serialize the file operations, rather than opening all files at once.
148 WriteMultitestToFileAndQueueIt(Map<String, String> tests, 146 WriteMultitestToFileAndQueueIt(Map<String, String> tests,
149 Map<String, String> outcomes, 147 Map<String, String> outcomes,
150 bool supportsFatalTypeErrors,
151 Iterator currentKey, 148 Iterator currentKey,
152 String basePath, 149 String basePath,
153 Function doTest, 150 Function doTest,
154 Function done) { 151 Function done) {
155 if (!currentKey.hasNext()) { 152 if (!currentKey.hasNext()) {
156 done(); 153 done();
157 return; 154 return;
158 } 155 }
159 final String key = currentKey.next(); 156 final String key = currentKey.next();
160 final String filename = '${basePath}_$key.dart'; 157 final String filename = '${basePath}_$key.dart';
161 final File file = new File(filename); 158 final File file = new File(filename);
162 file.errorHandler = (error) { 159 file.errorHandler = (error) {
163 Expect.fail("Error creating temp file: $error"); 160 Expect.fail("Error creating temp file: $error");
164 }; 161 };
165 file.createHandler = () { 162 file.createHandler = () {
166 file.open(writable: true); 163 file.open(writable: true);
167 }; 164 };
168 file.openHandler = (RandomAccessFile openedFile) { 165 file.openHandler = (RandomAccessFile openedFile) {
169 openedFile.noPendingWriteHandler =() { 166 openedFile.noPendingWriteHandler =() {
170 openedFile.close(); 167 openedFile.close();
171 }; 168 };
172 openedFile.closeHandler = () { 169 openedFile.closeHandler = () {
173 var outcome = outcomes[key]; 170 var outcome = outcomes[key];
174 bool enableFatalTypeErrors = (supportsFatalTypeErrors && 171 bool enableFatalTypeErrors = outcome.contains('static type error');
175 outcome.contains('static type error'));
176 bool isNegative = (outcome.contains('compile-time error') || 172 bool isNegative = (outcome.contains('compile-time error') ||
177 outcome.contains('runtime error') || 173 outcome.contains('runtime error'));
178 enableFatalTypeErrors);
179 bool isNegativeIfChecked = outcome.contains('dynamic type error'); 174 bool isNegativeIfChecked = outcome.contains('dynamic type error');
180 doTest(filename, 175 doTest(filename,
181 isNegative, 176 isNegative,
182 isNegativeIfChecked, 177 isNegativeIfChecked,
183 enableFatalTypeErrors); 178 enableFatalTypeErrors);
184 WriteMultitestToFileAndQueueIt(tests, 179 WriteMultitestToFileAndQueueIt(tests,
185 outcomes, 180 outcomes,
186 supportsFatalTypeErrors,
187 currentKey, 181 currentKey,
188 basePath, 182 basePath,
189 doTest, 183 doTest,
190 done); 184 done);
191 }; 185 };
192 var bytes = tests[key].charCodes(); 186 var bytes = tests[key].charCodes();
193 openedFile.writeList(bytes, 0, bytes.length); 187 openedFile.writeList(bytes, 0, bytes.length);
194 }; 188 };
195 file.create(); 189 file.create();
196 } 190 }
197 191
198 String CreateMultitestDirectory(String buildDir, String testDir) { 192 String CreateMultitestDirectory(String outputDir, String testDir) {
199 final String generatedTestDirectory = 'generated_tests'; 193 final String generatedTestDirectory = 'generated_tests';
200 Directory parentDir = new Directory(buildDir + generatedTestDirectory); 194 Directory parentDir = new Directory(outputDir + generatedTestDirectory);
201 if (!parentDir.existsSync()) { 195 if (!parentDir.existsSync()) {
202 parentDir.createSync(); 196 parentDir.createSync();
203 } 197 }
204 var split = testDir.split('/'); 198 var split = testDir.split('/');
205 var lastComponent = split.removeLast(); 199 var lastComponent = split.removeLast();
206 Expect.isTrue(lastComponent == 'src'); 200 Expect.isTrue(lastComponent == 'src');
207 String path = '${parentDir.path}/${split.last()}'; 201 String path = '${parentDir.path}/${split.last()}';
208 Directory dir = new Directory(path); 202 Directory dir = new Directory(path);
209 if (!dir.existsSync()) { 203 if (!dir.existsSync()) {
210 dir.createSync(); 204 dir.createSync();
211 } 205 }
212 return path; 206 return path;
213 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698