Skip to content

Commit 0689ec5

Browse files
munificentcommit-bot@chromium.org
authored andcommitted
Move "test.dart" (well, most of its contents) into pkg/test_runner.
I don't like having a large volume of Dart code sitting under tools/ where it is hard to analyze, lint, test, and reuse. Also, eventually we want to merge test.dart and test.py. This seems like an easy mostly mechanical first step. All I did was: 1. Move the contents of tools/test.dart to pkg/test_runner/lib/test_runner.dart. (That's not a great file name since we already have pkg/test_runner/bin/test_runner.dart, but it was the best I could come up with. 2. Copy tools/bots/results to pkg/test_runner/bot_results.dart. I don't like duplicating this, but there are other scripts under tools that import the old location. Eventually, we should have those scripts import it from package:test_runner/bot_results.dart, but I didn't want to do that here since I'm not familiar with those other scripts. 3. Make tools/test.dart import and forward to pkg/test_runner/lib/test_runner.dart. 4. Fix any linter and type errors. The test_runner package has a bunch of strictness checks and lints enable to keep it cleaner. 5. Run dartfmt --fix to format and get rid of "new", etc. Change-Id: Ifc89817508d3fc147fa78dbc6744d547aeaf4c55 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155240 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Jonas Termansen <sortie@google.com>
1 parent 1094b3c commit 0689ec5

File tree

6 files changed

+638
-613
lines changed

6 files changed

+638
-613
lines changed

tools/bots/results.dart renamed to pkg/test_runner/lib/bot_results.dart

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// results.json and flaky.json parser.
5+
/// Parses results.json and flaky.json.
66
77
import 'dart:async';
88
import 'dart:convert';
99
import 'dart:io';
10-
import 'dart:math';
10+
import 'dart:math' as math;
1111

1212
import 'package:pool/pool.dart';
1313

@@ -18,34 +18,34 @@ String gsutilPy;
1818
const testResultsStoragePath = "gs://dart-test-results/builders";
1919

2020
/// Limit the number of concurrent subprocesses by half the number of cores.
21-
final gsutilPool = new Pool(max(1, Platform.numberOfProcessors ~/ 2));
21+
final gsutilPool = Pool(math.max(1, Platform.numberOfProcessors ~/ 2));
2222

2323
/// Runs gsutil with the provided [arguments] and returns the standard output.
24+
///
2425
/// Returns null if the requested URL didn't exist.
2526
Future<String> runGsutil(List<String> arguments) async {
2627
return gsutilPool.withResource(() async {
27-
final processResult = await Process.run(
28+
var processResult = await Process.run(
2829
"python", [gsutilPy]..addAll(arguments),
2930
runInShell: Platform.isWindows);
31+
var stderr = processResult.stderr as String;
3032
if (processResult.exitCode != 0) {
31-
if (processResult.exitCode == 1 &&
32-
processResult.stderr.contains("No URLs matched") ||
33-
processResult.stderr
34-
.contains("One or more URLs matched no objects")) {
33+
if (processResult.exitCode == 1 && stderr.contains("No URLs matched") ||
34+
stderr.contains("One or more URLs matched no objects")) {
3535
return null;
3636
}
37-
String error = "Failed to run: python $gsutilPy $arguments\n"
37+
var error = "Failed to run: python $gsutilPy $arguments\n"
3838
"exitCode: ${processResult.exitCode}\n"
3939
"stdout:\n${processResult.stdout}\n"
4040
"stderr:\n${processResult.stderr}";
4141
if (processResult.exitCode == 1 &&
42-
processResult.stderr.contains("401 Anonymous caller")) {
42+
stderr.contains("401 Anonymous caller")) {
4343
error =
4444
"\n\nYou need to authenticate by running:\npython $gsutilPy config\n";
4545
}
46-
throw new Exception(error);
46+
throw Exception(error);
4747
}
48-
return processResult.stdout;
48+
return processResult.stdout as String;
4949
});
5050
}
5151

@@ -56,12 +56,12 @@ Future<String> catGsutil(String path) => runGsutil(["cat", path]);
5656
/// Returns the files and directories in the provided cloud storage [directory],
5757
/// or null if it didn't exist.
5858
Future<Iterable<String>> lsGsutil(String directory) async {
59-
final contents = await runGsutil(["ls", directory]);
59+
var contents = await runGsutil(["ls", directory]);
6060
if (contents == null) {
6161
return null;
6262
}
6363
return LineSplitter.split(contents).map((String path) {
64-
final elements = path.split("/");
64+
var elements = path.split("/");
6565
if (elements[elements.length - 1].isEmpty) {
6666
return elements[elements.length - 2];
6767
} else {
@@ -113,23 +113,22 @@ List<Map<String, dynamic>> parseResults(String contents) {
113113
}
114114

115115
Future<List<Map<String, dynamic>>> loadResults(String path) async {
116-
final results = <Map<String, dynamic>>[];
117-
final lines = new File(path)
116+
var results = <Map<String, dynamic>>[];
117+
var lines = File(path)
118118
.openRead()
119119
.cast<List<int>>()
120120
.transform(utf8.decoder)
121-
.transform(new LineSplitter());
122-
await for (final line in lines) {
123-
final Map<String, dynamic> map = jsonDecode(line);
124-
results.add(map);
121+
.transform(const LineSplitter());
122+
await for (var line in lines) {
123+
results.add(jsonDecode(line) as Map<String, dynamic>);
125124
}
126125
return results;
127126
}
128127

129128
Map<String, Map<String, dynamic>> createResultsMap(
130129
List<Map<String, dynamic>> results) {
131-
Map<String, Map<String, dynamic>> result = {};
132-
for (Map<String, dynamic> map in results) {
130+
var result = <String, Map<String, dynamic>>{};
131+
for (var map in results) {
133132
var key = "${map["configuration"]}:${map["name"]}";
134133
result.putIfAbsent(key, () => map);
135134
}

0 commit comments

Comments
 (0)