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

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

Issue 19774003: Bugfix in multitest.dart: Make sure we copy imported files to the generated_tests directory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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) 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 annotation.key = parts[0]; 143 annotation.key = parts[0];
144 annotation.rest = parts[1]; 144 annotation.rest = parts[1];
145 annotation.outcomesList = annotation.rest.split(',') 145 annotation.outcomesList = annotation.rest.split(',')
146 .map((s) => s.trim()).toList(); 146 .map((s) => s.trim()).toList();
147 return annotation; 147 return annotation;
148 } 148 }
149 } 149 }
150 150
151 // Find all relative imports and copy them into the dir that contains 151 // Find all relative imports and copy them into the dir that contains
152 // the generated tests. 152 // the generated tests.
153 Set<Path> _findAllRelativeImports(Path topLibrary) { 153 Set<String> _findAllRelativeImports(Path topLibrary) {
154 Set<Path> toSearch = new Set<Path>.from([topLibrary]); 154 Set<Path> toSearch = new Set<Path>.from([topLibrary]);
155 Set<Path> foundImports = new Set<Path>(); 155 Set<String> foundImports = new Set<String>();
156 Path libraryDir = topLibrary.directoryPath; 156 Path libraryDir = topLibrary.directoryPath;
157 // Matches #import( or #source( followed by " or ' followed by anything
158 // except dart:, dart-ext: or /, at the beginning of a line.
159 RegExp relativeImportRegExp = new RegExp( 157 RegExp relativeImportRegExp = new RegExp(
160 '^#(import|source)[(]["\'](?!(dart:|dart-ext:|/))([^"\']*)["\']'); 158 '^(import|part)\\s+["\'](?!(dart:|dart-ext:|package:|/))([^"\']*)["\']');
161 while (!toSearch.isEmpty) { 159 while (!toSearch.isEmpty) {
162 var thisPass = toSearch; 160 var thisPass = toSearch;
163 toSearch = new Set<Path>(); 161 toSearch = new Set<Path>();
164 for (Path filename in thisPass) { 162 for (Path filename in thisPass) {
165 File f = new File.fromPath(filename); 163 File f = new File.fromPath(filename);
166 for (String line in f.readAsLinesSync()) { 164 for (String line in f.readAsLinesSync()) {
167 Match match = relativeImportRegExp.firstMatch(line); 165 Match match = relativeImportRegExp.firstMatch(line);
168 if (match != null) { 166 if (match != null) {
169 Path relativePath = new Path(match.group(3)); 167 Path relativePath = new Path(match.group(3));
170 if (foundImports.contains(relativePath)) { 168 if (foundImports.contains(relativePath.toString())) {
171 continue; 169 continue;
172 } 170 }
173 if (relativePath.toString().contains('..')) { 171 if (relativePath.toString().contains('..')) {
174 // This is just for safety reasons, we don't want 172 // This is just for safety reasons, we don't want
175 // to unintentionally clobber files relative to the destination 173 // to unintentionally clobber files relative to the destination
176 // dir when copying them ove. 174 // dir when copying them ove.
177 print("relative paths containing .. are not allowed."); 175 print("relative paths containing .. are not allowed.");
178 exit(1); 176 exit(1);
179 } 177 }
180 foundImports.add(relativePath); 178 foundImports.add(relativePath.toString());
181 toSearch.add(libraryDir.join(relativePath)); 179 toSearch.add(libraryDir.join(relativePath));
182 } 180 }
183 } 181 }
184 } 182 }
185 } 183 }
186 return foundImports; 184 return foundImports;
187 } 185 }
188 186
189 Future doMultitest(Path filePath, String outputDir, Path suiteDir, 187 Future doMultitest(Path filePath, String outputDir, Path suiteDir,
190 CreateTest doTest) { 188 CreateTest doTest) {
191 // Each new test is a single String value in the Map tests. 189 // Each new test is a single String value in the Map tests.
192 Map<String, String> tests = new Map<String, String>(); 190 Map<String, String> tests = new Map<String, String>();
193 Map<String, Set<String>> outcomes = new Map<String, Set<String>>(); 191 Map<String, Set<String>> outcomes = new Map<String, Set<String>>();
194 ExtractTestsFromMultitest(filePath, tests, outcomes); 192 ExtractTestsFromMultitest(filePath, tests, outcomes);
195 193
196 Path sourceDir = filePath.directoryPath; 194 Path sourceDir = filePath.directoryPath;
197 Path targetDir = CreateMultitestDirectory(outputDir, suiteDir); 195 Path targetDir = CreateMultitestDirectory(outputDir, suiteDir);
198 assert(targetDir != null); 196 assert(targetDir != null);
199 197
200 // Copy all the relative imports of the multitest. 198 // Copy all the relative imports of the multitest.
201 Set<Path> importsToCopy = _findAllRelativeImports(filePath); 199 Set<String> importsToCopy = _findAllRelativeImports(filePath);
202 List<Future> futureCopies = []; 200 List<Future> futureCopies = [];
203 for (Path importPath in importsToCopy) { 201 for (String relativeImport in importsToCopy) {
202 Path importPath = new Path(relativeImport);
204 // Make sure the target directory exists. 203 // Make sure the target directory exists.
205 Path importDir = importPath.directoryPath; 204 Path importDir = importPath.directoryPath;
206 if (!importDir.isEmpty) { 205 if (!importDir.isEmpty) {
207 TestUtils.mkdirRecursive(targetDir, importDir); 206 TestUtils.mkdirRecursive(targetDir, importDir);
208 } 207 }
209 // Copy file. 208 // Copy file.
210 futureCopies.add(TestUtils.copyFile(sourceDir.join(importPath), 209 futureCopies.add(TestUtils.copyFile(sourceDir.join(importPath),
211 targetDir.join(importPath))); 210 targetDir.join(importPath)));
212 } 211 }
213 212
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // TestSuite.forDirectory. 255 // TestSuite.forDirectory.
257 split.removeLast(); 256 split.removeLast();
258 } 257 }
259 String path = '${generatedTestDir.path}/${split.last}'; 258 String path = '${generatedTestDir.path}/${split.last}';
260 Directory dir = new Directory(path); 259 Directory dir = new Directory(path);
261 if (!dir.existsSync()) { 260 if (!dir.existsSync()) {
262 dir.createSync(); 261 dir.createSync();
263 } 262 }
264 return new Path(new File(path).fullPathSync()); 263 return new Path(new File(path).fullPathSync());
265 } 264 }
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