Skip to content

Commit

Permalink
dart analysis of tests, cleanup (flutter#13033)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Oct 9, 2019
1 parent 2666765 commit 6bd0ef3
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 84 deletions.
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# private fields, especially on the Window object):

analyzer:
# this test pretends to be part of dart:ui and results in lots of false
# positives.
exclude: [ testing/dart/window_hooks_integration_test.dart ]
strong-mode:
implicit-dynamic: false
errors:
Expand Down
36 changes: 34 additions & 2 deletions ci/analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ fi

echo "Analyzing flutter_frontend_server..."
RESULTS=`dartanalyzer \
--packages=flutter/flutter_frontend_server/.packages \
--packages=flutter/flutter_frontend_server/.packages \
--options flutter/analysis_options.yaml \
flutter/flutter_frontend_server \
flutter/flutter_frontend_server \
2>&1 \
| grep -Ev "No issues found!" \
| grep -Ev "Analyzing.+frontend_server"`
Expand All @@ -46,3 +46,35 @@ if [ -n "$RESULTS" ]; then
echo "Failed."
exit 1;
fi

echo "Analyzing testing/dart..."
flutter/tools/gn --unoptimized
ninja -C out/host_debug_unopt sky_engine sky_services
(cd flutter/testing/dart && pub get)
RESULTS=`dartanalyzer \
--packages=flutter/testing/dart/.packages \
--options flutter/analysis_options.yaml \
flutter/testing/dart \
2>&1 \
| grep -Ev "No issues found!" \
| grep -Ev "Analyzing.+testing/dart"`
echo "$RESULTS"
if [ -n "$RESULTS" ]; then
echo "Failed."
exit 1;
fi

echo "Analyzing testing/scenario_app..."
(cd flutter/testing/scenario_app && pub get)
RESULTS=`dartanalyzer \
--packages=flutter/testing/scenario_app/.packages \
--options flutter/analysis_options.yaml \
flutter/testing/scenario_app \
2>&1 \
| grep -Ev "No issues found!" \
| grep -Ev "Analyzing.+testing/scenario_app"`
echo "$RESULTS"
if [ -n "$RESULTS" ]; then
echo "Failed."
exit 1;
fi
2 changes: 1 addition & 1 deletion testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'dart:io';
import 'package:image/image.dart' as dart_image;

import 'package:path/path.dart' as path;
Expand Down
98 changes: 48 additions & 50 deletions testing/dart/channel_buffers_test.dart
Original file line number Diff line number Diff line change
@@ -1,73 +1,69 @@
import 'dart:ui' as ui;
import 'dart:typed_data';
import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:test/test.dart';

void main() {

ByteData _makeByteData(String str) {
var list = utf8.encode(str);
var buffer = list is Uint8List ? list.buffer : new Uint8List.fromList(list).buffer;
final Uint8List list = utf8.encode(str);
final ByteBuffer buffer = list is Uint8List ? list.buffer : Uint8List.fromList(list).buffer;
return ByteData.view(buffer);
}

String _getString(ByteData data) {
final buffer = data.buffer;
var list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
return utf8.decode(list);
}

void _resize(ui.ChannelBuffers buffers, String name, int newSize) {
buffers.handleMessage(_makeByteData("resize\r$name\r$newSize"));
buffers.handleMessage(_makeByteData('resize\r$name\r$newSize'));
}

test('push drain', () async {
String channel = "foo";
ByteData data = _makeByteData('bar');
ui.ChannelBuffers buffers = ui.ChannelBuffers();
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
const String channel = 'foo';
final ByteData data = _makeByteData('bar');
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
buffers.push(channel, data, callback);
await buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) {
expect(drainedData, equals(data));
expect(drainedCallback, equals(callback));
return;
});
});

test('push drain zero', () async {
String channel = "foo";
ByteData data = _makeByteData('bar');
const String channel = 'foo';
final ByteData data = _makeByteData('bar');
final
ui.ChannelBuffers buffers = ui.ChannelBuffers();
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
_resize(buffers, channel, 0);
buffers.push(channel, data, callback);
bool didCall = false;
await buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) {
didCall = true;
return;
});
expect(didCall, equals(false));
});

test('empty', () async {
String channel = "foo";
ByteData data = _makeByteData('bar');
ui.ChannelBuffers buffers = ui.ChannelBuffers();
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
const String channel = 'foo';
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
bool didCall = false;
await buffers.drain(channel, (ByteData drainedData, ui.PlatformMessageResponseCallback drainedCallback) {
didCall = true;
return;
});
expect(didCall, equals(false));
});

test('overflow', () async {
String channel = "foo";
ByteData one = _makeByteData('one');
ByteData two = _makeByteData('two');
ByteData three = _makeByteData('three');
ByteData four = _makeByteData('four');
ui.ChannelBuffers buffers = ui.ChannelBuffers();
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
const String channel = 'foo';
final ByteData one = _makeByteData('one');
final ByteData two = _makeByteData('two');
final ByteData three = _makeByteData('three');
final ByteData four = _makeByteData('four');
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
_resize(buffers, channel, 3);
expect(buffers.push(channel, one, callback), equals(false));
expect(buffers.push(channel, two, callback), equals(false));
Expand All @@ -79,17 +75,18 @@ void main() {
expect(drainedData, equals(two));
expect(drainedCallback, equals(callback));
}
return;
});
expect(counter, equals(3));
});

