Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 00fdc7f

Browse files
committed
dart analysis of tests, cleanup
1 parent 7b0c82b commit 00fdc7f

File tree

10 files changed

+104
-84
lines changed

10 files changed

+104
-84
lines changed

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# private fields, especially on the Window object):
1111

1212
analyzer:
13+
# this test pretends to be part of dart:ui and results in lots of false
14+
# positives.
15+
exclude: [ testing/dart/window_hooks_integration_test.dart ]
1316
strong-mode:
1417
implicit-dynamic: false
1518
errors:

ci/analyze.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ fi
2020

2121
echo "Analyzing flutter_frontend_server..."
2222
RESULTS=`dartanalyzer \
23-
--packages=flutter/flutter_frontend_server/.packages \
23+
--packages=flutter/flutter_frontend_server/.packages \
2424
--options flutter/analysis_options.yaml \
25-
flutter/flutter_frontend_server \
25+
flutter/flutter_frontend_server \
2626
2>&1 \
2727
| grep -Ev "No issues found!" \
2828
| grep -Ev "Analyzing.+frontend_server"`
@@ -46,3 +46,33 @@ if [ -n "$RESULTS" ]; then
4646
echo "Failed."
4747
exit 1;
4848
fi
49+
50+
echo "Analyzing testing/dart..."
51+
(cd flutter/testing/dart && pub get)
52+
RESULTS=`dartanalyzer \
53+
--packages=flutter/testing/dart/.packages \
54+
--options flutter/analysis_options.yaml \
55+
flutter/testing/dart \
56+
2>&1 \
57+
| grep -Ev "No issues found!" \
58+
| grep -Ev "Analyzing.+testing/dart"`
59+
echo "$RESULTS"
60+
if [ -n "$RESULTS" ]; then
61+
echo "Failed."
62+
exit 1;
63+
fi
64+
65+
echo "Analyzing testing/scenario_app..."
66+
(cd flutter/testing/scenario_app && pub get)
67+
RESULTS=`dartanalyzer \
68+
--packages=flutter/testing/scenario_app/.packages \
69+
--options flutter/analysis_options.yaml \
70+
flutter/testing/scenario_app \
71+
2>&1 \
72+
| grep -Ev "No issues found!" \
73+
| grep -Ev "Analyzing.+testing/scenario_app"`
74+
echo "$RESULTS"
75+
if [ -n "$RESULTS" ]; then
76+
echo "Failed."
77+
exit 1;
78+
fi

testing/dart/canvas_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:io';
56
import 'dart:typed_data';
67
import 'dart:ui';
7-
import 'dart:io';
88
import 'package:image/image.dart' as dart_image;
99

1010
import 'package:path/path.dart' as path;
Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,69 @@
1-
import 'dart:ui' as ui;
2-
import 'dart:typed_data';
31
import 'dart:convert';
2+
import 'dart:typed_data';
3+
import 'dart:ui' as ui;
44

55
import 'package:test/test.dart';
66

77
void main() {
88

99
ByteData _makeByteData(String str) {
10-
var list = utf8.encode(str);
11-
var buffer = list is Uint8List ? list.buffer : new Uint8List.fromList(list).buffer;
10+
final Uint8List list = utf8.encode(str);
11+
final ByteBuffer buffer = list is Uint8List ? list.buffer : Uint8List.fromList(list).buffer;
1212
return ByteData.view(buffer);
1313
}
1414

15-
String _getString(ByteData data) {
16-
final buffer = data.buffer;
17-
var list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
18-
return utf8.decode(list);
19-
}
20-
2115
void _resize(ui.ChannelBuffers buffers, String name, int newSize) {
22-
buffers.handleMessage(_makeByteData("resize\r$name\r$newSize"));
16+
buffers.handleMessage(_makeByteData('resize\r$name\r$newSize'));
2317
}
2418

2519
test('push drain', () async {
26-
String channel = "foo";
27-
ByteData data = _makeByteData('bar');
28-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
29-
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
20+
const String channel = 'foo';
21+
final ByteData data = _makeByteData('bar');
22+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
23+
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
3024
buffers.push(channel, data, callback);
3125
await buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) {
3226
expect(drainedData, equals(data));
3327
expect(drainedCallback, equals(callback));
28+
return;
3429
});
3530
});
3631

