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

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

Issue 9003017: Use blocking file access in tools/test.dart for multitest creation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | 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
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // Add the template, with no multitest lines, as a test with key 'none'. 105 // Add the template, with no multitest lines, as a test with key 'none'.
106 testsAsLines['none'] = testTemplate; 106 testsAsLines['none'] = testTemplate;
107 outcomes['none'] = ''; 107 outcomes['none'] = '';
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
Bill Hesse 2011/12/30 16:12:23 Oops.
116
117 void DoMultitest(String filename, 116 void DoMultitest(String filename,
118 String outputDir, 117 String outputDir,
119 String testDir, 118 String testDir,
120 Function doTest(String filename, 119 Function doTest(String filename,
121 bool isNegative, 120 bool isNegative,
122 [bool isNegativeIfChecked]), 121 [bool isNegativeIfChecked]),
123 Function multitestDone) { 122 Function multitestDone) {
124 // Each new test is a single String value in the Map tests. 123 // Each new test is a single String value in the Map tests.
125 Map<String, String> tests = new Map<String, String>(); 124 Map<String, String> tests = new Map<String, String>();
126 Map<String, String> outcomes = new Map<String, String>(); 125 Map<String, String> outcomes = new Map<String, String>();
127 ExtractTestsFromMultitest(filename, tests, outcomes); 126 ExtractTestsFromMultitest(filename, tests, outcomes);
128 127
129 String directory = CreateMultitestDirectory(outputDir, testDir); 128 String directory = CreateMultitestDirectory(outputDir, testDir);
130 String pathSeparator = new Platform().pathSeparator(); 129 String pathSeparator = new Platform().pathSeparator();
131 int start = filename.lastIndexOf(pathSeparator) + 1; 130 int start = filename.lastIndexOf(pathSeparator) + 1;
132 int end = filename.indexOf('.dart', start); 131 int end = filename.indexOf('.dart', start);
133 String baseFilename = filename.substring(start, end); 132 String baseFilename = filename.substring(start, end);
134 Iterator currentKey = tests.getKeys().iterator(); 133 for (String key in tests.getKeys()) {
135 WriteMultitestToFileAndQueueIt(tests, 134 final String filename = '$directory/${baseFilename}_$key.dart';
136 outcomes, 135 final File file = new File(filename);
137 currentKey,
138 '$directory$pathSeparator$baseFilename',
139 doTest,
140 multitestDone);
141 }
142 136
143 137 file.createSync();
144 // Write multiple tests to files, using tail recursion in a callback 138 RandomAccessFile openedFile = file.openSync(writable: true);
145 // to serialize the file operations, rather than opening all files at once. 139 var bytes = tests[key].charCodes();
146 WriteMultitestToFileAndQueueIt(Map<String, String> tests, 140 openedFile.writeListSync(bytes, 0, bytes.length);
147 Map<String, String> outcomes, 141 openedFile.closeSync();
148 Iterator currentKey, 142 var outcome = outcomes[key];
149 String basePath, 143 bool enableFatalTypeErrors = outcome.contains('static type error');
150 Function doTest, 144 bool isNegative = (outcome.contains('compile-time error') ||
151 Function done) { 145 outcome.contains('runtime error'));
152 if (!currentKey.hasNext()) { 146 bool isNegativeIfChecked = outcome.contains('dynamic type error');
153 done(); 147 doTest(filename,
154 return; 148 isNegative,
149 isNegativeIfChecked,
150 enableFatalTypeErrors);
155 } 151 }
156 final String key = currentKey.next(); 152 multitestDone();
157 final String filename = '${basePath}_$key.dart';
158 final File file = new File(filename);
159 file.errorHandler = (error) {
160 Expect.fail("Error creating temp file: $error");
161 };
162 file.createHandler = () {
163 file.open(writable: true);
164 };
165 file.openHandler = (RandomAccessFile openedFile) {
166 openedFile.noPendingWriteHandler =() {
167 openedFile.close();
168 };
169 openedFile.closeHandler = () {
170 var outcome = outcomes[key];
171 bool enableFatalTypeErrors = outcome.contains('static type error');
172 bool isNegative = (outcome.contains('compile-time error') ||
173 outcome.contains('runtime error'));
174 bool isNegativeIfChecked = outcome.contains('dynamic type error');
175 doTest(filename,
176 isNegative,
177 isNegativeIfChecked,
178 enableFatalTypeErrors);
179 WriteMultitestToFileAndQueueIt(tests,
180 outcomes,
181 currentKey,
182 basePath,
183 doTest,
184 done);
185 };
186 var bytes = tests[key].charCodes();
187 openedFile.writeList(bytes, 0, bytes.length);
188 };
189 file.create();
190 } 153 }
191 154
192 String CreateMultitestDirectory(String outputDir, String testDir) { 155 String CreateMultitestDirectory(String outputDir, String testDir) {
193 final String generatedTestDirectory = 'generated_tests'; 156 final String generatedTestDirectory = 'generated_tests';
194 Directory parentDir = new Directory(outputDir + generatedTestDirectory); 157 Directory parentDir = new Directory(outputDir + generatedTestDirectory);
195 if (!parentDir.existsSync()) { 158 if (!parentDir.existsSync()) {
196 parentDir.createSync(); 159 parentDir.createSync();
197 } 160 }
198 var split = testDir.split('/'); 161 var split = testDir.split('/');
199 var lastComponent = split.removeLast(); 162 var lastComponent = split.removeLast();
200 Expect.isTrue(lastComponent == 'src'); 163 Expect.isTrue(lastComponent == 'src');
201 String path = '${parentDir.path}/${split.last()}'; 164 String path = '${parentDir.path}/${split.last()}';
202 Directory dir = new Directory(path); 165 Directory dir = new Directory(path);
203 if (!dir.existsSync()) { 166 if (!dir.existsSync()) {
204 dir.createSync(); 167 dir.createSync();
205 } 168 }
206 return path; 169 return path;
207 } 170 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698