diff --git a/analysis_options.yaml b/analysis_options.yaml index 6420a5457adca..699ca970ef474 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -10,9 +10,6 @@ # private fields, especially on the Window object): analyzer: - language: - enableStrictCallChecks: true - enableSuperMixins: true strong-mode: implicit-dynamic: false errors: @@ -20,6 +17,7 @@ analyzer: missing_required_param: warning # treat missing returns as a warning (not a hint) missing_return: warning + native_function_body_in_non_sdk_code: ignore # allow having TODOs in the code todo: ignore # `flutter analyze` (without `--watch`) just ignores directories @@ -94,7 +92,6 @@ linter: # - parameter_assignments # we do this commonly - prefer_adjacent_string_concatenation - prefer_asserts_in_initializer_lists - - prefer_bool_in_asserts - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors diff --git a/ci/analyze.sh b/ci/analyze.sh index c86d506858e0c..09bf3e12f3993 100755 --- a/ci/analyze.sh +++ b/ci/analyze.sh @@ -4,13 +4,7 @@ RESULTS=`dartanalyzer \ --options flutter/analysis_options.yaml \ out/host_debug_unopt/gen/sky/bindings/dart_ui/ui.dart \ 2>&1 \ - | grep -v "Native functions can only be declared in the SDK and code that is loaded through native extensions" \ - | grep -Ev "The function '.+' (is not|isn't) used" \ - | grep -Ev "The top level variable '.+' isn't used" \ - | grep -Ev "Undefined name 'main'" \ - | grep -v "The library 'dart:_internal' is internal" \ - | grep -Ev "Unused import.+ui\.dart" \ - | grep -Ev "[0-9]+ errors.*found\." \ + | grep -Ev "No issues found!" \ | grep -Ev "Analyzing.+out/host_debug_unopt/gen/sky/bindings/dart_ui/ui\.dart"` echo "$RESULTS" diff --git a/lib/ui/hooks.dart b/lib/ui/hooks.dart index 1262a51ec12cf..465e596ec4c25 100644 --- a/lib/ui/hooks.dart +++ b/lib/ui/hooks.dart @@ -2,17 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(dnfield): Remove unused_import ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved. + part of dart.ui; +// ignore: unused_element String _decodeUTF8(ByteData message) { return message != null ? utf8.decoder.convert(message.buffer.asUint8List()) : null; } +// ignore: unused_element dynamic _decodeJSON(String message) { return message != null ? json.decode(message) : null; } @pragma('vm:entry-point') +// ignore: unused_element void _updateWindowMetrics(double devicePixelRatio, double width, double height, @@ -50,9 +55,11 @@ String _localeClosure() { } @pragma('vm:entry-point') +// ignore: unused_element _LocaleClosure _getLocaleClosure() => _localeClosure; @pragma('vm:entry-point') +// ignore: unused_element void _updateLocales(List locales) { const int stringsPerLocale = 4; final int numLocales = locales.length ~/ stringsPerLocale; @@ -71,6 +78,7 @@ void _updateLocales(List locales) { } @pragma('vm:entry-point') +// ignore: unused_element void _updateUserSettingsData(String jsonData) { final Map data = json.decode(jsonData); if (data.isEmpty) { @@ -90,12 +98,14 @@ void _updateAlwaysUse24HourFormat(bool alwaysUse24HourFormat) { } @pragma('vm:entry-point') +// ignore: unused_element void _updateSemanticsEnabled(bool enabled) { window._semanticsEnabled = enabled; _invoke(window.onSemanticsEnabledChanged, window._onSemanticsEnabledChangedZone); } @pragma('vm:entry-point') +// ignore: unused_element void _updateAccessibilityFeatures(int values) { final AccessibilityFeatures newFeatures = new AccessibilityFeatures._(values); if (newFeatures == window._accessibilityFeatures) @@ -122,12 +132,14 @@ void _dispatchPlatformMessage(String name, ByteData data, int responseId) { } @pragma('vm:entry-point') +// ignore: unused_element void _dispatchPointerDataPacket(ByteData packet) { if (window.onPointerDataPacket != null) _invoke1(window.onPointerDataPacket, window._onPointerDataPacketZone, _unpackPointerDataPacket(packet)); } @pragma('vm:entry-point') +// ignore: unused_element void _dispatchSemanticsAction(int id, int action, ByteData args) { _invoke3( window.onSemanticsAction, @@ -139,11 +151,13 @@ void _dispatchSemanticsAction(int id, int action, ByteData args) { } @pragma('vm:entry-point') +// ignore: unused_element void _beginFrame(int microseconds) { _invoke1(window.onBeginFrame, window._onBeginFrameZone, new Duration(microseconds: microseconds)); } @pragma('vm:entry-point') +// ignore: unused_element void _drawFrame() { _invoke(window.onDrawFrame, window._onDrawFrameZone); } @@ -177,6 +191,7 @@ void _invoke1(void callback(A a), Zone zone, A arg) { } /// Invokes [callback] inside the given [zone] passing it [arg1] and [arg2]. +// ignore: unused_element void _invoke2(void callback(A1 a1, A2 a2), Zone zone, A1 arg1, A2 arg2) { if (callback == null) return; diff --git a/lib/ui/natives.dart b/lib/ui/natives.dart index 2a42a7298b428..1e9a0798f96f6 100644 --- a/lib/ui/natives.dart +++ b/lib/ui/natives.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(dnfield): remove unused_element ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved. + part of dart.ui; // Corelib 'print' implementation. @@ -28,7 +30,7 @@ Future _scheduleFrame( } @pragma('vm:entry-point') -void _setupHooks() { +void _setupHooks() { // ignore: unused_element assert(() { // In debug mode, register the schedule frame extension. developer.registerExtension('ext.ui.window.scheduleFrame', _scheduleFrame); @@ -67,9 +69,9 @@ int _getCallbackHandle(Function closure) native 'GetCallbackHandle'; Function _getCallbackFromHandle(int handle) native 'GetCallbackFromHandle'; // Required for gen_snapshot to work correctly. -int _isolateId; +int _isolateId; // ignore: unused_element @pragma('vm:entry-point') -Function _getPrintClosure() => _print; +Function _getPrintClosure() => _print; // ignore: unused_element @pragma('vm:entry-point') -Function _getScheduleMicrotaskClosure() => _scheduleMicrotask; +Function _getScheduleMicrotaskClosure() => _scheduleMicrotask; // ignore: unused_element diff --git a/lib/ui/ui.dart b/lib/ui/ui.dart index 47fa1bb53bc37..cef4db81cee0e 100644 --- a/lib/ui/ui.dart +++ b/lib/ui/ui.dart @@ -11,12 +11,12 @@ /// text, layout, and rendering subsystems. library dart.ui; -import 'dart:_internal' hide Symbol; +import 'dart:_internal' hide Symbol; // ignore: import_internal_library, unused_import import 'dart:async'; import 'dart:collection' as collection; import 'dart:convert'; import 'dart:developer' as developer; -import 'dart:io'; +import 'dart:io'; // ignore: unused_import import 'dart:isolate' show SendPort; import 'dart:math' as math; import 'dart:nativewrappers'; diff --git a/runtime/fixtures/simple_main.dart b/runtime/fixtures/simple_main.dart index 55187d8642bfa..f47442176160f 100644 --- a/runtime/fixtures/simple_main.dart +++ b/runtime/fixtures/simple_main.dart @@ -3,5 +3,5 @@ // found in the LICENSE file. void main() { - print("Hello"); + print('Hello'); } diff --git a/testing/dart/canvas_test.dart b/testing/dart/canvas_test.dart index 9d4704038e9f0..4a14a92da6624 100644 --- a/testing/dart/canvas_test.dart +++ b/testing/dart/canvas_test.dart @@ -2,51 +2,52 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui'; import 'dart:typed_data'; +import 'dart:ui'; import 'package:test/test.dart'; -typedef void CanvasCallback(Canvas canvas); +typedef CanvasCallback = void Function(Canvas canvas); void testCanvas(CanvasCallback callback) { try { callback(Canvas(PictureRecorder(), Rect.fromLTRB(0.0, 0.0, 0.0, 0.0))); - } catch (error) { } + } catch (error) { } // ignore: empty_catches } void main() { - test("canvas APIs should not crash", () { - Paint paint = Paint(); - Rect rect = Rect.fromLTRB(double.nan, double.nan, double.nan, double.nan); - RRect rrect = RRect.fromRectAndCorners(rect); - Offset offset = Offset(double.nan, double.nan); - Path path = Path(); - Color color = Color(0); - Paragraph paragraph = ParagraphBuilder(ParagraphStyle()).build(); + test('canvas APIs should not crash', () { + final Paint paint = Paint(); + final Rect rect = Rect.fromLTRB(double.nan, double.nan, double.nan, double.nan); + final RRect rrect = RRect.fromRectAndCorners(rect); + const Offset offset = Offset(double.nan, double.nan); + final Path path = Path(); + const Color color = Color(0); + final Paragraph paragraph = ParagraphBuilder(ParagraphStyle()).build(); - PictureRecorder recorder = PictureRecorder(); - Canvas recorderCanvas = Canvas(recorder); - Picture picture = recorder.endRecording(); - Image image = picture.toImage(1, 1); + final PictureRecorder recorder = PictureRecorder(); + final Canvas recorderCanvas = Canvas(recorder); + recorderCanvas.scale(1.0, 1.0); + final Picture picture = recorder.endRecording(); + final Image image = picture.toImage(1, 1); - try { Canvas(null, null); } catch (error) { } - try { Canvas(null, rect); } catch (error) { } - try { Canvas(PictureRecorder(), null); } catch (error) { } - try { Canvas(PictureRecorder(), rect); } catch (error) { } + try { Canvas(null, null); } catch (error) { } // ignore: empty_catches + try { Canvas(null, rect); } catch (error) { } // ignore: empty_catches + try { Canvas(PictureRecorder(), null); } catch (error) { } // ignore: empty_catches + try { Canvas(PictureRecorder(), rect); } catch (error) { } // ignore: empty_catches try { PictureRecorder() ..endRecording() ..endRecording() ..endRecording(); - } catch (error) { } + } catch (error) { } // ignore: empty_catches testCanvas((Canvas canvas) => canvas.clipPath(path)); testCanvas((Canvas canvas) => canvas.clipRect(rect)); testCanvas((Canvas canvas) => canvas.clipRRect(rrect)); testCanvas((Canvas canvas) => canvas.drawArc(rect, 0.0, 0.0, false, paint)); - testCanvas((Canvas canvas) => canvas.drawAtlas(image, [], [], [], BlendMode.src, rect, paint)); + testCanvas((Canvas canvas) => canvas.drawAtlas(image, [], [], [], BlendMode.src, rect, paint)); testCanvas((Canvas canvas) => canvas.drawCircle(offset, double.nan, paint)); testCanvas((Canvas canvas) => canvas.drawColor(color, BlendMode.src)); testCanvas((Canvas canvas) => canvas.drawDRRect(rrect, rrect, paint)); @@ -59,7 +60,7 @@ void main() { testCanvas((Canvas canvas) => canvas.drawParagraph(paragraph, offset)); testCanvas((Canvas canvas) => canvas.drawPath(path, paint)); testCanvas((Canvas canvas) => canvas.drawPicture(picture)); - testCanvas((Canvas canvas) => canvas.drawPoints(PointMode.points, [], paint)); + testCanvas((Canvas canvas) => canvas.drawPoints(PointMode.points, [], paint)); testCanvas((Canvas canvas) => canvas.drawRawAtlas(image, Float32List(0), Float32List(0), Int32List(0), BlendMode.src, rect, paint)); testCanvas((Canvas canvas) => canvas.drawRawPoints(PointMode.points, Float32List(0), paint)); testCanvas((Canvas canvas) => canvas.drawRect(rect, paint)); @@ -67,7 +68,7 @@ void main() { testCanvas((Canvas canvas) => canvas.drawShadow(path, color, double.nan, null)); testCanvas((Canvas canvas) => canvas.drawShadow(path, color, double.nan, false)); testCanvas((Canvas canvas) => canvas.drawShadow(path, color, double.nan, true)); - testCanvas((Canvas canvas) => canvas.drawVertices(Vertices(VertexMode.triangles, []), null, paint)); + testCanvas((Canvas canvas) => canvas.drawVertices(Vertices(VertexMode.triangles, []), null, paint)); testCanvas((Canvas canvas) => canvas.getSaveCount()); testCanvas((Canvas canvas) => canvas.restore()); testCanvas((Canvas canvas) => canvas.rotate(double.nan)); diff --git a/testing/dart/codec_test.dart b/testing/dart/codec_test.dart index 78b6930f5ea6c..728bfdcc269c1 100644 --- a/testing/dart/codec_test.dart +++ b/testing/dart/codec_test.dart @@ -2,10 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; import 'dart:io'; -import 'dart:ui' as ui; import 'dart:typed_data'; +import 'dart:ui' as ui; import 'package:test/test.dart'; import 'package:path/path.dart' as path; @@ -27,7 +26,7 @@ void main() { }); test('Fails with invalid data', () async { - Uint8List data = new Uint8List.fromList([1, 2, 3]); + final Uint8List data = Uint8List.fromList([1, 2, 3]); expect( ui.instantiateImageCodec(data), throwsA(exceptionWithMessage('operation failed')) @@ -35,64 +34,64 @@ void main() { }); test('nextFrame', () async { - Uint8List data = await _getSkiaResource('test640x479.gif').readAsBytes(); - ui.Codec codec = await ui.instantiateImageCodec(data); - List> decodedFrameInfos = []; + final Uint8List data = await _getSkiaResource('test640x479.gif').readAsBytes(); + final ui.Codec codec = await ui.instantiateImageCodec(data); + final List> decodedFrameInfos = >[]; for (int i = 0; i < 5; i++) { - ui.FrameInfo frameInfo = await codec.getNextFrame(); - decodedFrameInfos.add([ + final ui.FrameInfo frameInfo = await codec.getNextFrame(); + decodedFrameInfos.add([ frameInfo.duration.inMilliseconds, frameInfo.image.width, frameInfo.image.height, ]); } - expect(decodedFrameInfos, equals([ - [200, 640, 479], - [200, 640, 479], - [200, 640, 479], - [200, 640, 479], - [200, 640, 479], + expect(decodedFrameInfos, equals(>[ + [200, 640, 479], + [200, 640, 479], + [200, 640, 479], + [200, 640, 479], + [200, 640, 479], ])); }); test('decodedCacheRatioCap', () async { // No real way to test the native layer, but a smoke test here to at least // verify that animation is still consistent with caching disabled. - Uint8List data = await _getSkiaResource('test640x479.gif').readAsBytes(); - ui.Codec codec = await ui.instantiateImageCodec(data, decodedCacheRatioCap: 1.0); - List> decodedFrameInfos = []; + final Uint8List data = await _getSkiaResource('test640x479.gif').readAsBytes(); + final ui.Codec codec = await ui.instantiateImageCodec(data, decodedCacheRatioCap: 1.0); + final List> decodedFrameInfos = >[]; for (int i = 0; i < 5; i++) { - ui.FrameInfo frameInfo = await codec.getNextFrame(); - decodedFrameInfos.add([ + final ui.FrameInfo frameInfo = await codec.getNextFrame(); + decodedFrameInfos.add([ frameInfo.duration.inMilliseconds, frameInfo.image.width, frameInfo.image.height, ]); } - expect(decodedFrameInfos, equals([ - [200, 640, 479], - [200, 640, 479], - [200, 640, 479], - [200, 640, 479], - [200, 640, 479], + expect(decodedFrameInfos, equals(>[ + [200, 640, 479], + [200, 640, 479], + [200, 640, 479], + [200, 640, 479], + [200, 640, 479], ])); }); test('non animated image', () async { - Uint8List data = await _getSkiaResource('baby_tux.png').readAsBytes(); - ui.Codec codec = await ui.instantiateImageCodec(data); - List> decodedFrameInfos = []; + final Uint8List data = await _getSkiaResource('baby_tux.png').readAsBytes(); + final ui.Codec codec = await ui.instantiateImageCodec(data); + final List> decodedFrameInfos = >[]; for (int i = 0; i < 2; i++) { - ui.FrameInfo frameInfo = await codec.getNextFrame(); - decodedFrameInfos.add([ + final ui.FrameInfo frameInfo = await codec.getNextFrame(); + decodedFrameInfos.add([ frameInfo.duration.inMilliseconds, frameInfo.image.width, frameInfo.image.height, ]); } - expect(decodedFrameInfos, equals([ - [0, 240, 246], - [0, 240, 246], + expect(decodedFrameInfos, equals(>[ + [0, 240, 246], + [0, 240, 246], ])); }); } @@ -104,13 +103,13 @@ File _getSkiaResource(String fileName) { // assuming the curent working directory is engine/src. // This is fragile and should be changed once the Platform.script issue is // resolved. - String assetPath = + final String assetPath = path.join('third_party', 'skia', 'resources', 'images', fileName); - return new File(assetPath); + return File(assetPath); } Matcher exceptionWithMessage(String m) { - return predicate((e) { + return predicate((Exception e) { return e is Exception && e.toString().contains(m); }); } diff --git a/testing/dart/color_test.dart b/testing/dart/color_test.dart index 785c819aa7380..c70d2c7182f21 100644 --- a/testing/dart/color_test.dart +++ b/testing/dart/color_test.dart @@ -12,7 +12,7 @@ class NotAColor extends Color { void main() { test('color accessors should work', () { - final Color foo = const Color(0x12345678); + const Color foo = Color(0x12345678); expect(foo.alpha, equals(0x12)); expect(foo.red, equals(0x34)); expect(foo.green, equals(0x56)); @@ -20,7 +20,7 @@ void main() { }); test('paint set to black', () { - final Color c = const Color(0x00000000); + const Color c = Color(0x00000000); final Paint p = new Paint(); p.color = c; expect(c.toString(), equals('Color(0x00000000)')); @@ -28,7 +28,7 @@ void main() { test('color created with out of bounds value', () { try { - final Color c = const Color(0x100 << 24); + const Color c = Color(0x100 << 24); final Paint p = new Paint(); p.color = c; } catch (e) { @@ -38,7 +38,7 @@ void main() { test('color created with wildly out of bounds value', () { try { - final Color c = const Color(1 << 1000000); + const Color c = Color(1 << 1000000); final Paint p = new Paint(); p.color = c; } catch (e) { @@ -48,7 +48,7 @@ void main() { test('two colors are only == if they have the same runtime type', () { expect(const Color(123), equals(const Color(123))); - expect(const Color(123), equals(new Color(123))); + expect(const Color(123), equals(Color(123))); // ignore: prefer_const_constructors expect(const Color(123), isNot(equals(const Color(321)))); expect(const Color(123), isNot(equals(const NotAColor(123)))); expect(const NotAColor(123), isNot(equals(const Color(123)))); @@ -123,14 +123,14 @@ void main() { test('compute gray luminance', () { // Each color component is at 20%. - final Color lightGray = const Color(0xFF333333); + const Color lightGray = Color(0xFF333333); // Relative luminance's formula is just the linearized color value for gray. // ((0.2 + 0.055) / 1.055) ^ 2.4. expect(lightGray.computeLuminance(), equals(0.033104766570885055)); }); test('compute color luminance', () { - final Color brightRed = const Color(0xFFFF3B30); + const Color brightRed = Color(0xFFFF3B30); // 0.2126 * ((1.0 + 0.055) / 1.055) ^ 2.4 + // 0.7152 * ((0.23137254902 +0.055) / 1.055) ^ 2.4 + // 0.0722 * ((0.18823529411 + 0.055) / 1.055) ^ 2.4 diff --git a/testing/dart/encoding_test.dart b/testing/dart/encoding_test.dart index 28bba46303e92..81e53046fb68c 100644 --- a/testing/dart/encoding_test.dart +++ b/testing/dart/encoding_test.dart @@ -3,9 +3,9 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:ui'; -import 'dart:typed_data'; import 'dart:io'; +import 'dart:typed_data'; +import 'dart:ui'; import 'package:path/path.dart' as path; import 'package:test/test.dart'; @@ -20,14 +20,14 @@ void main() { group('Image.toByteData', () { group('RGBA format', () { test('works with simple image', () async { - ByteData data = await Square4x4Image.image.toByteData(); - expect(new Uint8List.view(data.buffer), Square4x4Image.bytes); + final ByteData data = await Square4x4Image.image.toByteData(); + expect(Uint8List.view(data.buffer), Square4x4Image.bytes); }); test('converts grayscale images', () async { - Image image = await GrayscaleImage.load(); - ByteData data = await image.toByteData(); - Uint8List bytes = data.buffer.asUint8List(); + final Image image = await GrayscaleImage.load(); + final ByteData data = await image.toByteData(); + final Uint8List bytes = data.buffer.asUint8List(); expect(bytes, hasLength(16)); expect(bytes, GrayscaleImage.bytesAsRgba); }); @@ -35,15 +35,15 @@ void main() { group('Unmodified format', () { test('works with simple image', () async { - Image image = Square4x4Image.image; - ByteData data = await image.toByteData(format: ImageByteFormat.rawUnmodified); - expect(new Uint8List.view(data.buffer), Square4x4Image.bytes); + final Image image = Square4x4Image.image; + final ByteData data = await image.toByteData(format: ImageByteFormat.rawUnmodified); + expect(Uint8List.view(data.buffer), Square4x4Image.bytes); }); test('works with grayscale images', () async { - Image image = await GrayscaleImage.load(); - ByteData data = await image.toByteData(format: ImageByteFormat.rawUnmodified); - Uint8List bytes = data.buffer.asUint8List(); + final Image image = await GrayscaleImage.load(); + final ByteData data = await image.toByteData(format: ImageByteFormat.rawUnmodified); + final Uint8List bytes = data.buffer.asUint8List(); expect(bytes, hasLength(4)); expect(bytes, GrayscaleImage.bytesUnmodified); }); @@ -51,46 +51,48 @@ void main() { group('PNG format', () { test('works with simple image', () async { - Image image = Square4x4Image.image; - ByteData data = await image.toByteData(format: ImageByteFormat.png); - List expected = await readFile('square.png'); - expect(new Uint8List.view(data.buffer), expected); + final Image image = Square4x4Image.image; + final ByteData data = await image.toByteData(format: ImageByteFormat.png); + final List expected = await readFile('square.png'); + expect(Uint8List.view(data.buffer), expected); }); }); }); } class Square4x4Image { + Square4x4Image._(); + static Image get image { - double width = _kWidth.toDouble(); - double radius = _kRadius.toDouble(); - double innerWidth = (_kWidth - 2 * _kRadius).toDouble(); + final double width = _kWidth.toDouble(); + final double radius = _kRadius.toDouble(); + final double innerWidth = (_kWidth - 2 * _kRadius).toDouble(); - PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = - new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, width, width)); + final PictureRecorder recorder = PictureRecorder(); + final Canvas canvas = + Canvas(recorder, Rect.fromLTWH(0.0, 0.0, width, width)); - Paint black = new Paint() + final Paint black = Paint() ..strokeWidth = 1.0 ..color = _kBlack; - Paint green = new Paint() + final Paint green = Paint() ..strokeWidth = 1.0 ..color = _kGreen; - canvas.drawRect(new Rect.fromLTWH(0.0, 0.0, width, width), black); + canvas.drawRect(Rect.fromLTWH(0.0, 0.0, width, width), black); canvas.drawRect( - new Rect.fromLTWH(radius, radius, innerWidth, innerWidth), green); + Rect.fromLTWH(radius, radius, innerWidth, innerWidth), green); return recorder.endRecording().toImage(_kWidth, _kWidth); } static List get bytes { - int bytesPerChannel = 4; - List result = new List(_kWidth * _kWidth * bytesPerChannel); + const int bytesPerChannel = 4; + final List result = List(_kWidth * _kWidth * bytesPerChannel); - fillWithColor(Color color, int min, int max) { + void fillWithColor(Color color, int min, int max) { for (int i = min; i < max; i++) { for (int j = min; j < max; j++) { - int offset = i * bytesPerChannel + j * _kWidth * bytesPerChannel; + final int offset = i * bytesPerChannel + j * _kWidth * bytesPerChannel; result[offset] = color.red; result[offset + 1] = color.green; result[offset + 2] = color.blue; @@ -107,9 +109,11 @@ class Square4x4Image { } class GrayscaleImage { + GrayscaleImage._(); + static Future load() async { - Uint8List bytes = await readFile('4x4.png'); - Completer completer = new Completer(); + final Uint8List bytes = await readFile('4x4.png'); + final Completer completer = Completer(); decodeImageFromList(bytes, (Image image) => completer.complete(image)); return await completer.future; } @@ -126,7 +130,7 @@ class GrayscaleImage { static List get bytesUnmodified => [255, 127, 127, 0]; } -Future readFile(fileName) async { - final file = new File(path.join('flutter', 'testing', 'resources', fileName)); +Future readFile(String fileName) async { + final File file = File(path.join('flutter', 'testing', 'resources', fileName)); return await file.readAsBytes(); } diff --git a/testing/dart/gradient_test.dart b/testing/dart/gradient_test.dart index b0160d019fd05..5e1bd6fd6ff13 100644 --- a/testing/dart/gradient_test.dart +++ b/testing/dart/gradient_test.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:typed_data' show Float64List; import 'dart:ui'; import 'package:test/test.dart'; @@ -66,7 +65,7 @@ void main() { Offset.zero, 1.0, ), - throwsA(const isInstanceOf()), + throwsA(const TypeMatcher()), ); }); } diff --git a/testing/dart/isolate_name_server_test.dart b/testing/dart/isolate_name_server_test.dart index d48eefc084815..5a02d9722dd4d 100644 --- a/testing/dart/isolate_name_server_test.dart +++ b/testing/dart/isolate_name_server_test.dart @@ -2,24 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; import 'dart:isolate'; import 'dart:ui'; import 'package:test/test.dart'; -const kPortName = 'foobar'; -const kErrorCode = -1; -const kStartCode = 0; -const kCloseCode = 1; -const kDeletedCode = 2; +const String kPortName = 'foobar'; +const int kErrorCode = -1; +const int kStartCode = 0; +const int kCloseCode = 1; +const int kDeletedCode = 2; void isolateSpawnEntrypoint(SendPort port) { - sendHelper(int code, [String message = '']) { + void sendHelper(int code, [String message = '']) { port.send([code, message]); } - SendPort shared = IsolateNameServer.lookupPortByName(kPortName); + final SendPort shared = IsolateNameServer.lookupPortByName(kPortName); if (shared == null) { sendHelper(kErrorCode, 'Could not find port: $kPortName'); return; @@ -35,7 +34,7 @@ void isolateSpawnEntrypoint(SendPort port) { // send another message to ensure we don't crash. shared.send('garbage'); - bool result = IsolateNameServer.removePortNameMapping(kPortName); + final bool result = IsolateNameServer.removePortNameMapping(kPortName); if (result) { sendHelper(kDeletedCode); } else { @@ -55,14 +54,14 @@ void main() { expect(IsolateNameServer.removePortNameMapping(kPortName), isFalse); // Register a SendPort. - final receivePort = new ReceivePort(); - final sendPort = receivePort.sendPort; + final ReceivePort receivePort = ReceivePort(); + final SendPort sendPort = receivePort.sendPort; expect(IsolateNameServer.registerPortWithName(sendPort, kPortName), isTrue); expect(IsolateNameServer.lookupPortByName(kPortName), sendPort); // Check we can't register the same name twice. - final receivePort2 = new ReceivePort(); - final sendPort2 = receivePort2.sendPort; + final ReceivePort receivePort2 = ReceivePort(); + final SendPort sendPort2 = receivePort2.sendPort; expect( IsolateNameServer.registerPortWithName(sendPort2, kPortName), isFalse); expect(IsolateNameServer.lookupPortByName(kPortName), sendPort); @@ -83,13 +82,13 @@ void main() { test('isolate name server multi-isolate', () async { // Register our send port with the name server. - final receivePort = new ReceivePort(); - final sendPort = receivePort.sendPort; + final ReceivePort receivePort = ReceivePort(); + final SendPort sendPort = receivePort.sendPort; expect(IsolateNameServer.registerPortWithName(sendPort, kPortName), isTrue); // Test driver. - final testReceivePort = new ReceivePort(); - testReceivePort.listen(expectAsync1((response) { + final ReceivePort testReceivePort = ReceivePort(); + testReceivePort.listen(expectAsync1((dynamic response) { final int code = response[0]; final String message = response[1]; switch (code) { @@ -110,7 +109,7 @@ void main() { } }, count: 3)); - receivePort.listen(expectAsync1((message) { + receivePort.listen(expectAsync1((dynamic message) { // If we don't get this message, we timeout and fail. expect(message, kPortName); })); diff --git a/testing/dart/locale_test.dart b/testing/dart/locale_test.dart index 9fcab7334ac5d..576df68af7064 100644 --- a/testing/dart/locale_test.dart +++ b/testing/dart/locale_test.dart @@ -8,12 +8,12 @@ import 'package:test/test.dart'; void main() { test('Locale', () { - final Null $null = null; + const Null $null = null; expect(const Locale('en').toString(), 'en'); - expect(const Locale('en'), new Locale('en', $null)); - expect(const Locale('en').hashCode, new Locale('en', $null).hashCode); - expect(const Locale('en'), isNot(new Locale('en', ''))); - expect(const Locale('en').hashCode, isNot(new Locale('en', '').hashCode)); + expect(const Locale('en'), const Locale('en', $null)); + expect(const Locale('en').hashCode, const Locale('en', $null).hashCode); + expect(const Locale('en'), isNot(const Locale('en', ''))); + expect(const Locale('en').hashCode, isNot(const Locale('en', '').hashCode)); expect(const Locale('en', 'US').toString(), 'en_US'); expect(const Locale('iw').toString(), 'he'); expect(const Locale('iw', 'DD').toString(), 'he_DE'); @@ -32,17 +32,17 @@ void main() { expect(const Locale.fromSubtags(countryCode: 'US').toString(), 'und_US'); expect(const Locale.fromSubtags(countryCode: 'US').countryCode, 'US'); - expect(Locale.fromSubtags(languageCode: 'es', countryCode: '419').toString(), 'es_419'); - expect(Locale.fromSubtags(languageCode: 'es', countryCode: '419').languageCode, 'es'); - expect(Locale.fromSubtags(languageCode: 'es', countryCode: '419').countryCode, '419'); + expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').toString(), 'es_419'); + expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').languageCode, 'es'); + expect(const Locale.fromSubtags(languageCode: 'es', countryCode: '419').countryCode, '419'); - expect(Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN').toString(), 'zh_Hans_CN'); + expect(const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'CN').toString(), 'zh_Hans_CN'); }); test('Locale equality', () { - expect(Locale.fromSubtags(languageCode: 'en'), - isNot(Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); - expect(Locale.fromSubtags(languageCode: 'en').hashCode, - isNot(Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode)); + expect(const Locale.fromSubtags(languageCode: 'en'), + isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); + expect(const Locale.fromSubtags(languageCode: 'en').hashCode, + isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode)); }); } diff --git a/testing/dart/paragraph_builder_test.dart b/testing/dart/paragraph_builder_test.dart index d84a8e17c5f66..2810d73113356 100644 --- a/testing/dart/paragraph_builder_test.dart +++ b/testing/dart/paragraph_builder_test.dart @@ -13,7 +13,7 @@ void main() { final Paragraph paragraph = builder.build(); expect(paragraph, isNotNull); - paragraph.layout(ParagraphConstraints(width: 800.0)); + paragraph.layout(const ParagraphConstraints(width: 800.0)); expect(paragraph.width, isNonZero); expect(paragraph.height, isNonZero); }); diff --git a/testing/dart/path_test.dart b/testing/dart/path_test.dart index 1c569dd5ea286..a4b4a609461f3 100644 --- a/testing/dart/path_test.dart +++ b/testing/dart/path_test.dart @@ -93,7 +93,7 @@ void main() { test('transformation tests', () { final Rect bounds = new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0); final Path p = new Path()..addRect(bounds); - final Float64List scaleMatrix = new Float64List.fromList([ + final Float64List scaleMatrix = Float64List.fromList([ 2.5, 0.0, 0.0, 0.0, // first col 0.0, 0.5, 0.0, 0.0, // second col 0.0, 0.0, 1.0, 0.0, // third col @@ -178,7 +178,7 @@ void main() { final double midPoint = simpleMetricsDiagonal.iterator.current.length / 2; final Tangent posTanDiagonal = simpleMetricsDiagonal.iterator.current.getTangentForOffset(midPoint); - expect(posTanDiagonal.position, equals(new Offset(5.0, 5.0))); + expect(posTanDiagonal.position, equals(const Offset(5.0, 5.0))); expect(posTanDiagonal.angle, closeTo(-0.7853981633974483, .00001)); // ~45 degrees diff --git a/testing/dart/plugin_utilities_test.dart b/testing/dart/plugin_utilities_test.dart index 27d7d60d57138..057b17cf76a4c 100644 --- a/testing/dart/plugin_utilities_test.dart +++ b/testing/dart/plugin_utilities_test.dart @@ -6,7 +6,7 @@ import 'dart:ui'; import 'package:test/test.dart'; -String top() => "top"; +String top() => 'top'; class Foo { const Foo(); @@ -19,29 +19,29 @@ const Foo foo = const Foo(); void main() { test('PluginUtilities Callback Handles', () { // Top level callback. - final hTop = PluginUtilities.getCallbackHandle(top); + final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top); expect(hTop, isNotNull); expect(hTop, isNot(0)); expect(PluginUtilities.getCallbackHandle(top), hTop); - final topClosure = PluginUtilities.getCallbackFromHandle(hTop); + final Function topClosure = PluginUtilities.getCallbackFromHandle(hTop); expect(topClosure, isNotNull); - expect(topClosure(), "top"); + expect(topClosure(), 'top'); // Static method callback. - final hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt); + final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt); expect(hGetInt, isNotNull); expect(hGetInt, isNot(0)); expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt); - final getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt); + final Function getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt); expect(getIntClosure, isNotNull); expect(getIntClosure(), 1); // Instance method callbacks cannot be looked up. - final foo = new Foo(); + const Foo foo = Foo(); expect(PluginUtilities.getCallbackHandle(foo.getDouble), isNull); // Anonymous closures cannot be looked up. - final anon = (int a, int b) => a + b; + final Function anon = (int a, int b) => a + b; expect(PluginUtilities.getCallbackHandle(anon), isNull); }); } diff --git a/testing/dart/pubspec.yaml b/testing/dart/pubspec.yaml index ec3ea88b2ac6d..ccffd1626119b 100644 --- a/testing/dart/pubspec.yaml +++ b/testing/dart/pubspec.yaml @@ -2,3 +2,9 @@ name: engine_tests dependencies: test: 1.3.0 path: 1.6.2 + +dependency_overrides: + sky_engine: + path: ../../../out/host_debug_unopt/gen/dart-pkg/sky_engine + sky_services: + path: ../../../out/host_debug_unopt/gen/dart-pkg/sky_services \ No newline at end of file diff --git a/testing/dart/rect_test.dart b/testing/dart/rect_test.dart index ed352a1474491..b392932c662ea 100644 --- a/testing/dart/rect_test.dart +++ b/testing/dart/rect_test.dart @@ -7,16 +7,16 @@ import 'dart:ui'; import 'package:test/test.dart'; void main() { - test("rect accessors", () { - final Rect r = new Rect.fromLTRB(1.0, 3.0, 5.0, 7.0); + test('rect accessors', () { + final Rect r = Rect.fromLTRB(1.0, 3.0, 5.0, 7.0); expect(r.left, equals(1.0)); expect(r.top, equals(3.0)); expect(r.right, equals(5.0)); expect(r.bottom, equals(7.0)); }); - test("rect created by width and height", () { - final Rect r = new Rect.fromLTWH(1.0, 3.0, 5.0, 7.0); + test('rect created by width and height', () { + final Rect r = Rect.fromLTWH(1.0, 3.0, 5.0, 7.0); expect(r.left, equals(1.0)); expect(r.top, equals(3.0)); expect(r.right, equals(6.0)); @@ -25,9 +25,9 @@ void main() { expect(r.longestSide, equals(7.0)); }); - test("rect intersection", () { - final Rect r1 = new Rect.fromLTRB(0.0, 0.0, 100.0, 100.0); - final Rect r2 = new Rect.fromLTRB(50.0, 50.0, 200.0, 200.0); + test('rect intersection', () { + final Rect r1 = Rect.fromLTRB(0.0, 0.0, 100.0, 100.0); + final Rect r2 = Rect.fromLTRB(50.0, 50.0, 200.0, 200.0); final Rect r3 = r1.intersect(r2); expect(r3.left, equals(50.0)); expect(r3.top, equals(50.0)); @@ -37,9 +37,9 @@ void main() { expect(r4, equals(r3)); }); - test("rect expandToInclude overlapping rects", () { - final Rect r1 = new Rect.fromLTRB(0.0, 0.0, 100.0, 100.0); - final Rect r2 = new Rect.fromLTRB(50.0, 50.0, 200.0, 200.0); + test('rect expandToInclude overlapping rects', () { + final Rect r1 = Rect.fromLTRB(0.0, 0.0, 100.0, 100.0); + final Rect r2 = Rect.fromLTRB(50.0, 50.0, 200.0, 200.0); final Rect r3 = r1.expandToInclude(r2); expect(r3.left, equals(0.0)); expect(r3.top, equals(0.0)); @@ -49,9 +49,9 @@ void main() { expect(r4, equals(r3)); }); - test("rect expandToInclude crossing rects", () { - final Rect r1 = new Rect.fromLTRB(50.0, 0.0, 50.0, 200.0); - final Rect r2 = new Rect.fromLTRB(0.0, 50.0, 200.0, 50.0); + test('rect expandToInclude crossing rects', () { + final Rect r1 = Rect.fromLTRB(50.0, 0.0, 50.0, 200.0); + final Rect r2 = Rect.fromLTRB(0.0, 50.0, 200.0, 50.0); final Rect r3 = r1.expandToInclude(r2); expect(r3.left, equals(0.0)); expect(r3.top, equals(0.0)); @@ -61,17 +61,17 @@ void main() { expect(r4, equals(r3)); }); - test("size created from doubles", () { - final Size size = new Size(5.0, 7.0); + test('size created from doubles', () { + const Size size = Size(5.0, 7.0); expect(size.width, equals(5.0)); expect(size.height, equals(7.0)); expect(size.shortestSide, equals(5.0)); expect(size.longestSide, equals(7.0)); }); - test("rounded rect created from rect and radii", () { - final Rect baseRect = new Rect.fromLTWH(1.0, 3.0, 5.0, 7.0); - final RRect r = new RRect.fromRectXY(baseRect, 1.0, 1.0); + test('rounded rect created from rect and radii', () { + final Rect baseRect = Rect.fromLTWH(1.0, 3.0, 5.0, 7.0); + final RRect r = RRect.fromRectXY(baseRect, 1.0, 1.0); expect(r.left, equals(1.0)); expect(r.top, equals(3.0)); expect(r.right, equals(6.0)); diff --git a/testing/dart/window_hooks_integration_test.dart b/testing/dart/window_hooks_integration_test.dart index 446f5ac8ab6a5..a7a8b81a9a1ad 100644 --- a/testing/dart/window_hooks_integration_test.dart +++ b/testing/dart/window_hooks_integration_test.dart @@ -6,15 +6,14 @@ library dart.ui; import 'dart:async'; -import 'dart:io'; -import 'dart:typed_data'; +// this needs to be imported because painting.dart expects it this way +import 'dart:collection' as collection; import 'dart:convert'; import 'dart:developer' as developer; import 'dart:math' as math; -import 'dart:nativewrappers'; +import 'dart:nativewrappers'; // ignore: unused_import +import 'dart:typed_data'; -// this needs to be imported because painting.dart expects it this way -import 'dart:collection' as collection; import 'package:test/test.dart'; diff --git a/testing/dart/window_test.dart b/testing/dart/window_test.dart index 110e9af4ec86f..e9b20ebd327c9 100644 --- a/testing/dart/window_test.dart +++ b/testing/dart/window_test.dart @@ -12,7 +12,7 @@ void main() { test('window.sendPlatformMessage preserves callback zone', () { runZoned(() { final Zone innerZone = Zone.current; - window.sendPlatformMessage('test', new ByteData.view(new Uint8List(0).buffer), expectAsync((ByteData data) { + window.sendPlatformMessage('test', new ByteData.view(new Uint8List(0).buffer), expectAsync1((ByteData data) { final Zone runZone = Zone.current; expect(runZone, isNotNull); expect(runZone, same(innerZone)); diff --git a/testing/run_tests.sh b/testing/run_tests.sh index 38fcaf7ba6ee0..85968fa9ff454 100755 --- a/testing/run_tests.sh +++ b/testing/run_tests.sh @@ -21,7 +21,7 @@ run_test () { } # Verify that a failing test returns a failure code. -! run_test flutter/testing/fail_test.dart +! run_test flutter/testing/smoke_test_failure/fail_test.dart for TEST_SCRIPT in flutter/testing/dart/*.dart; do run_test $TEST_SCRIPT diff --git a/testing/fail_test.dart b/testing/smoke_test_failure/fail_test.dart similarity index 100% rename from testing/fail_test.dart rename to testing/smoke_test_failure/fail_test.dart diff --git a/testing/smoke_test_failure/pubspec.yaml b/testing/smoke_test_failure/pubspec.yaml new file mode 100644 index 0000000000000..9eb330ef6f4e7 --- /dev/null +++ b/testing/smoke_test_failure/pubspec.yaml @@ -0,0 +1,4 @@ +name: smoke_test_failure +dependencies: + test: 1.3.0 + path: 1.6.2 diff --git a/testing/symbols/verify_exported.dart b/testing/symbols/verify_exported.dart index 37ff8f5be5f6a..e2c61e0ba1267 100644 --- a/testing/symbols/verify_exported.dart +++ b/testing/symbols/verify_exported.dart @@ -30,7 +30,7 @@ void main(List arguments) { final Iterable releaseBuilds = new Directory(outPath).listSync() .where((FileSystemEntity entity) => entity is Directory) - .map((FileSystemEntity dir) => p.basename(dir.path)) + .map((FileSystemEntity dir) => p.basename(dir.path)) .where((String s) => s.contains('_release')); final Iterable iosReleaseBuilds = releaseBuilds