3732
test('push drain zero', () async {
38-
String channel = "foo";
39-
ByteData data = _makeByteData('bar');
33+
const String channel = 'foo';
34+
final ByteData data = _makeByteData('bar');
35+
final
4036
ui.ChannelBuffers buffers = ui.ChannelBuffers();
41-
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
37+
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
4238
_resize(buffers, channel, 0);
4339
buffers.push(channel, data, callback);
4440
bool didCall = false;
4541
await buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) {
4642
didCall = true;
43+
return;
4744
});
4845
expect(didCall, equals(false));
4946
});
5047

5148
test('empty', () async {
52-
String channel = "foo";
53-
ByteData data = _makeByteData('bar');
54-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
55-
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
49+
const String channel = 'foo';
50+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
5651
bool didCall = false;
5752
await buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) {
5853
didCall = true;
54+
return;
5955
});
6056
expect(didCall, equals(false));
6157
});
6258

6359
test('overflow', () async {
64-
String channel = "foo";
65-
ByteData one = _makeByteData('one');
66-
ByteData two = _makeByteData('two');
67-
ByteData three = _makeByteData('three');
68-
ByteData four = _makeByteData('four');
69-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
70-
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
60+
const String channel = 'foo';
61+
final ByteData one = _makeByteData('one');
62+
final ByteData two = _makeByteData('two');
63+
final ByteData three = _makeByteData('three');
64+
final ByteData four = _makeByteData('four');
65+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
66+
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
7167
_resize(buffers, channel, 3);
7268
expect(buffers.push(channel, one, callback), equals(false));
7369
expect(buffers.push(channel, two, callback), equals(false));
@@ -79,17 +75,18 @@ void main() {
7975
expect(drainedData, equals(two));
8076
expect(drainedCallback, equals(callback));
8177
}
78+
return;
8279
});
8380
expect(counter, equals(3));
8481
});
8582

8683
test('resize drop', () async {
87-
String channel = "foo";
88-
ByteData one = _makeByteData('one');
89-
ByteData two = _makeByteData('two');
90-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
84+
const String channel = 'foo';
85+
final ByteData one = _makeByteData('one');
86+
final ByteData two = _makeByteData('two');
87+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
9188
_resize(buffers, channel, 100);
92-
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
89+
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
9390
expect(buffers.push(channel, one, callback), equals(false));
9491
expect(buffers.push(channel, two, callback), equals(false));
9592
_resize(buffers, channel, 1);
@@ -99,20 +96,21 @@ void main() {
9996
expect(drainedData, equals(two));
10097
expect(drainedCallback, equals(callback));
10198
}
99+
return;
102100
});
103101
expect(counter, equals(1));
104102
});
105103

106104
test('resize dropping calls callback', () async {
107-
String channel = "foo";
108-
ByteData one = _makeByteData('one');
109-
ByteData two = _makeByteData('two');
110-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
105+
const String channel = 'foo';
106+
final ByteData one = _makeByteData('one');
107+
final ByteData two = _makeByteData('two');
108+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
111109
bool didCallCallback = false;
112-
ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
110+
final ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
113111
didCallCallback = true;
114112
};
115-
ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
113+
final ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
116114
_resize(buffers, channel, 100);
117115
expect(buffers.push(channel, one, oneCallback), equals(false));
118116
expect(buffers.push(channel, two, twoCallback), equals(false));
@@ -121,30 +119,30 @@ void main() {
121119
});
122120

123121
test('overflow calls callback', () async {
124-
String channel = "foo";
125-
ByteData one = _makeByteData('one');
126-
ByteData two = _makeByteData('two');
127-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
122+
const String channel = 'foo';
123+
final ByteData one = _makeByteData('one');
124+
final ByteData two = _makeByteData('two');
125+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
128126
bool didCallCallback = false;
129-
ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
127+
final ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
130128
didCallCallback = true;
131129
};
132-
ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
130+
final ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
133131
_resize(buffers, channel, 1);
134132
expect(buffers.push(channel, one, oneCallback), equals(false));
135133
expect(buffers.push(channel, two, twoCallback), equals(true));
136134
expect(didCallCallback, equals(true));
137135
});
138136

