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

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

Issue 12417004: Update the test runner to use the new dart:io API (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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:async"; 7 import "dart:async";
8 import "dart:io"; 8 import "dart:io";
9 import "test_suite.dart"; 9 import "test_suite.dart";
10 import "utils.dart"; 10 import "utils.dart";
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 // Check that every key (other than the none case) has at least one outcome 111 // Check that every key (other than the none case) has at least one outcome
112 for (var outcomeKey in outcomes.keys) { 112 for (var outcomeKey in outcomes.keys) {
113 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) { 113 if (outcomeKey != 'none' && outcomes[outcomeKey].isEmpty) {
114 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes.\n" 114 Expect.fail("Test ${outcomeKey} has no valid annotated outcomes.\n"
115 "Expected one of: ${validMultitestOutcomes.toString()}"); 115 "Expected one of: ${validMultitestOutcomes.toString()}");
116 } 116 }
117 } 117 }
118 118
119 // Add the template, with no multitest lines, as a test with key 'none'. 119 // Add the template, with no mulpedBytitest lines, as a test with key 'none'.
kustermann 2013/03/13 13:37:56 What is this?
Søren Gjesse 2013/03/13 15:17:18 Done.
120 testsAsLines['none'] = testTemplate; 120 testsAsLines['none'] = testTemplate;
121 outcomes['none'] = new Set<String>(); 121 outcomes['none'] = new Set<String>();
122 122
123 // Copy all the tests into the output map tests, as multiline strings. 123 // Copy all the tests into the output map tests, as multiline strings.
124 for (String key in testsAsLines.keys) { 124 for (String key in testsAsLines.keys) {
125 tests[key] = testsAsLines[key].join(line_separator).concat(line_separator); 125 tests[key] = testsAsLines[key].join(line_separator).concat(line_separator);
126 } 126 }
127 } 127 }
128 128
129 // Represents a mutlitest annotation in the special /// comment. 129 // Represents a mutlitest annotation in the special /// comment.
130 class _Annotation { 130 class _Annotation {
131 String key; 131 String key;
132 String rest; 132 String rest;
133 List<String> outcomesList; 133 List<String> outcomesList;
134 _Annotation() {} 134 _Annotation() {}
135 factory _Annotation.from(String line) { 135 factory _Annotation.from(String line) {
136 if (!line.contains('///')) { 136 if (!line.contains('///')) {
137 return null; 137 return null;
138 } 138 }
139 var annotation = new _Annotation(); 139 var annotation = new _Annotation();
140 var parts = line.split('///')[1].split(':') 140 var parts = line.split('///')[1].split(':').map((s) => s.trim()).toList();
141 .mappedBy((s) => s.trim()).toList();
142 annotation.key = parts[0]; 141 annotation.key = parts[0];
143 annotation.rest = parts[1]; 142 annotation.rest = parts[1];
144 annotation.outcomesList = annotation.rest.split(',') 143 annotation.outcomesList = annotation.rest.split(',')
145 .mappedBy((s) => s.trim()).toList(); 144 .map((s) => s.trim()).toList();
146 return annotation; 145 return annotation;
147 } 146 }
148 } 147 }
149 148
150 // Find all relative imports and copy them into the dir that contains 149 // Find all relative imports and copy them into the dir that contains
151 // the generated tests. 150 // the generated tests.
152 Set<Path> _findAllRelativeImports(Path topLibrary) { 151 Set<Path> _findAllRelativeImports(Path topLibrary) {
153 Set<Path> toSearch = new Set<Path>.from([topLibrary]); 152 Set<Path> toSearch = new Set<Path>.from([topLibrary]);
154 Set<Path> foundImports = new HashSet<Path>(); 153 Set<Path> foundImports = new Set<Path>();
155 Path libraryDir = topLibrary.directoryPath; 154 Path libraryDir = topLibrary.directoryPath;
156 // Matches #import( or #source( followed by " or ' followed by anything 155 // Matches #import( or #source( pedByfollowed by " or ' followed by anything
kustermann 2013/03/13 13:37:56 What is this?
Søren Gjesse 2013/03/13 15:17:18 Done.
Bill Hesse 2013/03/13 16:07:00 This must be stray changes when someone converted
157 // except dart:, dart-ext: or /, at the beginning of a line. 156 // except dart:, dart-ext: or /, at the beginning of a line.
158 RegExp relativeImportRegExp = new RegExp( 157 RegExp relativeImportRegExp = new RegExp(
159 '^#(import|source)[(]["\'](?!(dart:|dart-ext:|/))([^"\']*)["\']'); 158 '^#(import|source)[(]["\'](?!(dart:|dart-ext:|/))([^"\']*)["\']');
160 while (!toSearch.isEmpty) { 159 while (!toSearch.isEmpty) {
161 var thisPass = toSearch; 160 var thisPass = toSearch;
162 toSearch = new HashSet<Path>(); 161 toSearch = new Set<Path>();
163 for (Path filename in thisPass) { 162 for (Path filename in thisPass) {
164 File f = new File.fromPath(filename); 163 File f = new File.fromPath(filename);
165 for (String line in f.readAsLinesSync()) { 164 for (String line in f.readAsLinesSync()) {
166 Match match = relativeImportRegExp.firstMatch(line); 165 Match match = relativeImportRegExp.firstMatch(line);
167 if (match != null) { 166 if (match != null) {
168 Path relativePath = new Path(match.group(3)); 167 Path relativePath = new Path(match.group(3));
169 if (foundImports.contains(relativePath)) { 168 if (foundImports.contains(relativePath)) {
170 continue; 169 continue;
171 } 170 }
172 if (relativePath.toString().contains('..')) { 171 if (relativePath.toString().contains('..')) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // Wait until all imports are copied before scheduling test cases. 211 // Wait until all imports are copied before scheduling test cases.
213 return Future.wait(futureCopies).then((_) { 212 return Future.wait(futureCopies).then((_) {
214 String baseFilename = filePath.filenameWithoutExtension; 213 String baseFilename = filePath.filenameWithoutExtension;
215 for (String key in tests.keys) { 214 for (String key in tests.keys) {
216 final Path multitestFilename = 215 final Path multitestFilename =
217 targetDir.append('${baseFilename}_$key.dart'); 216 targetDir.append('${baseFilename}_$key.dart');
218 final File file = new File.fromPath(multitestFilename); 217 final File file = new File.fromPath(multitestFilename);
219 218
220 file.createSync(); 219 file.createSync();
221 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 220 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
222 var bytes = tests[key].charCodes; 221 var bytes = tests[key].codeUnits;
223 openedFile.writeListSync(bytes, 0, bytes.length); 222 openedFile.writeListSync(bytes, 0, bytes.length);
224 openedFile.closeSync(); 223 openedFile.closeSync();
225 Set<String> outcome = outcomes[key]; 224 Set<String> outcome = outcomes[key];
226 bool enableFatalTypeErrors = outcome.contains('static type warning'); 225 bool enableFatalTypeErrors = outcome.contains('static type warning');
227 bool hasRuntimeErrors = outcome.contains('runtime error'); 226 bool hasRuntimeErrors = outcome.contains('runtime error');
228 bool hasCompileError = outcome.contains('compile-time error'); 227 bool hasCompileError = outcome.contains('compile-time error');
229 bool isNegativeIfChecked = outcome.contains('dynamic type error'); 228 bool isNegativeIfChecked = outcome.contains('dynamic type error');
230 doTest(multitestFilename, 229 doTest(multitestFilename,
231 hasCompileError, 230 hasCompileError,
232 hasRuntimeErrors, 231 hasRuntimeErrors,
(...skipping 22 matching lines...) Expand all
255 // TestSuite.forDirectory. 254 // TestSuite.forDirectory.
256 split.removeLast(); 255 split.removeLast();
257 } 256 }
258 String path = '${generatedTestDir.path}/${split.last}'; 257 String path = '${generatedTestDir.path}/${split.last}';
259 Directory dir = new Directory(path); 258 Directory dir = new Directory(path);
260 if (!dir.existsSync()) { 259 if (!dir.existsSync()) {
261 dir.createSync(); 260 dir.createSync();
262 } 261 }
263 return new Path(new File(path).fullPathSync()); 262 return new Path(new File(path).fullPathSync());
264 } 263 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698