Chromium Code Reviews| Index: tools/migration/bin/migrate_batch.dart |
| diff --git a/tools/migration/bin/migrate_batch.dart b/tools/migration/bin/migrate_batch.dart |
| index b0ae2b1f2722a5cf9940da0314a11dc39df77ed4..1556d92990c84c08f8d5b01949a2b52cfb871989 100644 |
| --- a/tools/migration/bin/migrate_batch.dart |
| +++ b/tools/migration/bin/migrate_batch.dart |
| @@ -13,6 +13,7 @@ import 'dart:io'; |
| import 'package:path/path.dart' as p; |
| import 'package:migration/src/log.dart'; |
| +import 'package:migration/src/status_file.dart'; |
| const simpleDirs = const ["corelib", "language", "lib"]; |
| @@ -40,8 +41,13 @@ void main(List<String> arguments) { |
| exit(1); |
| } |
| - var first = toTwoPath(arguments[0]); |
| - var last = toTwoPath(arguments[1]); |
| + var first = arguments[0]; |
| + var last = arguments[1]; |
| + |
| + print("Preparing to migrate tests from ${bold(first)} to ${bold(last)}..."); |
|
Bob Nystrom
2017/07/24 21:47:47
This is because the scan process is a lot longer w
bkonyi
2017/07/25 22:13:39
Oh yeah, this is here because I'm really not doing
|
| + |
| + first = toTwoPath(first); |
| + last = toTwoPath(last); |
| var tests = scanTests(); |
| @@ -62,6 +68,11 @@ void main(List<String> arguments) { |
| } |
| } |
| + if ((endIndex - startIndex) == 0) { |
| + print(bold("No tests to migrate.")); |
| + return; |
| + } |
| + |
| print("Migrating ${bold(endIndex - startIndex)} tests from ${bold(first)} " |
| "to ${bold(last)}..."); |
| print(""); |
| @@ -93,6 +104,38 @@ void main(List<String> arguments) { |
| print(summary); |
| todos.forEach(todo); |
| + |
| + // Print status file entries. |
| + var statusFileEntries = ""; |
| + for (var i = startIndex; i < endIndex; i++) { |
| + statusFileEntries += printStatusFileEntries(tests[i]); |
|
Bob Nystrom
2017/07/24 21:47:47
Instead of repeatedly concatenating strings, it's
bkonyi
2017/07/25 22:13:39
Right, that makes sense. Done.
|
| + } |
| + |
| + new File("statuses.migration").writeAsStringSync(statusFileEntries); |
| + print( |
| + bold("Wrote relevant test status file entries to 'statuses.migration'")); |
| +} |
| + |
| +String printStatusFileEntries(Fork test) { |
| + var statusFileEntries = ""; |
| + if (test.onePath != null && !test.oneStatusFile.isEmpty) { |
| + statusFileEntries += |
| + bold("Status file entries for: ${test.onePath}") + "\n"; |
| + for (var section in test.oneStatusFile.sections) { |
| + statusFileEntries += section.toString(); |
| + } |
| + } |
| + if (test.strongPath != null && !test.strongStatusFile.isEmpty) { |
| + if (statusFileEntries != "") { |
| + statusFileEntries += "\n"; |
| + } |
| + statusFileEntries += |
| + bold("Status file entries for: ${test.strongPath}") + "\n"; |
| + for (var section in test.strongStatusFile.sections) { |
| + statusFileEntries += section.toString(); |
| + } |
| + } |
| + return statusFileEntries; |
| } |
| String toTwoPath(String path) { |
| @@ -136,13 +179,17 @@ List<Fork> scanTests() { |
| if (!entry.path.endsWith("_test.dart")) continue; |
| var fromPath = p.relative(entry.path, from: testRoot); |
| + var fromStatus = testRoot + "/$fromDir/${fromDir}.status"; |
| + var testName = entry.path.split("/").last.split(".")[0]; |
| + var statusFile = getStatusFileEntries(fromStatus, testName); |
|
Bob Nystrom
2017/07/24 21:47:47
This call does two things:
1. It reads the status
bkonyi
2017/07/25 22:13:39
Done.
|
| var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir)); |
| - |
| var fork = tests.putIfAbsent(twoPath, () => new Fork(twoPath)); |
| if (fromDir.contains("_strong")) { |
| fork.strongPath = fromPath; |
| + fork.strongStatusFile = statusFile; |
| } else { |
| fork.onePath = fromPath; |
| + fork.oneStatusFile = statusFile; |
| } |
| } |
| } |
| @@ -161,6 +208,26 @@ List<Fork> scanTests() { |
| return sorted; |
| } |
| +StatusFile getStatusFileEntries(String path, String test) { |
| + final statusFile = new StatusFile.read(path); |
| + final filteredStatusFile = new StatusFile(path); |
|
Bob Nystrom
2017/07/24 21:47:47
Style nit: Elsewhere, I tend to use "var" even for
bkonyi
2017/07/25 22:13:40
Hm, that's interesting. I've heard different opini
|
| + for (var section in statusFile.sections) { |
| + StatusSection currentSection = null; |
| + for (var entry in section.entries) { |
| + if (entry.contains(test)) { |
| + if (currentSection == null) { |
| + currentSection = new StatusSection(section.condition); |
| + } |
| + currentSection.entries.add(entry); |
| + } |
| + } |
| + if (currentSection != null) { |
| + filteredStatusFile.sections.add(currentSection); |
| + } |
| + } |
| + return filteredStatusFile; |
| +} |
| + |
| /// Moves the file from [from] to [to], which are both assumed to be relative |
| /// paths inside "tests". |
| void moveFile(String from, String to) { |
| @@ -198,7 +265,9 @@ bool checkForUnitTest(String path, String source) { |
| class Fork { |
| final String twoPath; |
| String onePath; |
| + StatusFile oneStatusFile; |
|
Bob Nystrom
2017/07/24 21:47:47
Unfortunately, to make things more annoying, there
bkonyi
2017/07/25 22:13:39
Ah, I didn't realize that. Fixed.
|
| String strongPath; |
| + StatusFile strongStatusFile; |
| String get twoSource { |
| if (twoPath == null) return null; |