139137
test('handle garbage', () async {
140-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
141-
expect(() => buffers.handleMessage(_makeByteData("asdfasdf")),
138+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
139+
expect(() => buffers.handleMessage(_makeByteData('asdfasdf')),
142140
throwsException);
143141
});
144142

145143
test('handle resize garbage', () async {
146-
ui.ChannelBuffers buffers = ui.ChannelBuffers();
147-
expect(() => buffers.handleMessage(_makeByteData("resize\rfoo\rbar")),
144+
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
145+
expect(() => buffers.handleMessage(_makeByteData('resize\rfoo\rbar')),
148146
throwsException);
149147
});
150148
}

testing/dart/color_filter_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ void main() {
4242
}
4343

4444
test('ColorFilter - nulls', () async {
45-
final Paint paint = Paint()..colorFilter = ColorFilter.mode(null, null);
45+
final Paint paint = Paint()..colorFilter = const ColorFilter.mode(null, null);
4646
expect(paint.colorFilter, null);
4747

48-
paint.colorFilter = ColorFilter.matrix(null);
48+
paint.colorFilter = const ColorFilter.matrix(null);
4949
expect(paint.colorFilter, null);
5050
});
5151

5252
test('ColorFilter - mode', () async {
5353
final Paint paint = Paint()
5454
..color = green
55-
..colorFilter = ColorFilter.mode(red, BlendMode.color);
55+
..colorFilter = const ColorFilter.mode(red, BlendMode.color);
5656

5757
Uint32List bytes = await getBytesForPaint(paint);
5858
expect(bytes[0], greenRedColorBlend);
@@ -65,7 +65,7 @@ void main() {
6565
test('ColorFilter - matrix', () async {
6666
final Paint paint = Paint()
6767
..color = green
68-
..colorFilter = ColorFilter.matrix(greyscaleColorMatrix);
68+
..colorFilter = const ColorFilter.matrix(greyscaleColorMatrix);
6969

7070
Uint32List bytes = await getBytesForPaint(paint);
7171
expect(bytes[0], greenGreyscaled);
@@ -78,7 +78,7 @@ void main() {
7878
test('ColorFilter - linearToSrgbGamma', () async {
7979
final Paint paint = Paint()
8080
..color = green
81-
..colorFilter = ColorFilter.linearToSrgbGamma();
81+
..colorFilter = const ColorFilter.linearToSrgbGamma();
8282

8383
Uint32List bytes = await getBytesForPaint(paint);
8484
expect(bytes[0], greenLinearToSrgbGamma);
@@ -91,7 +91,7 @@ void main() {
9191
test('ColorFilter - srgbToLinearGamma', () async {
9292
final Paint paint = Paint()
9393
..color = green
94-
..colorFilter = ColorFilter.srgbToLinearGamma();
94+
..colorFilter = const ColorFilter.srgbToLinearGamma();
9595

9696
Uint32List bytes = await getBytesForPaint(paint);
9797
expect(bytes[0], greenSrgbToLinearGamma);

testing/dart/encoding_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import 'package:test/test.dart';
1313
const int _kWidth = 10;
1414
const int _kRadius = 2;
1515

16-
const Color _kBlack = const Color.fromRGBO(0, 0, 0, 1.0);
17-
const Color _kGreen = const Color.fromRGBO(0, 255, 0, 1.0);
16+
const Color _kBlack = Color.fromRGBO(0, 0, 0, 1.0);
17+
const Color _kGreen = Color.fromRGBO(0, 255, 0, 1.0);
1818

1919
void main() {
2020
group('Image.toByteData', () {

testing/dart/plugin_utilities_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Foo {
1414
double getDouble() => 1.0;
1515
}
1616

17-
const Foo foo = const Foo();
17+
const Foo foo = Foo();
1818

1919
void main() {
2020
test('PluginUtilities Callback Handles', () {

testing/dart/window_hooks_integration_test.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,6 @@ void main() {
339339
});
340340

341341
test('Window padding/insets/viewPadding/systemGestureInsets', () {
342-
final double oldDPR = window.devicePixelRatio;
343-
final Size oldSize = window.physicalSize;
344-
final double oldPhysicalDepth = window.physicalDepth;
345-
final WindowPadding oldPadding = window.viewPadding;
346-
final WindowPadding oldInsets = window.viewInsets;
347-
final WindowPadding oldSystemGestureInsets = window.systemGestureInsets;
348-
349342
_updateWindowMetrics(
350343
1.0, // DPR
351344
800.0, // width

testing/dart/window_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main() {
2121
});
2222

2323
test('FrameTiming.toString has the correct format', () {
24-
FrameTiming timing = FrameTiming(<int>[1000, 8000, 9000, 19500]);
24+
final FrameTiming timing = FrameTiming(<int>[1000, 8000, 9000, 19500]);
2525
expect(timing.toString(), 'FrameTiming(buildDuration: 7.0ms, rasterDuration: 10.5ms, totalSpan: 18.5ms)');
2626
});
2727
}

0 commit comments

Comments
 (0)