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

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

Issue 8773036: Make multi tests work with DartC. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reworking 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 for (String key in testsAsLines.getKeys()) { 111 for (String key in testsAsLines.getKeys()) {
112 tests[key] = 112 tests[key] =
113 Strings.join(testsAsLines[key], line_separator) + line_separator; 113 Strings.join(testsAsLines[key], line_separator) + line_separator;
114 } 114 }
115 } 115 }
116 116
117 117
118 void DoMultitest(String filename, 118 void DoMultitest(String filename,
119 String buildDir, 119 String buildDir,
120 String testDir, 120 String testDir,
121 bool supportsFatalTypeErrors,
121 Function doTest(String filename, 122 Function doTest(String filename,
122 bool isNegative, 123 bool isNegative,
123 [bool isNegativeIfChecked]), 124 [bool isNegativeIfChecked]),
124 Function multitestDone) { 125 Function multitestDone) {
125 // Each new test is a single String value in the Map tests. 126 // Each new test is a single String value in the Map tests.
126 Map<String, String> tests = new Map<String, String>(); 127 Map<String, String> tests = new Map<String, String>();
127 Map<String, String> outcomes = new Map<String, String>(); 128 Map<String, String> outcomes = new Map<String, String>();
128 ExtractTestsFromMultitest(filename, tests, outcomes); 129 ExtractTestsFromMultitest(filename, tests, outcomes);
129 130
130 String directory = CreateMultitestDirectory(buildDir, testDir); 131 String directory = CreateMultitestDirectory(buildDir, testDir);
131 String pathSeparator = new Platform().pathSeparator(); 132 String pathSeparator = new Platform().pathSeparator();
132 int start = filename.lastIndexOf(pathSeparator) + 1; 133 int start = filename.lastIndexOf(pathSeparator) + 1;
133 int end = filename.indexOf('.dart', start); 134 int end = filename.indexOf('.dart', start);
134 String baseFilename = filename.substring(start, end); 135 String baseFilename = filename.substring(start, end);
135 Iterator currentKey = tests.getKeys().iterator(); 136 Iterator currentKey = tests.getKeys().iterator();
136 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey, 137 WriteMultitestToFileAndQueueIt(tests,
138 outcomes,
139 supportsFatalTypeErrors,
140 currentKey,
137 '$directory$pathSeparator$baseFilename', 141 '$directory$pathSeparator$baseFilename',
138 doTest, multitestDone); 142 doTest,
143 multitestDone);
139 } 144 }
140 145
141 146
142 // Write multiple tests to files, using tail recursion in a callback 147 // Write multiple tests to files, using tail recursion in a callback
143 // to serialize the file operations, rather than opening all files at once. 148 // to serialize the file operations, rather than opening all files at once.
144 WriteMultitestToFileAndQueueIt(Map<String, String> tests, 149 WriteMultitestToFileAndQueueIt(Map<String, String> tests,
145 Map<String, String> outcomes, 150 Map<String, String> outcomes,
151 bool supportsFatalTypeErrors,
146 Iterator currentKey, 152 Iterator currentKey,
147 String basePath, 153 String basePath,
148 Function doTest, 154 Function doTest,
149 Function done) { 155 Function done) {
150 if (!currentKey.hasNext()) { 156 if (!currentKey.hasNext()) {
151 done(); 157 done();
152 return; 158 return;
153 } 159 }
154 final String key = currentKey.next(); 160 final String key = currentKey.next();
155 final String filename = '${basePath}_$key.dart'; 161 final String filename = '${basePath}_$key.dart';
156 final File file = new File(filename); 162 final File file = new File(filename);
157 file.errorHandler = (error) { 163 file.errorHandler = (error) {
158 Expect.fail("Error creating temp file: $error"); 164 Expect.fail("Error creating temp file: $error");
159 }; 165 };
160 file.createHandler = () { 166 file.createHandler = () {
161 file.open(writable: true); 167 file.open(writable: true);
162 }; 168 };
163 file.openHandler = () { 169 file.openHandler = () {
164 var bytes = tests[key].charCodes(); 170 var bytes = tests[key].charCodes();
165 file.writeList(bytes, 0, bytes.length); 171 file.writeList(bytes, 0, bytes.length);
166 }; 172 };
167 file.noPendingWriteHandler =() { 173 file.noPendingWriteHandler =() {
168 file.close(); 174 file.close();
169 }; 175 };
170 file.closeHandler = () { 176 file.closeHandler = () {
171 var outcome = outcomes[key]; 177 var outcome = outcomes[key];
172 bool isNegative = outcome.contains('compile-time error') || 178 bool enableFatalTypeErrors = (supportsFatalTypeErrors &&
173 outcome.contains('runtime error'); 179 outcome.contains('static type error'));
180 bool isNegative = (outcome.contains('compile-time error') ||
181 outcome.contains('runtime error') ||
182 enableFatalTypeErrors);
174 bool isNegativeIfChecked = outcome.contains('type error'); 183 bool isNegativeIfChecked = outcome.contains('type error');
175 doTest(filename, isNegative, isNegativeIfChecked); 184 doTest(filename,
185 isNegative,
186 isNegativeIfChecked,
187 enableFatalTypeErrors);
176 // TODO(whesse): Register files and directories to be deleted. 188 // TODO(whesse): Register files and directories to be deleted.
177 // They should be registered in a persistent list, so they can 189 // They should be registered in a persistent list, so they can
Bill Hesse 2011/12/02 13:10:06 Remove this TODO - we are not planning to delete g
Mads Ager (google) 2011/12/02 13:32:49 Done.
178 // be deleted later even if the test script is interrupted. 190 // be deleted later even if the test script is interrupted.
179 WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey, 191 WriteMultitestToFileAndQueueIt(tests,
180 basePath, doTest, done); 192 outcomes,
193 supportsFatalTypeErrors,
194 currentKey,
195 basePath,
196 doTest,
197 done);
181 }; 198 };
182 file.create(); 199 file.create();
183 } 200 }
184 201
185 String CreateMultitestDirectory(String buildDir, String testDir) { 202 String CreateMultitestDirectory(String buildDir, String testDir) {
186 final String generatedTestDirectory = 'generated_tests/'; 203 final String generatedTestDirectory = 'generated_tests/';
187 Directory parent_dir = new Directory(buildDir + generatedTestDirectory); 204 Directory parent_dir = new Directory(buildDir + generatedTestDirectory);
188 if (!parent_dir.existsSync()) { 205 if (!parent_dir.existsSync()) {
189 parent_dir.createSync(); 206 parent_dir.createSync();
190 } 207 }
191 var split = testDir.split(new Platform().pathSeparator()); 208 var split = testDir.split(new Platform().pathSeparator());
192 var lastComponent = split.removeLast(); 209 var lastComponent = split.removeLast();
193 Expect.isTrue(lastComponent == 'src'); 210 Expect.isTrue(lastComponent == 'src');
194 String path = parent_dir.path + split.last(); 211 String path = parent_dir.path + split.last();
195 Directory dir = new Directory(path); 212 Directory dir = new Directory(path);
196 if (!dir.existsSync()) { 213 if (!dir.existsSync()) {
197 dir.createSync(); 214 dir.createSync();
198 } 215 }
199 return path; 216 return path;
200 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698