[tools] migrate the rest of tools/ to null safety

Change-Id: Ieec55a99e9020f8f3962654e07518726d9f66fc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249540
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
This commit is contained in:
Devon Carew 2022-06-24 16:38:39 +00:00 committed by Commit Bot
parent 33822c4caa
commit e9f7cab5ca
8 changed files with 51 additions and 50 deletions

View file

@ -24,35 +24,37 @@ class Result {
final bool matches;
final String name;
final String outcome;
final bool changed;
final String commitHash;
final bool? changed;
final String? commitHash;
final bool flaked; // From optional flakiness_data argument to constructor.
final bool isFlaky; // From results.json after it is extended.
final String previousOutcome;
final bool? isFlaky; // From results.json after it is extended.
final String? previousOutcome;
Result(
this.configuration,
this.name,
this.outcome,
this.expectation,
this.matches,
this.changed,
this.commitHash,
this.isFlaky,
this.previousOutcome,
[this.flaked = false]);
this.configuration,
this.name,
this.outcome,
this.expectation,
this.matches,
this.changed,
this.commitHash,
this.isFlaky,
this.previousOutcome, {
this.flaked = false,
});
Result.fromMap(Map<String, dynamic> map,
[Map<String, dynamic>? flakinessData])
: configuration = map["configuration"] as String,
Result.fromMap(
Map<String, dynamic> map, [
Map<String, dynamic>? flakinessData,
]) : configuration = map["configuration"] as String,
name = map["name"] as String,
outcome = map["result"] as String,
expectation = map["expected"] as String,
matches = map["matches"] as bool,
changed = map["changed"] as bool,
commitHash = map["commit_hash"] as String,
isFlaky = map["flaky"] as bool,
previousOutcome = map["previous_result"] as String,
changed = map["changed"] as bool?,
commitHash = map["commit_hash"] as String?,
isFlaky = map["flaky"] as bool?,
previousOutcome = map["previous_result"] as String?,
flaked = flakinessData != null &&
(flakinessData["active"] ?? true) == true &&
(flakinessData["outcomes"] as List).contains(map["result"]);

View file

@ -198,6 +198,16 @@ Result _result(
bool flaked = false,
bool isFlaky = false,
String previousOutcome = 'Pass'}) {
return Result(configuration, name, outcome, expectation, matches, changed,
commitHash, isFlaky, previousOutcome, flaked);
return Result(
configuration,
name,
outcome,
expectation,
matches,
changed,
commitHash,
isFlaky,
previousOutcome,
flaked: flaked,
);
}

View file

