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

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

Issue 9662063: Fix some type and logical errors in test.dart, found by the Dart editor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
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 #import("dart:io"); 7 #import("dart:io");
8 #import("test_suite.dart"); 8 #import("test_suite.dart");
9 9
10 // Multitests are Dart test scripts containing lines of the form 10 // Multitests are Dart test scripts containing lines of the form
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // aaa 50 // aaa
51 // ddd /// 07: static type warning, dynamic type error 51 // ddd /// 07: static type warning, dynamic type error
52 // eee 52 // eee
53 53
54 void ExtractTestsFromMultitest(String filename, 54 void ExtractTestsFromMultitest(String filename,
55 Map<String, String> tests, 55 Map<String, String> tests,
56 Map<String, Set<String>> outcomes) { 56 Map<String, Set<String>> outcomes) {
57 // Read the entire file into a byte buffer and transform it to a 57 // Read the entire file into a byte buffer and transform it to a
58 // String. This will treat the file as ascii but the only parts 58 // String. This will treat the file as ascii but the only parts
59 // we are interested in will be ascii in any case. 59 // we are interested in will be ascii in any case.
60 RandomAccessFile file = (new File(filename)).openSync(); 60 RandomAccessFile file = (new File(filename)).openSync(FileMode.READ);
61 List chars = new List(file.lengthSync()); 61 List chars = new List(file.lengthSync());
62 int offset = 0; 62 int offset = 0;
63 while (offset != chars.length) { 63 while (offset != chars.length) {
64 offset += file.readListSync(chars, offset, chars.length - offset); 64 offset += file.readListSync(chars, offset, chars.length - offset);
65 } 65 }
66 file.closeSync(); 66 file.closeSync();
67 String contents = new String.fromCharCodes(chars); 67 String contents = new String.fromCharCodes(chars);
68 chars = null; 68 chars = null;
69 int first_newline = contents.indexOf('\n'); 69 int first_newline = contents.indexOf('\n');
70 final String line_separator = 70 final String line_separator =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 void DoMultitest(String filename, 165 void DoMultitest(String filename,
166 String outputDir, 166 String outputDir,
167 String testDir, 167 String testDir,
168 // TODO(zundel): Are the boolean flags now redundant 168 // TODO(zundel): Are the boolean flags now redundant
169 // with the 'multitestOutcome' field? 169 // with the 'multitestOutcome' field?
170 Function doTest(String filename, 170 Function doTest(String filename,
171 bool isNegative, 171 bool isNegative,
172 [bool isNegativeIfChecked, 172 [bool isNegativeIfChecked,
173 bool hasFatalTypeErrors, 173 bool hasFatalTypeErrors,
174 bool hasRuntimeErrors, 174 bool hasRuntimeErrors,
175 String multitestOutcome]), 175 Set<String> multitestOutcome]),
176 Function multitestDone) { 176 Function multitestDone) {
177 // Each new test is a single String value in the Map tests. 177 // Each new test is a single String value in the Map tests.
178 Map<String, String> tests = new Map<String, String>(); 178 Map<String, String> tests = new Map<String, String>();
179 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); 179 Map<String, Set<String>> outcomes = new Map<String, Set<String>>();
180 ExtractTestsFromMultitest(filename, tests, outcomes); 180 ExtractTestsFromMultitest(filename, tests, outcomes);
181 181
182 String directory = CreateMultitestDirectory(outputDir, testDir); 182 String directory = CreateMultitestDirectory(outputDir, testDir);
183 Expect.isNotNull(directory); 183 Expect.isNotNull(directory);
184 String pathSep = new Platform().pathSeparator(); 184 String pathSep = new Platform().pathSeparator();
185 int start = filename.lastIndexOf(pathSep) + 1; 185 int start = filename.lastIndexOf(pathSep) + 1;
186 int end = filename.indexOf('.dart', start); 186 int end = filename.indexOf('.dart', start);
187 String baseFilename = filename.substring(start, end); 187 String baseFilename = filename.substring(start, end);
188 String sourceDirectory = filename.substring(0, start - 1); 188 String sourceDirectory = filename.substring(0, start - 1);
189 Set<String> importsToCopy = _findAllRelativeImports(filename); 189 Set<String> importsToCopy = _findAllRelativeImports(filename);
190 Directory destDir = new Directory("directory"); 190 Directory destDir = new Directory("directory");
191 for (String import in importsToCopy) { 191 for (String import in importsToCopy) {
192 File source = new File('$sourceDirectory/$import'); 192 File source = new File('$sourceDirectory/$import');
193 var dest = new File('$directory/$import'); 193 var dest = new File('$directory/$import');
194 var basenameStart = import.lastIndexOf('/'); 194 var basenameStart = import.lastIndexOf('/');
195 if (basenameStart > 0) { 195 if (basenameStart > 0) {
196 // make sure we have a dir for it 196 // make sure we have a dir for it
197 var importDir = import.substring(0, basenameStart); 197 var importDir = import.substring(0, basenameStart);
198 TestUtils.mkdirRecursive(directory, importDir); 198 TestUtils.mkdirRecursive(directory, importDir);
199 } 199 }
200 TestUtils.copyFile(source, dest); 200 TestUtils.copyFile(source, dest);
201 } 201 }
202 for (String key in tests.getKeys()) { 202 for (String key in tests.getKeys()) {
203 final String filename = '$directory/${baseFilename}_$key.dart'; 203 final String multitestFilename = '$directory/${baseFilename}_$key.dart';
204 final File file = new File(filename); 204 final File file = new File(multitestFilename);
205 205
206 file.createSync(); 206 file.createSync();
207 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 207 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
208 var bytes = tests[key].charCodes(); 208 var bytes = tests[key].charCodes();
209 openedFile.writeListSync(bytes, 0, bytes.length); 209 openedFile.writeListSync(bytes, 0, bytes.length);
210 openedFile.closeSync(); 210 openedFile.closeSync();
211 Set<String> outcome = outcomes[key]; 211 Set<String> outcome = outcomes[key];
212 bool enableFatalTypeErrors = outcome.contains('static type warning'); 212 bool enableFatalTypeErrors = outcome.contains('static type warning');
213 bool hasRuntimeErrors = outcome.contains('runtime error'); 213 bool hasRuntimeErrors = outcome.contains('runtime error');
214 bool isNegative = hasRuntimeErrors 214 bool isNegative = hasRuntimeErrors
215 || outcome.contains('compile-time error'); 215 || outcome.contains('compile-time error');
216 bool isNegativeIfChecked = outcome.contains('dynamic type error'); 216 bool isNegativeIfChecked = outcome.contains('dynamic type error');
217 doTest(filename, 217 doTest(multitestFilename,
218 isNegative, 218 isNegative,
219 isNegativeIfChecked, 219 isNegativeIfChecked,
220 enableFatalTypeErrors, 220 enableFatalTypeErrors,
221 hasRuntimeErrors, 221 hasRuntimeErrors,
222 outcome); 222 outcome);
223 } 223 }
224 multitestDone(); 224 multitestDone();
225 } 225 }
226 226
227 227
228 String CreateMultitestDirectory(String outputDir, String testDir) { 228 String CreateMultitestDirectory(String outputDir, String testDir) {
229 final String generatedTestDirectory = 'generated_tests'; 229 final String generatedTestDirectory = 'generated_tests';
230 Directory generatedTestDir = new Directory('$outputDir/generated_tests'); 230 Directory generatedTestDir = new Directory('$outputDir/generated_tests');
231 if (!new Directory(outputDir).existsSync()) { 231 if (!new Directory(outputDir).existsSync()) {
232 new Directory(outputDir).createSync(); 232 new Directory(outputDir).createSync();
233 } 233 }
234 if (!generatedTestDir.existsSync()) { 234 if (!generatedTestDir.existsSync()) {
235 generatedTestDir.createSync(); 235 generatedTestDir.createSync();
236 } 236 }
237 var split = testDir.split('/'); 237 var split = testDir.split('/');
238 var lastComponent = split.removeLast(); 238 var lastComponent = split.removeLast();
239 Expect.isTrue(lastComponent == 'src'); 239 Expect.isTrue(lastComponent == 'src');
240 String path = '${generatedTestDir.path}/${split.last()}'; 240 String path = '${generatedTestDir.path}/${split.last()}';
241 Directory dir = new Directory(path); 241 Directory dir = new Directory(path);
242 if (!dir.existsSync()) { 242 if (!dir.existsSync()) {
243 dir.createSync(); 243 dir.createSync();
244 } 244 }
245 return path; 245 return path;
246 } 246 }
OLDNEW
« no previous file with comments | « no previous file | tools/testing/dart/test_options.dart » ('j') | tools/testing/dart/test_runner.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698