Chromium Code Reviews| Index: tools/testing/dart/multitest.dart |
| diff --git a/tools/testing/dart/multitest.dart b/tools/testing/dart/multitest.dart |
| index a637c987e23872ae08b9ca0b87ac5a08127bd96f..55a488a8489aa9e937d88d0f4b7ba9ef5f05cd0d 100644 |
| --- a/tools/testing/dart/multitest.dart |
| +++ b/tools/testing/dart/multitest.dart |
| @@ -77,10 +77,6 @@ void ExtractTestsFromMultitest(String filename, |
| // time we see a multitest line with a new key. |
| Map<String, List<String>> testsAsLines = new Map<String, List<String>>(); |
| - // Matches #import( or #source( followed by " or ' followed by anything |
| - // except dart: or /, at the beginning of a line. |
| - RegExp relativeImportRegExp = |
| - const RegExp('^#(import|source)[(]["\'](?!(dart:|/))'); |
| int lineCount = 0; |
| for (String line in lines) { |
| lineCount++; |
| @@ -102,11 +98,6 @@ void ExtractTestsFromMultitest(String filename, |
| testTemplate.add(line); |
| for (var test in testsAsLines.getValues()) test.add(line); |
| } |
| - // Warn if any import or source tags have relative paths. |
| - if (relativeImportRegExp.hasMatch(line)) { |
| - print('Warning: Multitest cannot contain relative imports:'); |
| - print(' $filename: $line'); |
| - } |
| } |
| // Add the template, with no multitest lines, as a test with key 'none'. |
| testsAsLines['none'] = testTemplate; |
| @@ -119,6 +110,50 @@ void ExtractTestsFromMultitest(String filename, |
| } |
| } |
| +void _copyFile(File source, File dest) { |
|
zundel
2012/03/01 06:06:58
is there already a canned way to do this somewhere
Bill Hesse
2012/03/01 15:01:52
Not that I know of, except by calling the shell.
zundel
2012/03/01 18:06:01
Moved to TestUtils class.
|
| + List contents = source.readAsBytesSync(); |
| + RandomAccessFile handle = dest.openSync(FileMode.WRITE); |
|
Bill Hesse
2012/03/01 15:01:52
This will not work except for files in the same di
zundel
2012/03/01 18:06:01
the generated test files don't go away between tes
|
| + handle.writeListSync(contents, 0, contents.length); |
| + handle.closeSync(); |
| +} |
| + |
| +// Find all relative imports and copy them into the dir that contains |
| +// the generated tests. |
| +Set<String> _findAllRelativeImports(String topLibrary) { |
| + Set<String> toSearch = new Set<String>.from([topLibrary]); |
| + Set<String> foundImports = new HashSet<String>(); |
| + String pathSep = new Platform().pathSeparator(); |
|
Bill Hesse
2012/03/01 15:01:52
Rather than use pathSeparator, I would use "/" eve
zundel
2012/03/01 18:06:01
Done.
|
| + int end = topLibrary.lastIndexOf(pathSep); |
| + String libraryDir = topLibrary.substring(0, end); |
| + |
| + // Matches #import( or #source( followed by " or ' followed by anything |
| + // except dart: or /, at the beginning of a line. |
| + RegExp relativeImportRegExp1 = |
| + const RegExp('^#(import|source)[(]["\'](?!(dart:|/))'); |
| + // Like the above, but captures the path in the import |
| + RegExp relativeImportRegExp2 = |
| + const RegExp('^#(import|source)[(]["\']([^"\']*)["\']'); |
| + while (!toSearch.isEmpty()) { |
| + var thisPass = toSearch; |
| + toSearch = new HashSet<String>(); |
| + for (String filename in thisPass) { |
| + File f = new File(filename); |
| + for (String line in f.readAsLinesSync()) { |
| + if (relativeImportRegExp1.hasMatch(line)) { |
|
Bill Hesse
2012/03/01 15:01:52
I think you can combine the two regexp to
'.....
zundel
2012/03/01 18:06:01
i've never used the non-capturing before, but it d
|
| + // remember relative import so we can copy it later |
| + Match match = relativeImportRegExp2.firstMatch(line); |
| + String relativePath = match.group(2); |
| + if (foundImports.contains(relativePath)) { |
| + continue; |
| + } |
| + foundImports.add(relativePath); |
| + toSearch.add('$libraryDir$pathSep$relativePath'); |
| + } |
| + } |
| + } |
| + } |
| + return foundImports; |
| +} |
| void DoMultitest(String filename, |
| String outputDir, |
| @@ -132,13 +167,23 @@ void DoMultitest(String filename, |
| // Each new test is a single String value in the Map tests. |
| Map<String, String> tests = new Map<String, String>(); |
| Map<String, String> outcomes = new Map<String, String>(); |
| + Set<String> importsToCopy = new Set<String>(); |
|
Bill Hesse
2012/03/01 15:01:52
This initializer is overwritten - can be omitted.
zundel
2012/03/01 18:06:01
Done.
|
| ExtractTestsFromMultitest(filename, tests, outcomes); |
| - String directory = CreateMultitestDirectory(outputDir, testDir); |
| - String pathSeparator = new Platform().pathSeparator(); |
| - int start = filename.lastIndexOf(pathSeparator) + 1; |
| + String directory = CreateMultitestDirectory(outputDir, testDir); |
|
Bill Hesse
2012/03/01 15:01:52
extra space before testDir?
zundel
2012/03/01 18:06:01
Done.
|
| + Expect.isNotNull(directory); |
| + String pathSep = new Platform().pathSeparator(); |
| + int start = filename.lastIndexOf(pathSep) + 1; |
| int end = filename.indexOf('.dart', start); |
| String baseFilename = filename.substring(start, end); |
| + String sourceDirectory = filename.substring(0, start - 1); |
| + importsToCopy = _findAllRelativeImports(filename); |
| + for (String import in importsToCopy) { |
| + File source = new File('$sourceDirectory$pathSep$import'); |
|
Bill Hesse
2012/03/01 15:01:52
Again, no need for $pathSep. "/" works on all pla
zundel
2012/03/01 18:06:01
Done.
|
| + // assumes no subdirs |
| + var dest = new File('$directory$pathSep$import'); |
| + _copyFile(source, dest); |
| + } |
| for (String key in tests.getKeys()) { |
| final String filename = '$directory/${baseFilename}_$key.dart'; |
| final File file = new File(filename); |