OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 | 8 |
9 import 'io.dart'; | 9 import 'io.dart'; |
10 import 'log.dart'; | 10 import 'log.dart'; |
11 import 'test_directories.dart'; | 11 import 'test_directories.dart'; |
12 import 'validate.dart'; | 12 import 'validate.dart'; |
13 | 13 |
| 14 int findFork(List<Fork> forks, String description) { |
| 15 var matches = <int>[]; |
| 16 |
| 17 for (var i = 0; i < forks.length; i++) { |
| 18 if (forks[i].twoPath.contains(description)) matches.add(i); |
| 19 } |
| 20 |
| 21 if (matches.isEmpty) { |
| 22 print('Could not find a test matching "${bold(description)}".'); |
| 23 return null; |
| 24 } else if (matches.length == 1) { |
| 25 return matches.first; |
| 26 } else { |
| 27 print('Description "${bold(description)}" is ambiguous. Could be any of:'); |
| 28 for (var i in matches) { |
| 29 print("- ${forks[i].twoPath.replaceAll(description, bold(description))}"); |
| 30 } |
| 31 |
| 32 print("Please use a more precise description."); |
| 33 return null; |
| 34 } |
| 35 } |
| 36 |
| 37 /// Loads all of the unforked test files. |
| 38 /// |
| 39 /// Creates an list of [Fork]s, ordered by their destination paths. Handles |
| 40 /// tests that only appear in one fork or the other, or both. |
| 41 List<Fork> scanTests() { |
| 42 var tests = <String, Fork>{}; |
| 43 |
| 44 for (var fromDir in fromRootDirs) { |
| 45 var twoDir = toTwoDirectory(fromDir); |
| 46 for (var path in listFiles(fromDir)) { |
| 47 var fromPath = p.relative(path, from: testRoot); |
| 48 var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir)); |
| 49 |
| 50 tests.putIfAbsent(twoPath, () => new Fork(twoPath)); |
| 51 } |
| 52 } |
| 53 |
| 54 // Include tests that have already been migrated too so we can show what |
| 55 // works remains to be done in them. |
| 56 for (var dir in twoRootDirs) { |
| 57 for (var path in listFiles(dir)) { |
| 58 var twoPath = p.relative(path, from: testRoot); |
| 59 tests.putIfAbsent(twoPath, () => new Fork(twoPath)); |
| 60 } |
| 61 } |
| 62 |
| 63 var sorted = tests.values.toList(); |
| 64 sorted.sort((a, b) => a.twoPath.compareTo(b.twoPath)); |
| 65 return sorted; |
| 66 } |
| 67 |
14 /// Tracks one test and the various forked locations where it may appear. | 68 /// Tracks one test and the various forked locations where it may appear. |
15 /// | 69 /// |
16 /// * "One" refers to the original Dart 1.0 location of the test: language/, | 70 /// * "One" refers to the original Dart 1.0 location of the test: language/, |
17 /// corelib/, etc. | 71 /// corelib/, etc. |
18 /// | 72 /// |
19 /// * "Strong" is the DDC fork of the file: language_strong, etc. | 73 /// * "Strong" is the DDC fork of the file: language_strong, etc. |
20 /// | 74 /// |
21 /// * "Two" is the migrated 2.0 destination location: language_2, etc. | 75 /// * "Two" is the migrated 2.0 destination location: language_2, etc. |
22 class Fork { | 76 class Fork { |
23 final String twoPath; | 77 final String twoPath; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 165 } |
112 | 166 |
113 // See what work is left to be done in the migrated file. | 167 // See what work is left to be done in the migrated file. |
114 if (twoExists) { | 168 if (twoExists) { |
115 validateFile(twoPath, twoSource, todos); | 169 validateFile(twoPath, twoSource, todos); |
116 } | 170 } |
117 | 171 |
118 return todos; | 172 return todos; |
119 } | 173 } |
120 } | 174 } |
OLD | NEW |