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

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

Issue 8883017: Split File into File and RandomAccessFile. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. 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
« no previous file with comments | « tests/standalone/src/FileTest.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 30 matching lines...) Expand all
41 // aaa 41 // aaa
42 // ddd /// 07: static type error 42 // ddd /// 07: static type error
43 // eee 43 // eee
44 44
45 void ExtractTestsFromMultitest(String filename, 45 void ExtractTestsFromMultitest(String filename,
46 Map<String, String> tests, 46 Map<String, String> tests,
47 Map<String, String> outcomes) { 47 Map<String, String> outcomes) {
48 // Read the entire file into a byte buffer and transform it to a 48 // Read the entire file into a byte buffer and transform it to a
49 // String. This will treat the file as ascii but the only parts 49 // String. This will treat the file as ascii but the only parts
50 // we are interested in will be ascii in any case. 50 // we are interested in will be ascii in any case.
51 File file = new File(filename); 51 RandomAccessFile file = (new File(filename)).openSync();
52 file.openSync();
53 List chars = new List(file.lengthSync()); 52 List chars = new List(file.lengthSync());
54 int offset = 0; 53 int offset = 0;
55 while (offset != chars.length) { 54 while (offset != chars.length) {
56 offset += file.readListSync(chars, offset, chars.length - offset); 55 offset += file.readListSync(chars, offset, chars.length - offset);
57 } 56 }
58 file.closeSync(); 57 file.closeSync();
59 String contents = new String.fromCharCodes(chars); 58 String contents = new String.fromCharCodes(chars);
60 chars = null; 59 chars = null;
61 int first_newline = contents.indexOf('\n'); 60 int first_newline = contents.indexOf('\n');
62 final String line_separator = 61 final String line_separator =
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 158 }
160 final String key = currentKey.next(); 159 final String key = currentKey.next();
161 final String filename = '${basePath}_$key.dart'; 160 final String filename = '${basePath}_$key.dart';
162 final File file = new File(filename); 161 final File file = new File(filename);
163 file.errorHandler = (error) { 162 file.errorHandler = (error) {
164 Expect.fail("Error creating temp file: $error"); 163 Expect.fail("Error creating temp file: $error");
165 }; 164 };
166 file.createHandler = () { 165 file.createHandler = () {
167 file.open(writable: true); 166 file.open(writable: true);
168 }; 167 };
169 file.openHandler = () { 168 file.openHandler = (RandomAccessFile openedFile) {
169 openedFile.noPendingWriteHandler =() {
170 openedFile.close();
171 };
172 openedFile.closeHandler = () {
173 var outcome = outcomes[key];
174 bool enableFatalTypeErrors = (supportsFatalTypeErrors &&
175 outcome.contains('static type error'));
176 bool isNegative = (outcome.contains('compile-time error') ||
177 outcome.contains('runtime error') ||
178 enableFatalTypeErrors);
179 bool isNegativeIfChecked = outcome.contains('dynamic type error');
180 doTest(filename,
181 isNegative,
182 isNegativeIfChecked,
183 enableFatalTypeErrors);
184 WriteMultitestToFileAndQueueIt(tests,
185 outcomes,
186 supportsFatalTypeErrors,
187 currentKey,
188 basePath,
189 doTest,
190 done);
191 };
170 var bytes = tests[key].charCodes(); 192 var bytes = tests[key].charCodes();
171 file.writeList(bytes, 0, bytes.length); 193 openedFile.writeList(bytes, 0, bytes.length);
172 };
173 file.noPendingWriteHandler =() {
174 file.close();
175 };
176 file.closeHandler = () {
177 var outcome = outcomes[key];
178 bool enableFatalTypeErrors = (supportsFatalTypeErrors &&
179 outcome.contains('static type error'));
180 bool isNegative = (outcome.contains('compile-time error') ||
181 outcome.contains('runtime error') ||
182 enableFatalTypeErrors);
183 bool isNegativeIfChecked = outcome.contains('dynamic type error');
184 doTest(filename,
185 isNegative,
186 isNegativeIfChecked,
187 enableFatalTypeErrors);
188 WriteMultitestToFileAndQueueIt(tests,
189 outcomes,
190 supportsFatalTypeErrors,
191 currentKey,
192 basePath,
193 doTest,
194 done);
195 }; 194 };
196 file.create(); 195 file.create();
197 } 196 }
198 197
199 String CreateMultitestDirectory(String buildDir, String testDir) { 198 String CreateMultitestDirectory(String buildDir, String testDir) {
200 final String generatedTestDirectory = 'generated_tests'; 199 final String generatedTestDirectory = 'generated_tests';
201 Directory parentDir = new Directory(buildDir + generatedTestDirectory); 200 Directory parentDir = new Directory(buildDir + generatedTestDirectory);
202 if (!parentDir.existsSync()) { 201 if (!parentDir.existsSync()) {
203 parentDir.createSync(); 202 parentDir.createSync();
204 } 203 }
205 var split = testDir.split('/'); 204 var split = testDir.split('/');
206 var lastComponent = split.removeLast(); 205 var lastComponent = split.removeLast();
207 Expect.isTrue(lastComponent == 'src'); 206 Expect.isTrue(lastComponent == 'src');
208 String path = '${parentDir.path}/${split.last()}'; 207 String path = '${parentDir.path}/${split.last()}';
209 Directory dir = new Directory(path); 208 Directory dir = new Directory(path);
210 if (!dir.existsSync()) { 209 if (!dir.existsSync()) {
211 dir.createSync(); 210 dir.createSync();
212 } 211 }
213 return path; 212 return path;
214 } 213 }
OLDNEW
« no previous file with comments | « tests/standalone/src/FileTest.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698