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

Side by Side Diff: tools/migration/bin/migrate_batch.dart

Issue 2987223002: Add a script to run the tests in a migration block. (Closed)
Patch Set: Merge branch 'master' into run-tests Created 3 years, 4 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
« no previous file with comments | « tools/migration/.packages ('k') | tools/migration/bin/run_tests.dart » ('j') | 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) 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 /// Given the beginning and ending file names in a batch, does as much automated 5 /// Given the beginning and ending file names in a batch, does as much automated
6 /// migration and possible and prints out the remaining manual steps required. 6 /// migration and possible and prints out the remaining manual steps required.
7 /// 7 ///
8 /// This should be safe to run, and safe to re-run on an in-progress chunk. 8 /// This should be safe to run, and safe to re-run on an in-progress chunk.
9 /// However, it has not been thoroughly tested, so run at your own risk. 9 /// However, it has not been thoroughly tested, so run at your own risk.
10 10
11 import 'dart:io'; 11 import 'dart:io';
12 12
13 import 'package:path/path.dart' as p;
14
15 import 'package:migration/src/fork.dart'; 13 import 'package:migration/src/fork.dart';
16 import 'package:migration/src/io.dart'; 14 import 'package:migration/src/io.dart';
17 import 'package:migration/src/log.dart'; 15 import 'package:migration/src/log.dart';
18 import 'package:migration/src/migrate_statuses.dart'; 16 import 'package:migration/src/migrate_statuses.dart';
19 import 'package:migration/src/test_directories.dart';
20 17
21 const simpleDirs = const ["corelib", "language", "lib"]; 18 const simpleDirs = const ["corelib", "language", "lib"];
22 19
23 void main(List<String> arguments) { 20 void main(List<String> arguments) {
24 if (arguments.contains("--dry-run")) { 21 if (arguments.contains("--dry-run")) {
25 dryRun = true; 22 dryRun = true;
26 arguments = arguments.where((argument) => argument != "--dry-run").toList(); 23 arguments = arguments.where((argument) => argument != "--dry-run").toList();
27 } 24 }
28 25
29 if (arguments.length != 2) { 26 if (arguments.length != 2) {
30 stderr.writeln( 27 stderr.writeln(
31 "Usage: dart migrate_batch.dart [--dry-run] <first file> <last file>"); 28 "Usage: dart migrate_batch.dart [--dry-run] <first file> <last file>");
32 stderr.writeln(); 29 stderr.writeln();
33 stderr.writeln("Example:"); 30 stderr.writeln("Example:");
34 stderr.writeln(); 31 stderr.writeln();
35 stderr.writeln( 32 stderr.writeln(" \$ dart migrate_batch.dart map_to_string queue");
36 " \$ dart migrate_batch.dart corelib/map_to_string corelib/queue");
37 exit(1); 33 exit(1);
38 } 34 }
39 35
40 var tests = scanTests(); 36 var tests = scanTests();
41 37
42 var startIndex = findFork(tests, arguments[0]); 38 var startIndex = findFork(tests, arguments[0]);
43 var endIndex = findFork(tests, arguments[1]); 39 var endIndex = findFork(tests, arguments[1]);
44 40
45 if (startIndex == null || endIndex == null) exit(1); 41 if (startIndex == null || endIndex == null) exit(1);
46 42
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 84 }
89 85
90 print(summary); 86 print(summary);
91 var todoTests = allTodos.keys.toList(); 87 var todoTests = allTodos.keys.toList();
92 todoTests.sort(); 88 todoTests.sort();
93 for (var todoTest in todoTests) { 89 for (var todoTest in todoTests) {
94 print("- ${bold(todoTest)}:"); 90 print("- ${bold(todoTest)}:");
95 allTodos[todoTest].forEach(todo); 91 allTodos[todoTest].forEach(todo);
96 } 92 }
97 } 93 }
98
99 int findFork(List<Fork> forks, String description) {
100 var matches = <int>[];
101
102 for (var i = 0; i < forks.length; i++) {
103 if (forks[i].twoPath.contains(description)) matches.add(i);
104 }
105
106 if (matches.isEmpty) {
107 print('Could not find a test matching "${bold(description)}".');
108 return null;
109 } else if (matches.length == 1) {
110 return matches.first;
111 } else {
112 print('Description "${bold(description)}" is ambiguous. Could be any of:');
113 for (var i in matches) {
114 print("- ${forks[i].twoPath.replaceAll(description, bold(description))}");
115 }
116
117 print("Please use a more precise description.");
118 return null;
119 }
120 }
121
122 /// Loads all of the unforked test files.
123 ///
124 /// Creates an list of [Fork]s, ordered by their destination paths. Handles
125 /// tests that only appear in one fork or the other, or both.
126 List<Fork> scanTests() {
127 var tests = <String, Fork>{};
128
129 for (var fromDir in fromRootDirs) {
130 var twoDir = toTwoDirectory(fromDir);
131 for (var path in listFiles(fromDir)) {
132 var fromPath = p.relative(path, from: testRoot);
133 var twoPath = p.join(twoDir, p.relative(fromPath, from: fromDir));
134
135 tests.putIfAbsent(twoPath, () => new Fork(twoPath));
136 }
137 }
138
139 // Include tests that have already been migrated too so we can show what
140 // works remains to be done in them.
141 for (var dir in twoRootDirs) {
142 for (var path in listFiles(dir)) {
143 var twoPath = p.relative(path, from: testRoot);
144 tests.putIfAbsent(twoPath, () => new Fork(twoPath));
145 }
146 }
147
148 var sorted = tests.values.toList();
149 sorted.sort((a, b) => a.twoPath.compareTo(b.twoPath));
150 return sorted;
151 }
OLDNEW
« no previous file with comments | « tools/migration/.packages ('k') | tools/migration/bin/run_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698