@ -7,8 +7,6 @@
// The output contains additional details in the verbose mode. There is a human
// readable mode that explains the results and how they changed.
// @dart = 2.9
import '../../pkg/test_runner/bin/compare_results.dart' as compare_results;
main(List<String> args) {

View file

@ -5,8 +5,6 @@
// Add fields with data about the test run and the commit tested, and
// with the result on the last build tested, to the test results file.
// @dart = 2.9
import 'dart:convert';
import 'dart:io';
@ -38,10 +36,10 @@ main(List<String> args) async {
}
});
for (final String key in results.keys) {
final Map<String, dynamic> result = results[key];
final Map<String, dynamic> priorResult = priorResults[key];
final Map<String, dynamic> flaky = flakes[key];
final Map<String, dynamic> priorFlaky = priorFlakes[key];
final Map<String, dynamic> result = results[key]!;
final Map<String, dynamic>? priorResult = priorResults[key];
final Map<String, dynamic>? flaky = flakes[key];
final Map<String, dynamic>? priorFlaky = priorFlakes[key];
result['commit_hash'] = commitHash;
result['commit_time'] = commitTime;
result['build_number'] = buildNumber;

View file

@ -6,8 +6,6 @@
// of active, non-approved failures which include the commit of the current
// bisection build.
// @dart = 2.9
import 'dart:io';
import 'package:args/args.dart';
@ -20,7 +18,7 @@ const skippedTest = 'skipped';
const maxAttempts = 20;
FirestoreDatabase database;
late FirestoreDatabase database;
class ResultRecord {
final Map data;
@ -77,7 +75,7 @@ Future<int> getCommitIndex(String commit) async {
/// Compute if the record should be updated based on the outcomes in the
/// result record and the new test result.
bool shouldUpdateRecord(ResultRecord resultRecord, Result testResult) {
bool shouldUpdateRecord(ResultRecord resultRecord, Result? testResult) {
if (testResult == null || !testResult.matches) {
return false;
}
@ -97,8 +95,8 @@ bool shouldUpdateRecord(ResultRecord resultRecord, Result testResult) {
return true;
}
void updateBlameLists(
String configuration, String commit, Map<String, Map> testResults) async {
void updateBlameLists(String configuration, String commit,
Map<String, Map<String, dynamic>> testResults) async {
int commitIndex = await getCommitIndex(commit);
var query = unapprovedActiveFailuresQuery(configuration);
bool needsRetry;
@ -127,7 +125,7 @@ void updateBlameLists(
print('Found result record: $configuration:${result.name}: '
'${result.previousResult} -> ${result.result} '
'in ${result.blamelistStartIndex}..${result.blamelistEndIndex} '
'to update with ${testResult.outcome} at $commitIndex.');
'to update with ${testResult?.outcome} at $commitIndex.');
// We found a result representation for this test and configuration whose
// blamelist includes this results' commit but whose outcome is different
// then the outcome in the provided test results.
@ -176,7 +174,7 @@ main(List<String> arguments) async {
}
// Pick an arbitrary result entry to find configuration and commit hash.
var firstResult = Result.fromMap(results.values.first);
var commit = firstResult.commitHash;
var commit = firstResult.commitHash!;
var configuration = firstResult.configuration;
var project = options['staging'] ? 'dart-ci-staging' : 'dart-ci';
database = FirestoreDatabase(

View file

@ -5,8 +5,6 @@
// Update the flakiness data with a set of fresh results.
// @dart = 2.9
import 'dart:convert';
import 'dart:io';
@ -43,7 +41,7 @@ ${parser.usage}''');
final resultsForInactiveFlakiness = {
for (final flakyTest in data.keys)
if (data[flakyTest]['active'] == false) flakyTest: <String>{}
if (data[flakyTest]!['active'] == false) flakyTest: <String>{}
};
// Incrementally update the flakiness data with each observed result.
for (final path in parameters) {
@ -99,11 +97,11 @@ ${parser.usage}''');
options['output'] != null ? File(options['output']).openWrite() : stdout;
final keys = data.keys.toList()..sort();
for (final key in keys) {
final testData = data[key];
final testData = data[key]!;
if (testData['outcomes'].length < 2) continue;
// Reactivate inactive flaky results that are flaky again.
if (testData['active'] == false) {
if (resultsForInactiveFlakiness[key].length > 1) {
if (resultsForInactiveFlakiness[key]!.length > 1) {
testData['active'] = true;
testData['reactivation_count'] =
(testData['reactivation_count'] ?? 0) + 1;

View file

@ -2,14 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.9
import 'dart:io' show File, Platform;
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
void main() {
YamlMap yaml = loadYaml(File.fromUri(computeYamlFile()).readAsStringSync());
final currentVersion = getAsVersionNumber(yaml['current-version']);
final currentVersion = getAsVersionNumber(yaml['current-version'])!;
final enumNames = StringBuffer();
final featureValues = StringBuffer();
final featureNames = StringBuffer();
@ -108,7 +107,7 @@ Uri computeHFile() {
return Platform.script.resolve("../runtime/vm/experimental_features.h");
}
List<num> getAsVersionNumber(dynamic value) {
List<num>? getAsVersionNumber(dynamic value) {
if (value == null) return null;
final version = List.of("$value".split(".").map(int.parse));
while (version.length < 3) {

View file

@ -3,8 +3,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.9
import 'package:test_runner/test_runner.dart';
void main(List<String> args) {