From e9f7cab5ca24e28d1b78444b9f8e30c0637a6654 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 24 Jun 2022 16:38:39 +0000 Subject: [PATCH] [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 Reviewed-by: Alexander Thomas --- pkg/test_runner/lib/bot_results.dart | 44 ++++++++++--------- .../compare_results/compare_results_test.dart | 14 +++++- tools/bots/compare_results.dart | 2 - tools/bots/extend_results.dart | 10 ++--- tools/bots/update_blamelists.dart | 14 +++--- tools/bots/update_flakiness.dart | 8 ++-- tools/generate_experimental_flags.dart | 7 ++- tools/test.dart | 2 - 8 files changed, 51 insertions(+), 50 deletions(-) diff --git a/pkg/test_runner/lib/bot_results.dart b/pkg/test_runner/lib/bot_results.dart index 1bad14ebbae..6b0a850c809 100644 --- a/pkg/test_runner/lib/bot_results.dart +++ b/pkg/test_runner/lib/bot_results.dart @@ -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 map, - [Map? flakinessData]) - : configuration = map["configuration"] as String, + Result.fromMap( + Map map, [ + Map? 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"]); diff --git a/pkg/test_runner/test/compare_results/compare_results_test.dart b/pkg/test_runner/test/compare_results/compare_results_test.dart index 2a8b17415cd..c655ddf7547 100644 --- a/pkg/test_runner/test/compare_results/compare_results_test.dart +++ b/pkg/test_runner/test/compare_results/compare_results_test.dart @@ -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, + ); } diff --git a/tools/bots/compare_results.dart b/tools/bots/compare_results.dart index 1e2bad318ce..5ca9f1f9892 100755 --- a/tools/bots/compare_results.dart +++ b/tools/bots/compare_results.dart @@ -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 args) { diff --git a/tools/bots/extend_results.dart b/tools/bots/extend_results.dart index 6b036235b98..98fcec828c8 100644 --- a/tools/bots/extend_results.dart +++ b/tools/bots/extend_results.dart @@ -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 args) async { } }); for (final String key in results.keys) { - final Map result = results[key]; - final Map priorResult = priorResults[key]; - final Map flaky = flakes[key]; - final Map priorFlaky = priorFlakes[key]; + final Map result = results[key]!; + final Map? priorResult = priorResults[key]; + final Map? flaky = flakes[key]; + final Map? priorFlaky = priorFlakes[key]; result['commit_hash'] = commitHash; result['commit_time'] = commitTime; result['build_number'] = buildNumber; diff --git a/tools/bots/update_blamelists.dart b/tools/bots/update_blamelists.dart index 0776afcfbb4..7956090a3d5 100644 --- a/tools/bots/update_blamelists.dart +++ b/tools/bots/update_blamelists.dart @@ -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 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 testResults) async { +void updateBlameLists(String configuration, String commit, + Map> 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 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( diff --git a/tools/bots/update_flakiness.dart b/tools/bots/update_flakiness.dart index 92667a5abec..a112fedf543 100755 --- a/tools/bots/update_flakiness.dart +++ b/tools/bots/update_flakiness.dart @@ -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: {} + if (data[flakyTest]!['active'] == false) flakyTest: {} }; // 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; diff --git a/tools/generate_experimental_flags.dart b/tools/generate_experimental_flags.dart index 3ae2858ca58..f096ae9f152 100644 --- a/tools/generate_experimental_flags.dart +++ b/tools/generate_experimental_flags.dart @@ -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 getAsVersionNumber(dynamic value) { +List? getAsVersionNumber(dynamic value) { if (value == null) return null; final version = List.of("$value".split(".").map(int.parse)); while (version.length < 3) { diff --git a/tools/test.dart b/tools/test.dart index fece115b9f5..e85bebd24de 100755 --- a/tools/test.dart +++ b/tools/test.dart @@ -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 args) {