test('resize drop', () async {
String channel = "foo";
ByteData one = _makeByteData('one');
ByteData two = _makeByteData('two');
ui.ChannelBuffers buffers = ui.ChannelBuffers();
const String channel = 'foo';
final ByteData one = _makeByteData('one');
final ByteData two = _makeByteData('two');
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
_resize(buffers, channel, 100);
ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
final ui.PlatformMessageResponseCallback callback = (ByteData responseData) {};
expect(buffers.push(channel, one, callback), equals(false));
expect(buffers.push(channel, two, callback), equals(false));
_resize(buffers, channel, 1);
Expand All @@ -99,20 +96,21 @@ void main() {
expect(drainedData, equals(two));
expect(drainedCallback, equals(callback));
}
return;
});
expect(counter, equals(1));
});

test('resize dropping calls callback', () async {
String channel = "foo";
ByteData one = _makeByteData('one');
ByteData two = _makeByteData('two');
ui.ChannelBuffers buffers = ui.ChannelBuffers();
const String channel = 'foo';
final ByteData one = _makeByteData('one');
final ByteData two = _makeByteData('two');
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
bool didCallCallback = false;
ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
final ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
didCallCallback = true;
};
ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
final ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
_resize(buffers, channel, 100);
expect(buffers.push(channel, one, oneCallback), equals(false));
expect(buffers.push(channel, two, twoCallback), equals(false));
Expand All @@ -121,30 +119,30 @@ void main() {
});

test('overflow calls callback', () async {
String channel = "foo";
ByteData one = _makeByteData('one');
ByteData two = _makeByteData('two');
ui.ChannelBuffers buffers = ui.ChannelBuffers();
const String channel = 'foo';
final ByteData one = _makeByteData('one');
final ByteData two = _makeByteData('two');
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
bool didCallCallback = false;
ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
final ui.PlatformMessageResponseCallback oneCallback = (ByteData responseData) {
didCallCallback = true;
};
ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
final ui.PlatformMessageResponseCallback twoCallback = (ByteData responseData) {};
_resize(buffers, channel, 1);
expect(buffers.push(channel, one, oneCallback), equals(false));
expect(buffers.push(channel, two, twoCallback), equals(true));
expect(didCallCallback, equals(true));
});

test('handle garbage', () async {
ui.ChannelBuffers buffers = ui.ChannelBuffers();
expect(() => buffers.handleMessage(_makeByteData("asdfasdf")),
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
expect(() => buffers.handleMessage(_makeByteData('asdfasdf')),
throwsException);
});

test('handle resize garbage', () async {
ui.ChannelBuffers buffers = ui.ChannelBuffers();
expect(() => buffers.handleMessage(_makeByteData("resize\rfoo\rbar")),
final ui.ChannelBuffers buffers = ui.ChannelBuffers();
expect(() => buffers.handleMessage(_makeByteData('resize\rfoo\rbar')),
throwsException);
});
}
12 changes: 6 additions & 6 deletions testing/dart/color_filter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ void main() {
}

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

paint.colorFilter = ColorFilter.matrix(null);
paint.colorFilter = const ColorFilter.matrix(null);
expect(paint.colorFilter, null);
});

test('ColorFilter - mode', () async {
final Paint paint = Paint()
..color = green
..colorFilter = ColorFilter.mode(red, BlendMode.color);
..colorFilter = const ColorFilter.mode(red, BlendMode.color);

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

Uint32List bytes = await getBytesForPaint(paint);
expect(bytes[0], greenGreyscaled);
Expand All @@ -78,7 +78,7 @@ void main() {
test('ColorFilter - linearToSrgbGamma', () async {
final Paint paint = Paint()
..color = green
..colorFilter = ColorFilter.linearToSrgbGamma();
..colorFilter = const ColorFilter.linearToSrgbGamma();

Uint32List bytes = await getBytesForPaint(paint);
expect(bytes[0], greenLinearToSrgbGamma);
Expand All @@ -91,7 +91,7 @@ void main() {
test('ColorFilter - srgbToLinearGamma', () async {
final Paint paint = Paint()
..color = green
..colorFilter = ColorFilter.srgbToLinearGamma();
..colorFilter = const ColorFilter.srgbToLinearGamma();

Uint32List bytes = await getBytesForPaint(paint);
expect(bytes[0], greenSrgbToLinearGamma);
Expand Down
4 changes: 2 additions & 2 deletions testing/dart/encoding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import 'package:test/test.dart';
const int _kWidth = 10;
const int _kRadius = 2;

const Color _kBlack = const Color.fromRGBO(0, 0, 0, 1.0);
const Color _kGreen = const Color.fromRGBO(0, 255, 0, 1.0);
const Color _kBlack = Color.fromRGBO(0, 0, 0, 1.0);
const Color _kGreen = Color.fromRGBO(0, 255, 0, 1.0);

void main() {
group('Image.toByteData', () {
Expand Down
2 changes: 1 addition & 1 deletion testing/dart/plugin_utilities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Foo {
double getDouble() => 1.0;
}

const Foo foo = const Foo();
const Foo foo = Foo();

void main() {
test('PluginUtilities Callback Handles', () {
Expand Down
7 changes: 0 additions & 7 deletions testing/dart/window_hooks_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,6 @@ void main() {
});

test('Window padding/insets/viewPadding/systemGestureInsets', () {
final double oldDPR = window.devicePixelRatio;
final Size oldSize = window.physicalSize;
final double oldPhysicalDepth = window.physicalDepth;
final WindowPadding oldPadding = window.viewPadding;
final WindowPadding oldInsets = window.viewInsets;
final WindowPadding oldSystemGestureInsets = window.systemGestureInsets;

_updateWindowMetrics(
1.0, // DPR
800.0, // width
Expand Down
2 changes: 1 addition & 1 deletion testing/dart/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
});

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

0 comments on commit 6bd0ef3

Please sign in to comment.