refactor: migrate test_benchmarks to null safety (#757)
* refactor: machine migration
* address comments
* update pubspec
diff --git a/pubspec.lock b/pubspec.lock
index 031584b..004f9e8 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -7,7 +7,7 @@
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
- version: "46.0.0"
+ version: "47.0.0"
adaptive_breakpoints:
dependency: "direct main"
description:
@@ -21,14 +21,14 @@
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
- version: "4.6.0"
+ version: "4.7.0"
animations:
dependency: "direct main"
description:
name: animations
url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.3"
+ version: "2.0.4"
archive:
dependency: transitive
description:
@@ -140,7 +140,7 @@
name: file
url: "https://pub.dartlang.org"
source: hosted
- version: "6.1.3"
+ version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
@@ -394,7 +394,7 @@
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.19"
+ version: "2.0.20"
path_provider_ios:
dependency: transitive
description:
@@ -429,7 +429,7 @@
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.2"
+ version: "2.1.3"
platform:
dependency: transitive
description:
@@ -527,7 +527,7 @@
name: shared_preferences_platform_interface
url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.0"
+ version: "2.1.0"
shared_preferences_web:
dependency: transitive
description:
@@ -644,21 +644,21 @@
name: test
url: "https://pub.dartlang.org"
source: hosted
- version: "1.21.4"
+ version: "1.21.5"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.12"
+ version: "0.4.13"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.16"
+ version: "0.4.17"
typed_data:
dependency: transitive
description:
@@ -728,7 +728,7 @@
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.2"
+ version: "2.1.3"
vm_service:
dependency: transitive
description:
@@ -749,7 +749,7 @@
name: web_benchmarks
url: "https://pub.dartlang.org"
source: hosted
- version: "0.0.7+1"
+ version: "0.1.0+1"
web_socket_channel:
dependency: transitive
description:
@@ -770,7 +770,7 @@
name: webkit_inspection_protocol
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
win32:
dependency: transitive
description:
@@ -784,7 +784,7 @@
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
- version: "0.2.0+1"
+ version: "0.2.0+2"
yaml:
dependency: transitive
description:
@@ -793,5 +793,5 @@
source: hosted
version: "3.1.1"
sdks:
- dart: ">=2.17.0 <3.0.0"
+ dart: ">=2.18.0-146.0.dev <3.0.0"
flutter: ">=3.1.0-0"
diff --git a/pubspec.yaml b/pubspec.yaml
index 06d5ef2..d5de85b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -44,7 +44,7 @@
path: ^1.8.1
string_scanner: ^1.1.0
test: ^1.21.1
- web_benchmarks: ^0.0.7
+ web_benchmarks: ^0.1.0
flutter:
deferred-components:
diff --git a/test_benchmarks/benchmarks/client.dart b/test_benchmarks/benchmarks/client.dart
index 817d0f0..c3d6e42 100644
--- a/test_benchmarks/benchmarks/client.dart
+++ b/test_benchmarks/benchmarks/client.dart
@@ -1,4 +1,6 @@
-// @dart=2.9
+// Copyright 2020 The Flutter team. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
import 'package:web_benchmarks/client.dart';
diff --git a/test_benchmarks/benchmarks/common.dart b/test_benchmarks/benchmarks/common.dart
index a30aee2..36af7f9 100644
--- a/test_benchmarks/benchmarks/common.dart
+++ b/test_benchmarks/benchmarks/common.dart
@@ -1,4 +1,6 @@
-// @dart=2.9
+// Copyright 2020 The Flutter team. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
const String galleryBenchmarkPrefix = 'gallery_v2';
diff --git a/test_benchmarks/benchmarks/gallery_automator.dart b/test_benchmarks/benchmarks/gallery_automator.dart
index f747a89..d1a9910 100644
--- a/test_benchmarks/benchmarks/gallery_automator.dart
+++ b/test_benchmarks/benchmarks/gallery_automator.dart
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// @dart=2.9
-
// ignore_for_file:avoid_print
import 'package:flutter/material.dart';
@@ -41,17 +39,17 @@
/// A class that automates the gallery.
class GalleryAutomator {
GalleryAutomator({
- @required this.benchmarkName,
+ required this.benchmarkName,
this.shouldRunPredicate,
this.testScrollsOnly = false,
- @required this.stopWarmingUpCallback,
+ required this.stopWarmingUpCallback,
}) : assert(testScrollsOnly || shouldRunPredicate != null);
/// The name of the current benchmark.
final String benchmarkName;
/// A function deciding whether a demo should be run in this benchmark.
- final bool Function(String) shouldRunPredicate;
+ final bool Function(String)? shouldRunPredicate;
/// Whether we only test scrolling in this benchmark.
final bool testScrollsOnly;
@@ -66,7 +64,7 @@
bool finished = false;
/// A widget controller for automation.
- LiveWidgetController controller;
+ late LiveWidgetController controller;
/// An iterable that generates all demo names.
Iterable<String> get demoNames => Demos.allDescriptions();
@@ -88,7 +86,7 @@
print('==== List of demos to be run ====');
for (final demo in demoNames) {
- if (shouldRunPredicate(demo)) {
+ if (shouldRunPredicate!(demo)) {
print(demo);
}
}
@@ -119,7 +117,7 @@
// Note that the above scrolling is required even for demos *not*
// satisfying `runCriterion`, because we need to scroll
// through every `Scrollable` to find the `demoButton`.
- if (shouldRunPredicate(demo)) {
+ if (shouldRunPredicate!(demo)) {
print('Running demo "$demo"');
for (var i = 0; i < 2; ++i) {
@@ -203,9 +201,9 @@
// Find first demo that is not being tested here.
// We open this demo as a way to warm up the engine, so we need to use an
// untested demo to avoid biasing the benchmarks.
- String firstUntestedDemo;
+ String? firstUntestedDemo;
for (final demo in candidateDemos) {
- if (testScrollsOnly || !shouldRunPredicate(demo)) {
+ if (testScrollsOnly || !shouldRunPredicate!(demo)) {
firstUntestedDemo = demo;
break;
}
@@ -214,7 +212,7 @@
// Open and close the demo twice to warm up.
for (var i = 0; i < 2; ++i) {
- await controller.tap(find.byKey(ValueKey(firstUntestedDemo)));
+ await controller.tap(find.byKey(ValueKey(firstUntestedDemo!)));
if (typeOfDemo(firstUntestedDemo) == DemoType.animatedWidget) {
await Future<void>.delayed(_defaultWaitingDuration);
diff --git a/test_benchmarks/benchmarks/gallery_recorder.dart b/test_benchmarks/benchmarks/gallery_recorder.dart
index 78e97c3..8631466 100644
--- a/test_benchmarks/benchmarks/gallery_recorder.dart
+++ b/test_benchmarks/benchmarks/gallery_recorder.dart
@@ -2,8 +2,6 @@
// 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:flutter/material.dart';
import 'package:web_benchmarks/client.dart';
@@ -12,7 +10,7 @@
/// A recorder that measures frame building durations for the Gallery.
class GalleryRecorder extends WidgetRecorder {
GalleryRecorder({
- @required this.benchmarkName,
+ required this.benchmarkName,
this.shouldRunPredicate,
this.testScrollingOnly = false,
}) : assert(testScrollingOnly || shouldRunPredicate != null),
@@ -32,12 +30,12 @@
/// `progress-indicator@material`.
/// A list of all demo names can be obtained using
/// [allGalleryDemoDescriptions].
- final bool Function(String) shouldRunPredicate;
+ final bool Function(String)? shouldRunPredicate;
/// Whether this benchmark only tests scrolling.
final bool testScrollingOnly;
- GalleryAutomator _galleryAutomator;
+ GalleryAutomator? _galleryAutomator;
bool get _finished => _galleryAutomator?.finished ?? false;
/// Whether we should continue recording.
@@ -53,6 +51,6 @@
testScrollsOnly: testScrollingOnly,
stopWarmingUpCallback: profile.stopWarmingUp,
);
- return _galleryAutomator.createWidget();
+ return _galleryAutomator!.createWidget();
}
}
diff --git a/test_benchmarks/benchmarks/project_root_directory.dart b/test_benchmarks/benchmarks/project_root_directory.dart
index 17ed906..b8ae785 100644
--- a/test_benchmarks/benchmarks/project_root_directory.dart
+++ b/test_benchmarks/benchmarks/project_root_directory.dart
@@ -1,4 +1,6 @@
-// @dart=2.9
+// Copyright 2020 The Flutter team. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
import 'dart:io';
import 'package:path/path.dart' as path;
diff --git a/test_benchmarks/benchmarks/run_benchmarks.dart b/test_benchmarks/benchmarks/run_benchmarks.dart
index e7bde22..1d16a85 100644
--- a/test_benchmarks/benchmarks/run_benchmarks.dart
+++ b/test_benchmarks/benchmarks/run_benchmarks.dart
@@ -1,4 +1,6 @@
-// @dart=2.9
+// Copyright 2020 The Flutter team. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
import 'dart:convert' show JsonEncoder;
import 'dart:io';
diff --git a/test_benchmarks/benchmarks/scroll.dart b/test_benchmarks/benchmarks/scroll.dart
index 5caaae2..62cbf29 100644
--- a/test_benchmarks/benchmarks/scroll.dart
+++ b/test_benchmarks/benchmarks/scroll.dart
@@ -2,8 +2,6 @@
// 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:async';
import 'package:flutter/material.dart';
@@ -24,7 +22,7 @@
Rect _windowRect(BuildContext context) => Offset.zero & _windowSize(context);
-bool _isSuperset({@required Rect large, @required Rect small}) =>
+bool _isSuperset({required Rect large, required Rect small}) =>
large.top <= small.top &&
large.left <= small.left &&
large.bottom >= small.bottom &&
@@ -35,9 +33,9 @@
/// Whether [small] is a subset of [large] and has sufficient room
/// inside [large], at the end of [large] specified by [axisDirection].
bool _hasSufficientFreeRoom({
- @required Rect large,
- @required Rect small,
- @required AxisDirection axisDirection,
+ required Rect large,
+ required Rect small,
+ required AxisDirection axisDirection,
}) {
if (!_isSuperset(large: large, small: small)) {
return false;
@@ -79,15 +77,15 @@
}
Future<void> scrollUntilVisible({
- @required Element element,
+ required Element element,
bool strict = false,
bool animated = true,
}) async {
- final elementRenderObject = element.renderObject;
+ final elementRenderObject = element.renderObject!;
final elementRect = _absoluteRect(elementRenderObject);
final scrollable = Scrollable.of(element);
- final viewport = RenderAbstractViewport.of(elementRenderObject);
+ final viewport = RenderAbstractViewport.of(elementRenderObject)!;
final visibleWindow = _absoluteRect(viewport).intersect(_windowRect(element));
@@ -97,13 +95,13 @@
_hasSufficientFreeRoom(
large: visibleWindow,
small: elementRect,
- axisDirection: scrollable.axisDirection,
+ axisDirection: scrollable!.axisDirection,
)) {
return;
}
- double pixelsToBeMoved;
- switch (scrollable.axisDirection) {
+ late double pixelsToBeMoved;
+ switch (scrollable!.axisDirection) {
case AxisDirection.down:
pixelsToBeMoved = elementRect.top - visibleWindow.top;
break;
@@ -134,13 +132,13 @@
}
Future<void> scrollToExtreme({
- @required ScrollableState scrollable,
+ required ScrollableState? scrollable,
bool toEnd = false,
bool animated = true,
}) async {
final targetPixels = toEnd
- ? scrollable.position.maxScrollExtent
- : scrollable.position.minScrollExtent;
+ ? scrollable!.position.maxScrollExtent
+ : scrollable!.position.minScrollExtent;
await scrollToPosition(
scrollable: scrollable,
@@ -150,18 +148,18 @@
}
Future<void> scrollToPosition({
- @required ScrollableState scrollable,
- @required double pixels,
+ required ScrollableState? scrollable,
+ required double pixels,
bool animated = true,
}) async {
if (animated) {
- await scrollable.position.animateTo(
+ await scrollable!.position.animateTo(
pixels,
duration: _scrollAnimationLength,
curve: Curves.easeInOut,
);
} else {
- scrollable.position.jumpTo(pixels);
+ scrollable!.position.jumpTo(pixels);
}
await animationStops();
diff --git a/test_benchmarks/benchmarks_test.dart b/test_benchmarks/benchmarks_test.dart
index 8aa7f0d..b45d7f8 100644
--- a/test_benchmarks/benchmarks_test.dart
+++ b/test_benchmarks/benchmarks_test.dart
@@ -1,4 +1,6 @@
-// @dart=2.9
+// Copyright 2020 The Flutter team. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
import 'dart:convert' show JsonEncoder;
import 'dart:io';
@@ -46,7 +48,7 @@
for (final metricName in metricList) {
for (final valueName in valueList) {
expect(
- taskResult.scores[benchmarkName].where(
+ taskResult.scores[benchmarkName]?.where(
(score) => score.metric == '$metricName.$valueName',
),
hasLength(1),
@@ -55,7 +57,7 @@
}
expect(
- taskResult.scores[benchmarkName].where(
+ taskResult.scores[benchmarkName]?.where(
(score) => score.metric == 'totalUiFrame.average',
),
hasLength(1),
diff --git a/test_benchmarks/web_bundle_size_test.dart b/test_benchmarks/web_bundle_size_test.dart
index d89338f..8de10d1 100644
--- a/test_benchmarks/web_bundle_size_test.dart
+++ b/test_benchmarks/web_bundle_size_test.dart
@@ -2,8 +2,6 @@
// 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';
import 'package:path/path.dart' as path;