From b8c799676313c7e2fc603a58809b53d517e06248 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Tue, 10 Sep 2024 15:37:35 -0700 Subject: [PATCH 1/4] Move most of the dart:ui tests to pkg/test. --- testing/dart/assets_test.dart | 22 +++++--- testing/dart/channel_buffers_test.dart | 2 +- testing/dart/codec_test.dart | 2 +- testing/dart/color_filter_test.dart | 2 +- testing/dart/color_test.dart | 50 +++++++++---------- testing/dart/compositing_test.dart | 8 +-- testing/dart/dart_test.dart | 2 +- testing/dart/encoding_test.dart | 2 +- testing/dart/fragment_shader_test.dart | 2 +- testing/dart/geometry_test.dart | 6 +-- testing/dart/gesture_settings_test.dart | 10 ++-- testing/dart/gpu_test.dart | 2 +- testing/dart/gradient_test.dart | 4 +- .../http_allow_http_connections_test.dart | 2 +- .../http_disallow_http_connections_test.dart | 2 +- testing/dart/image_descriptor_test.dart | 2 +- testing/dart/image_dispose_test.dart | 2 +- testing/dart/image_events_test.dart | 2 +- testing/dart/image_filter_test.dart | 6 +-- testing/dart/image_resize_test.dart | 2 +- testing/dart/image_shader_test.dart | 8 +-- testing/dart/image_test.dart | 2 +- testing/dart/isolate_name_server_test.dart | 2 +- testing/dart/isolate_test.dart | 2 +- testing/dart/lerp_test.dart | 27 ++++++---- testing/dart/locale_test.dart | 14 +++--- testing/dart/mask_filter_test.dart | 2 +- testing/dart/painting_test.dart | 2 +- testing/dart/paragraph_builder_test.dart | 2 +- testing/dart/paragraph_test.dart | 10 ++-- testing/dart/path_test.dart | 2 +- testing/dart/picture_test.dart | 2 +- testing/dart/platform_dispatcher_test.dart | 2 +- .../dart/platform_isolate_shutdown_test.dart | 8 +-- testing/dart/platform_isolate_test.dart | 2 +- testing/dart/platform_view_test.dart | 2 +- testing/dart/plugin_utilities_test.dart | 18 ++++--- testing/dart/pubspec.yaml | 2 +- testing/dart/semantics_test.dart | 2 +- testing/dart/serial_gc_test.dart | 2 +- testing/dart/serialized_test_suite.dart | 4 +- testing/dart/spawn_test.dart | 4 +- testing/dart/stringification_test.dart | 2 +- testing/dart/task_order_test.dart | 2 +- testing/dart/text_test.dart | 2 +- testing/dart/window_test.dart | 2 +- 46 files changed, 136 insertions(+), 125 deletions(-) diff --git a/testing/dart/assets_test.dart b/testing/dart/assets_test.dart index 84a5d307fa86e..f831d77b3794b 100644 --- a/testing/dart/assets_test.dart +++ b/testing/dart/assets_test.dart @@ -7,7 +7,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Loading an asset that does not exist returns null', () async { @@ -33,26 +33,30 @@ void main() { }); test('returns the bytes of a bundled asset', () async { - final ImmutableBuffer buffer = await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); + final ImmutableBuffer buffer = + await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); expect(buffer.length == 354679, true); }); test('returns the bytes of a file', () async { - final ImmutableBuffer buffer = await ImmutableBuffer.fromFilePath('flutter/lib/ui/fixtures/DashInNooglerHat.jpg'); + final ImmutableBuffer buffer = await ImmutableBuffer.fromFilePath( + 'flutter/lib/ui/fixtures/DashInNooglerHat.jpg'); expect(buffer.length == 354679, true); }); test('Can load an asset with a space in the key', () async { // This assets actual path is "fixtures/DashInNooglerHat%20WithSpace.jpg" - final ImmutableBuffer buffer = await ImmutableBuffer.fromAsset('DashInNooglerHat WithSpace.jpg'); + final ImmutableBuffer buffer = + await ImmutableBuffer.fromAsset('DashInNooglerHat WithSpace.jpg'); expect(buffer.length == 354679, true); }); test('can dispose immutable buffer', () async { - final ImmutableBuffer buffer = await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); + final ImmutableBuffer buffer = + await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); buffer.dispose(); }); @@ -68,9 +72,11 @@ void main() { test('Tester can still load through dart:ui', () async { /// Manually load font asset through dart. - final Uint8List encoded = utf8.encode(Uri(path: Uri.encodeFull('Roboto-Medium.ttf')).path); + final Uint8List encoded = + utf8.encode(Uri(path: Uri.encodeFull('Roboto-Medium.ttf')).path); final Completer result = Completer(); - PlatformDispatcher.instance.sendPlatformMessage('flutter/assets', encoded.buffer.asByteData(), (ByteData? data) { + PlatformDispatcher.instance.sendPlatformMessage( + 'flutter/assets', encoded.buffer.asByteData(), (ByteData? data) { result.complete(data!.buffer.asUint8List()); }); @@ -81,7 +87,7 @@ void main() { final List bundledFontImage = await _createPictureFromFont('Roboto2'); // Bundling fonts is disabled, so the font selected in both cases should be ahem. // Therefore each buffer will contain identical contents. - expect(ahemImage, notEquals(bundledFontImage)); + expect(ahemImage, isNot(equals(bundledFontImage))); }); } diff --git a/testing/dart/channel_buffers_test.dart b/testing/dart/channel_buffers_test.dart index 0346bd9493d0d..13feaa41097d0 100644 --- a/testing/dart/channel_buffers_test.dart +++ b/testing/dart/channel_buffers_test.dart @@ -9,7 +9,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'dart:ui' as ui; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; ByteData _makeByteData(String str) { final Uint8List list = utf8.encode(str); diff --git a/testing/dart/codec_test.dart b/testing/dart/codec_test.dart index 6910f56b82fca..e21b099a8cee0 100644 --- a/testing/dart/codec_test.dart +++ b/testing/dart/codec_test.dart @@ -6,8 +6,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui' as ui; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; import 'impeller_enabled.dart'; diff --git a/testing/dart/color_filter_test.dart b/testing/dart/color_filter_test.dart index 66ec9548ca58f..12cd7f6ae8816 100644 --- a/testing/dart/color_filter_test.dart +++ b/testing/dart/color_filter_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; import 'impeller_enabled.dart'; diff --git a/testing/dart/color_test.dart b/testing/dart/color_test.dart index 56e8766f103b2..a6fdb27cba368 100644 --- a/testing/dart/color_test.dart +++ b/testing/dart/color_test.dart @@ -4,16 +4,12 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; class NotAColor extends Color { const NotAColor(super.value); } -Matcher approxEquals(dynamic o) => (v) { - Expect.approxEquals(o as num, v as num); -}; - void main() { test('color accessors should work', () { const Color foo = Color(0x12345678); @@ -44,10 +40,11 @@ void main() { test('two colors are only == if they have the same runtime type', () { expect(const Color(0x12345678), equals(const Color(0x12345678))); - expect(const Color(0x12345678), equals(Color(0x12345678))); // ignore: prefer_const_constructors - expect(const Color(0x12345678), notEquals(const Color(0x87654321))); - expect(const Color(0x12345678), notEquals(const NotAColor(0x12345678))); - expect(const NotAColor(0x12345678), notEquals(const Color(0x12345678))); + expect(const Color(0x12345678), + equals(Color(0x12345678))); // ignore: prefer_const_constructors + expect(const Color(0x12345678), isNot(const Color(0x87654321))); + expect(const Color(0x12345678), isNot(const NotAColor(0x12345678))); + expect(const NotAColor(0x12345678), isNot(const Color(0x12345678))); expect(const NotAColor(0x12345678), equals(const NotAColor(0x12345678))); }); @@ -90,8 +87,7 @@ void main() { green: 0, blue: 0, colorSpace: ColorSpace.displayP3), - const Color.from( - alpha: 1, red: 1, green: 0, blue: 0), + const Color.from(alpha: 1, red: 1, green: 0, blue: 0), 0.0); } catch (ex) { didThrow = true; @@ -244,9 +240,9 @@ void main() { alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); final Color srgb = p3.withValues(colorSpace: ColorSpace.extendedSRGB); expect(srgb.a, equals(1.0)); - expect(srgb.r, approxEquals(1.0931)); - expect(srgb.g, approxEquals(-0.22684034705162098)); - expect(srgb.b, approxEquals(-0.15007957816123998)); + expect(srgb.r, closeTo(1.0931, 1e4)); + expect(srgb.g, closeTo(-0.22684034705162098, 1e4)); + expect(srgb.b, closeTo(-0.15007957816123998, 1e4)); expect(srgb.colorSpace, equals(ColorSpace.extendedSRGB)); }); @@ -255,9 +251,9 @@ void main() { alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); final Color srgb = p3.withValues(colorSpace: ColorSpace.sRGB); expect(srgb.a, equals(1.0)); - expect(srgb.r, approxEquals(1)); - expect(srgb.g, approxEquals(0)); - expect(srgb.b, approxEquals(0)); + expect(srgb.r, closeTo(1, 1e4)); + expect(srgb.g, closeTo(0, 1e4)); + expect(srgb.b, closeTo(0, 1e4)); expect(srgb.colorSpace, equals(ColorSpace.sRGB)); }); @@ -270,9 +266,9 @@ void main() { colorSpace: ColorSpace.extendedSRGB); final Color p3 = srgb.withValues(colorSpace: ColorSpace.displayP3); expect(p3.a, equals(1.0)); - expect(p3.r, approxEquals(1)); - expect(p3.g, approxEquals(0)); - expect(p3.b, approxEquals(0)); + expect(p3.r, closeTo(1, 1e4)); + expect(p3.g, closeTo(0, 1e4)); + expect(p3.b, closeTo(0, 1e4)); expect(p3.colorSpace, equals(ColorSpace.displayP3)); }); @@ -294,19 +290,17 @@ void main() { }); test('hash considers colorspace', () { - const Color srgb = Color.from( - alpha: 1, red: 1, green: 0, blue: 0); + const Color srgb = Color.from(alpha: 1, red: 1, green: 0, blue: 0); const Color p3 = Color.from( alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); - expect(srgb.hashCode, notEquals(p3.hashCode)); + expect(srgb.hashCode, isNot(p3.hashCode)); }); test('equality considers colorspace', () { - const Color srgb = Color.from( - alpha: 1, red: 1, green: 0, blue: 0); + const Color srgb = Color.from(alpha: 1, red: 1, green: 0, blue: 0); const Color p3 = Color.from( alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); - expect(srgb, notEquals(p3)); + expect(srgb, isNot(p3)); }); // Regression test for https://github.com/flutter/flutter/issues/41257 @@ -320,7 +314,9 @@ void main() { } class DynamicColorClass extends Color { - const DynamicColorClass(int newValue) : _newValue = newValue, super(0); + const DynamicColorClass(int newValue) + : _newValue = newValue, + super(0); final int _newValue; diff --git a/testing/dart/compositing_test.dart b/testing/dart/compositing_test.dart index a2f95cdba0997..8b5c1447869b0 100644 --- a/testing/dart/compositing_test.dart +++ b/testing/dart/compositing_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Scene.toImageSync succeeds', () async { @@ -105,7 +105,7 @@ void main() { assert(() { expect( () => builder.pushTransform(matrix4WrongLength), - expectAssertion, + throwsA(isA()), ); return true; }()); @@ -119,7 +119,7 @@ void main() { assert(() { expect( () => builder.pushTransform(matrix4NaN), - expectAssertion, + throwsA(isA()), ); return true; }()); @@ -133,7 +133,7 @@ void main() { assert(() { expect( () => builder.pushTransform(matrix4Infinity), - expectAssertion, + throwsA(isA()), ); return true; }()); diff --git a/testing/dart/dart_test.dart b/testing/dart/dart_test.dart index a6ae889b5d5a4..bf0c6d495fefd 100644 --- a/testing/dart/dart_test.dart +++ b/testing/dart/dart_test.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; /// Verifies Dart semantics governed by flags set by Flutter tooling. void main() { diff --git a/testing/dart/encoding_test.dart b/testing/dart/encoding_test.dart index 2aa426a108100..64c965983860b 100644 --- a/testing/dart/encoding_test.dart +++ b/testing/dart/encoding_test.dart @@ -7,8 +7,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; import 'impeller_enabled.dart'; diff --git a/testing/dart/fragment_shader_test.dart b/testing/dart/fragment_shader_test.dart index 4d339029ce301..354dfccd7e355 100644 --- a/testing/dart/fragment_shader_test.dart +++ b/testing/dart/fragment_shader_test.dart @@ -9,8 +9,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; import 'impeller_enabled.dart'; import 'shader_test_file_utils.dart'; diff --git a/testing/dart/geometry_test.dart b/testing/dart/geometry_test.dart index c56b70444d0cd..75a3545242b40 100644 --- a/testing/dart/geometry_test.dart +++ b/testing/dart/geometry_test.dart @@ -9,7 +9,7 @@ import 'dart:math' as math show sqrt; import 'dart:math' show pi; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('OffsetBase.>=', () { @@ -47,8 +47,8 @@ void main() { test('OffsetBase.==', () { expect(const Offset(0, 0), equals(const Offset(0, 0))); - expect(const Offset(0, 0), notEquals(const Offset(1, 0))); - expect(const Offset(0, 0), notEquals(const Offset(0, 1))); + expect(const Offset(0, 0), isNot(const Offset(1, 0))); + expect(const Offset(0, 0), isNot(const Offset(0, 1))); }); test('Offset.direction', () { diff --git a/testing/dart/gesture_settings_test.dart b/testing/dart/gesture_settings_test.dart index 0ec8c2198dd54..8446b3174abfc 100644 --- a/testing/dart/gesture_settings_test.dart +++ b/testing/dart/gesture_settings_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('GestureSettings has a reasonable toString', () { @@ -23,11 +23,11 @@ void main() { expect(settingsA, equals(settingsC)); expect(settingsC, equals(settingsA)); - expect(settingsA, notEquals(settingsB)); - expect(settingsC, notEquals(settingsB)); + expect(settingsA, isNot(settingsB)); + expect(settingsC, isNot(settingsB)); - expect(settingsB, notEquals(settingsA)); - expect(settingsB, notEquals(settingsC)); + expect(settingsB, isNot(settingsA)); + expect(settingsB, isNot(settingsC)); }); test('GestureSettings copyWith preserves already set values', () { diff --git a/testing/dart/gpu_test.dart b/testing/dart/gpu_test.dart index cfafec5250a45..9df219c33d714 100644 --- a/testing/dart/gpu_test.dart +++ b/testing/dart/gpu_test.dart @@ -7,7 +7,7 @@ import 'dart:typed_data'; import 'dart:ui' as ui; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; import '../../lib/gpu/lib/gpu.dart' as gpu; import 'impeller_enabled.dart'; diff --git a/testing/dart/gradient_test.dart b/testing/dart/gradient_test.dart index 9d5f3a04b63b4..54d55d14841a8 100644 --- a/testing/dart/gradient_test.dart +++ b/testing/dart/gradient_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Gradient.radial with no focal point', () { @@ -64,7 +64,7 @@ void main() { Offset.zero, 1.0, ), - expectAssertion, + throwsA(isA()), ); return true; }()); diff --git a/testing/dart/http_allow_http_connections_test.dart b/testing/dart/http_allow_http_connections_test.dart index 165b50d53ccfe..09afaae598182 100644 --- a/testing/dart/http_allow_http_connections_test.dart +++ b/testing/dart/http_allow_http_connections_test.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:io'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; import 'http_disallow_http_connections_test.dart'; diff --git a/testing/dart/http_disallow_http_connections_test.dart b/testing/dart/http_disallow_http_connections_test.dart index fbe9874c23249..d2f9634348d55 100644 --- a/testing/dart/http_disallow_http_connections_test.dart +++ b/testing/dart/http_disallow_http_connections_test.dart @@ -7,7 +7,7 @@ import 'dart:async'; import 'dart:io'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; typedef FutureFunction = Future Function(); diff --git a/testing/dart/image_descriptor_test.dart b/testing/dart/image_descriptor_test.dart index 8155112d4012b..8160f12bd8a8d 100644 --- a/testing/dart/image_descriptor_test.dart +++ b/testing/dart/image_descriptor_test.dart @@ -7,8 +7,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; void main() { test('basic image descriptor - encoded - greyscale', () async { diff --git a/testing/dart/image_dispose_test.dart b/testing/dart/image_dispose_test.dart index d7692f287bba0..f0f1539dd61eb 100644 --- a/testing/dart/image_dispose_test.dart +++ b/testing/dart/image_dispose_test.dart @@ -6,8 +6,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; void main() { bool assertsEnabled = false; diff --git a/testing/dart/image_events_test.dart b/testing/dart/image_events_test.dart index 92b856c0014e4..c81d63c764d1f 100644 --- a/testing/dart/image_events_test.dart +++ b/testing/dart/image_events_test.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Image constructor and dispose invokes onCreate once', () async { diff --git a/testing/dart/image_filter_test.dart b/testing/dart/image_filter_test.dart index 0200d6f2d45cd..8c0cbe0bf4998 100644 --- a/testing/dart/image_filter_test.dart +++ b/testing/dart/image_filter_test.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; import 'goldens.dart'; import 'impeller_enabled.dart'; @@ -133,9 +133,9 @@ void main() async { expect(a[i].hashCode, equals(b[j].hashCode)); expect(a[i].toString(), equals(b[j].toString())); } else { - expect(a[i], notEquals(b[j])); + expect(a[i], isNot(b[j])); // No expectations on hashCode if objects are not equal - expect(a[i].toString(), notEquals(b[j].toString())); + expect(a[i].toString(), isNot(b[j].toString())); } } } diff --git a/testing/dart/image_resize_test.dart b/testing/dart/image_resize_test.dart index d4d892b0f03a7..c2e50d0d035b4 100644 --- a/testing/dart/image_resize_test.dart +++ b/testing/dart/image_resize_test.dart @@ -7,8 +7,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; void main() { bool assertsEnabled = false; diff --git a/testing/dart/image_shader_test.dart b/testing/dart/image_shader_test.dart index 6124e5746d5ab..c79049908d8f1 100644 --- a/testing/dart/image_shader_test.dart +++ b/testing/dart/image_shader_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; import 'canvas_test.dart' show createImage, testCanvas; void main() { @@ -38,9 +38,9 @@ void main() { image.dispose(); if (assertsEnabled) { - expectAssertion(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16))); + expect(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16)), throwsA(isA())); } else { - throwsException(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16))); + expect(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16)), throwsException); } }); @@ -50,7 +50,7 @@ void main() { shader.dispose(); if (assertsEnabled) { - expectAssertion(() => Paint()..shader = shader); + expect(() => Paint()..shader = shader, throwsA(isA())); return; } final Paint paint = Paint()..shader = shader; diff --git a/testing/dart/image_test.dart b/testing/dart/image_test.dart index 4cb44267b6f25..28ff8c1658c53 100644 --- a/testing/dart/image_test.dart +++ b/testing/dart/image_test.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('toImage succeeds', () async { diff --git a/testing/dart/isolate_name_server_test.dart b/testing/dart/isolate_name_server_test.dart index 58005227699ad..7e344bbbcf462 100644 --- a/testing/dart/isolate_name_server_test.dart +++ b/testing/dart/isolate_name_server_test.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'dart:isolate'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; const int kErrorCode = -1; const int kStartCode = 0; diff --git a/testing/dart/isolate_test.dart b/testing/dart/isolate_test.dart index c3330fb29d601..379a15b069a6e 100644 --- a/testing/dart/isolate_test.dart +++ b/testing/dart/isolate_test.dart @@ -5,7 +5,7 @@ import 'dart:isolate'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Invalid isolate URI', () async { diff --git a/testing/dart/lerp_test.dart b/testing/dart/lerp_test.dart index b3ce4e2f8c701..cb5cd25a45e05 100644 --- a/testing/dart/lerp_test.dart +++ b/testing/dart/lerp_test.dart @@ -4,7 +4,14 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; + +/// The epsilon of tolerable double precision error. +/// +/// This is used in various places in the framework to allow for floating point +/// precision loss in calculations. Differences below this threshold are safe +/// to disregard. +const double precisionErrorTolerance = 1e-10; // These tests should be kept in sync with the web tests in // lib/web_ui/test/lerp_test.dart. @@ -103,23 +110,23 @@ void main() { }); test('lerpDouble should throw AssertionError if interpolation value is NaN and a != b', () { - expectAssertion(() => lerpDouble(0.0, 10.0, double.nan)); + expect(() => lerpDouble(0.0, 10.0, double.nan), throwsA(isA())); }); test('lerpDouble should throw AssertionError if interpolation value is +/- infinity and a != b', () { - expectAssertion(() => lerpDouble(0.0, 10.0, double.infinity)); - expectAssertion(() => lerpDouble(0.0, 10.0, -double.infinity)); + expect(() => lerpDouble(0.0, 10.0, double.infinity), throwsA(isA())); + expect(() => lerpDouble(0.0, 10.0, -double.infinity), throwsA(isA())); }); test('lerpDouble should throw AssertionError if either start or end are NaN', () { - expectAssertion(() => lerpDouble(double.nan, 10.0, 5.0)); - expectAssertion(() => lerpDouble(0.0, double.nan, 5.0)); + expect(() => lerpDouble(double.nan, 10.0, 5.0), throwsA(isA())); + expect(() => lerpDouble(0.0, double.nan, 5.0), throwsA(isA())); }); test('lerpDouble should throw AssertionError if either start or end are +/- infinity', () { - expectAssertion(() => lerpDouble(double.infinity, 10.0, 5.0)); - expectAssertion(() => lerpDouble(-double.infinity, 10.0, 5.0)); - expectAssertion(() => lerpDouble(0.0, double.infinity, 5.0)); - expectAssertion(() => lerpDouble(0.0, -double.infinity, 5.0)); + expect(() => lerpDouble(double.infinity, 10.0, 5.0), throwsA(isA())); + expect(() => lerpDouble(-double.infinity, 10.0, 5.0), throwsA(isA())); + expect(() => lerpDouble(0.0, double.infinity, 5.0), throwsA(isA())); + expect(() => lerpDouble(0.0, -double.infinity, 5.0), throwsA(isA())); }); } diff --git a/testing/dart/locale_test.dart b/testing/dart/locale_test.dart index 57af946e30052..d5e3cef187974 100644 --- a/testing/dart/locale_test.dart +++ b/testing/dart/locale_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Locale', () { @@ -45,19 +45,19 @@ void main() { test('Locale equality', () { expect(const Locale.fromSubtags(languageCode: 'en'), - notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); + isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); expect(const Locale.fromSubtags(languageCode: 'en').hashCode, - notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode)); + isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode)); expect(const Locale('en', ''), const Locale('en')); expect(const Locale('en'), const Locale('en', '')); expect(const Locale('en'), const Locale('en')); expect(const Locale('en', ''), const Locale('en', '')); - expect(const Locale('en', ''), notEquals(const Locale('en', 'GB'))); - expect(const Locale('en'), notEquals(const Locale('en', 'GB'))); - expect(const Locale('en', 'GB'), notEquals(const Locale('en', ''))); - expect(const Locale('en', 'GB'), notEquals(const Locale('en'))); + expect(const Locale('en', ''), isNot(const Locale('en', 'GB'))); + expect(const Locale('en'), isNot(const Locale('en', 'GB'))); + expect(const Locale('en', 'GB'), isNot(const Locale('en', ''))); + expect(const Locale('en', 'GB'), isNot(const Locale('en'))); }); test("Locale toString does not include separator for ''", () { diff --git a/testing/dart/mask_filter_test.dart b/testing/dart/mask_filter_test.dart index f1cd3a1ba5787..8e65e01a98791 100644 --- a/testing/dart/mask_filter_test.dart +++ b/testing/dart/mask_filter_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('MaskFilter - NOP blur does not crash', () async { diff --git a/testing/dart/painting_test.dart b/testing/dart/painting_test.dart index fc39f9fdb7dc6..f335704fdaba9 100644 --- a/testing/dart/painting_test.dart +++ b/testing/dart/painting_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; import 'package:vector_math/vector_math_64.dart'; typedef CanvasCallback = void Function(Canvas canvas); diff --git a/testing/dart/paragraph_builder_test.dart b/testing/dart/paragraph_builder_test.dart index 14761f17f9c83..4e90d5d471df4 100644 --- a/testing/dart/paragraph_builder_test.dart +++ b/testing/dart/paragraph_builder_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Should be able to build and layout a paragraph', () { diff --git a/testing/dart/paragraph_test.dart b/testing/dart/paragraph_test.dart index 0af5506f10467..ccc2658bf0275 100644 --- a/testing/dart/paragraph_test.dart +++ b/testing/dart/paragraph_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { // Ahem font uses a constant ideographic/alphabetic baseline ratio. @@ -311,7 +311,7 @@ void main() { final GlyphInfo? bottomRight = paragraph.getClosestGlyphInfoForOffset(const Offset(99.0, 99.0)); final GlyphInfo? last = paragraph.getGlyphInfoAt(8); expect(bottomRight, equals(last)); - expect(bottomRight, notEquals(paragraph.getGlyphInfoAt(0))); + expect(bottomRight, isNot(paragraph.getGlyphInfoAt(0))); expect(bottomRight?.graphemeClusterLayoutBounds, const Rect.fromLTWH(30, 10, 10, 10)); expect(bottomRight?.graphemeClusterCodeUnitRange, const TextRange(start: 8, end: 9)); @@ -326,11 +326,7 @@ void main() { final Canvas canvas = Canvas(recorder); void callback() { canvas.drawParagraph(paragraph, Offset.zero); } - if (assertStatementsEnabled) { - expectAssertion(callback); - } else { - expect(callback, throwsStateError); - } + expect(callback, throwsA(isA())); }); test('rounding hack disabled', () { diff --git a/testing/dart/path_test.dart b/testing/dart/path_test.dart index 306797a32395c..e5ca66c8f0b37 100644 --- a/testing/dart/path_test.dart +++ b/testing/dart/path_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data' show Float64List; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('path getBounds', () { diff --git a/testing/dart/picture_test.dart b/testing/dart/picture_test.dart index 4ea13962fcaa8..d1472e97bd324 100644 --- a/testing/dart/picture_test.dart +++ b/testing/dart/picture_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Picture construction invokes onCreate once', () async { diff --git a/testing/dart/platform_dispatcher_test.dart b/testing/dart/platform_dispatcher_test.dart index e7ff1f1aa5646..c6b4546ba094c 100644 --- a/testing/dart/platform_dispatcher_test.dart +++ b/testing/dart/platform_dispatcher_test.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('ViewConstraints.tight', () { diff --git a/testing/dart/platform_isolate_shutdown_test.dart b/testing/dart/platform_isolate_shutdown_test.dart index af5c37048125f..20e5c65700ae6 100644 --- a/testing/dart/platform_isolate_shutdown_test.dart +++ b/testing/dart/platform_isolate_shutdown_test.dart @@ -7,10 +7,11 @@ import 'dart:ffi'; import 'dart:isolate'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { - test('PlatformIsolate runOnPlatformThread, cancels pending jobs if shutdown', () async { + test('PlatformIsolate runOnPlatformThread, cancels pending jobs if shutdown', + () async { final Future slowTask = runOnPlatformThread(() async { await Future.delayed(const Duration(seconds: 10)); return 123; @@ -25,7 +26,8 @@ void main() { try { await slowTask; } catch (error) { - expect(error.toString(), contains('PlatformIsolate shutdown unexpectedly')); + expect( + error.toString(), contains('PlatformIsolate shutdown unexpectedly')); throws = true; } expect(throws, true); diff --git a/testing/dart/platform_isolate_test.dart b/testing/dart/platform_isolate_test.dart index e6046beb557ef..bcc3d3abb98a0 100644 --- a/testing/dart/platform_isolate_test.dart +++ b/testing/dart/platform_isolate_test.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'dart:isolate'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; int counter = 0; diff --git a/testing/dart/platform_view_test.dart b/testing/dart/platform_view_test.dart index cd581a22d581d..7cbd8fc66d5f1 100644 --- a/testing/dart/platform_view_test.dart +++ b/testing/dart/platform_view_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('PlatformView layers do not emit errors from tester', () async { diff --git a/testing/dart/plugin_utilities_test.dart b/testing/dart/plugin_utilities_test.dart index b0a701f0cda2d..a7bbc2a68807f 100644 --- a/testing/dart/plugin_utilities_test.dart +++ b/testing/dart/plugin_utilities_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; typedef StringFunction = String Function(); typedef IntFunction = int Function(); @@ -21,16 +21,19 @@ void main() { test('PluginUtilities Callback Handles', () { // Top level callback. final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top)!; - expect(hTop, notEquals(0)); + expect(hTop, isNot(0)); expect(PluginUtilities.getCallbackHandle(top), hTop); - final StringFunction topClosure = PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction; + final StringFunction topClosure = + PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction; expect(topClosure(), 'top'); // Static method callback. - final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt)!; - expect(hGetInt, notEquals(0)); + final CallbackHandle hGetInt = + PluginUtilities.getCallbackHandle(Foo.getInt)!; + expect(hGetInt, isNot(0)); expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt); - final IntFunction getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction; + final IntFunction getIntClosure = + PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction; expect(getIntClosure(), 1); // Instance method callbacks cannot be looked up. @@ -38,7 +41,8 @@ void main() { expect(PluginUtilities.getCallbackHandle(foo.getDouble), isNull); // Anonymous closures cannot be looked up. - final Function anon = (int a, int b) => a + b; // ignore: prefer_function_declarations_over_variables + // ignore: prefer_function_declarations_over_variables + 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 ca3de69661984..00920cf6c4be0 100644 --- a/testing/dart/pubspec.yaml +++ b/testing/dart/pubspec.yaml @@ -14,10 +14,10 @@ resolution: workspace dependencies: ffi: any - litetest: any path: any skia_gold_client: any sky_engine: any + test: any vector_math: any vm_service: any vm_service_protos: any diff --git a/testing/dart/semantics_test.dart b/testing/dart/semantics_test.dart index 24c5bd10e088f..51fdbb7c1f890 100644 --- a/testing/dart/semantics_test.dart +++ b/testing/dart/semantics_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; // The body of this file is the same as ../../lib/web_ui/test/engine/semantics/semantics_api_test.dart // Please keep them in sync. diff --git a/testing/dart/serial_gc_test.dart b/testing/dart/serial_gc_test.dart index bd6c6c545b956..c21a0cf6c7ed4 100644 --- a/testing/dart/serial_gc_test.dart +++ b/testing/dart/serial_gc_test.dart @@ -4,7 +4,7 @@ // FlutterTesterOptions=--enable-serial-gc -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; int use(List a) { return a[0]; diff --git a/testing/dart/serialized_test_suite.dart b/testing/dart/serialized_test_suite.dart index 416f599dfd532..99f9ff508440e 100644 --- a/testing/dart/serialized_test_suite.dart +++ b/testing/dart/serialized_test_suite.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import 'package:litetest/litetest.dart' as litetest; +import 'package:test/test.dart' as pkg_test; // A group of tests that must be run without concurrency. // This is useful for tests that modify global state. @@ -22,6 +22,6 @@ class SerializedTestSuite { await body(); currentTestCompleter.complete(); } - litetest.test(name, wrappedBody); + pkg_test.test(name, wrappedBody); } } diff --git a/testing/dart/spawn_test.dart b/testing/dart/spawn_test.dart index a3f87b2a979b5..81b2db99f6a77 100644 --- a/testing/dart/spawn_test.dart +++ b/testing/dart/spawn_test.dart @@ -7,7 +7,7 @@ import 'dart:isolate'; import 'dart:ui'; import 'package:ffi/ffi.dart'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; // This import is used in a test, but not in a way that the analyzer can understand. // ignore: unused_import @@ -83,5 +83,5 @@ void main() { final Pointer fakePath = 'fake-path'.toNativeUtf8(); expect(_loadLibraryFromKernel(fakePath), null); malloc.free(fakePath); - }, skip: kProfileMode || kReleaseMode); // ignore: avoid_redundant_argument_values + }, skip: kProfileMode || kReleaseMode); } diff --git a/testing/dart/stringification_test.dart b/testing/dart/stringification_test.dart index 4e6f25c5f0ab9..2a6eceee86f33 100644 --- a/testing/dart/stringification_test.dart +++ b/testing/dart/stringification_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; final Uint8List imageData = Uint8List.fromList([ // Small WebP file 0x52, 0x49, 0x46, 0x46, 0x12, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50, 0x56, 0x50, 0x38, 0x4c, // |RIFF....WEBPVP8L| diff --git a/testing/dart/task_order_test.dart b/testing/dart/task_order_test.dart index 018c2bee857f4..b4fe2e090a442 100644 --- a/testing/dart/task_order_test.dart +++ b/testing/dart/task_order_test.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('Message loop flushes microtasks between iterations', () async { diff --git a/testing/dart/text_test.dart b/testing/dart/text_test.dart index cf141892245f9..108aefb7a53ed 100644 --- a/testing/dart/text_test.dart +++ b/testing/dart/text_test.dart @@ -11,8 +11,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; +import 'package:test/test.dart'; Future readFile(String fileName) async { final File file = File(path.join('flutter', 'testing', 'resources', fileName)); diff --git a/testing/dart/window_test.dart b/testing/dart/window_test.dart index fc13eeb10b7ce..0b8070592ed47 100644 --- a/testing/dart/window_test.dart +++ b/testing/dart/window_test.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:litetest/litetest.dart'; +import 'package:test/test.dart'; void main() { test('window.sendPlatformMessage preserves callback zone', () { From b60499f88433416b8844667c9119d2a4e651b4cf Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Tue, 10 Sep 2024 15:46:46 -0700 Subject: [PATCH 2/4] ++ --- testing/dart/color_test.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/testing/dart/color_test.dart b/testing/dart/color_test.dart index a6fdb27cba368..a467252d2e1f5 100644 --- a/testing/dart/color_test.dart +++ b/testing/dart/color_test.dart @@ -240,9 +240,9 @@ void main() { alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); final Color srgb = p3.withValues(colorSpace: ColorSpace.extendedSRGB); expect(srgb.a, equals(1.0)); - expect(srgb.r, closeTo(1.0931, 1e4)); - expect(srgb.g, closeTo(-0.22684034705162098, 1e4)); - expect(srgb.b, closeTo(-0.15007957816123998, 1e4)); + expect(srgb.r, closeTo(1.0931, 1e-4)); + expect(srgb.g, closeTo(-0.22684034705162098, 1e-4)); + expect(srgb.b, closeTo(-0.15007957816123998, 1e-4)); expect(srgb.colorSpace, equals(ColorSpace.extendedSRGB)); }); @@ -251,9 +251,9 @@ void main() { alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); final Color srgb = p3.withValues(colorSpace: ColorSpace.sRGB); expect(srgb.a, equals(1.0)); - expect(srgb.r, closeTo(1, 1e4)); - expect(srgb.g, closeTo(0, 1e4)); - expect(srgb.b, closeTo(0, 1e4)); + expect(srgb.r, closeTo(1, 1e-4)); + expect(srgb.g, closeTo(0, 1e-4)); + expect(srgb.b, closeTo(0, 1e-4)); expect(srgb.colorSpace, equals(ColorSpace.sRGB)); }); @@ -266,9 +266,9 @@ void main() { colorSpace: ColorSpace.extendedSRGB); final Color p3 = srgb.withValues(colorSpace: ColorSpace.displayP3); expect(p3.a, equals(1.0)); - expect(p3.r, closeTo(1, 1e4)); - expect(p3.g, closeTo(0, 1e4)); - expect(p3.b, closeTo(0, 1e4)); + expect(p3.r, closeTo(1, 1e-4)); + expect(p3.g, closeTo(0, 1e-4)); + expect(p3.b, closeTo(0, 1e-4)); expect(p3.colorSpace, equals(ColorSpace.displayP3)); }); From ffa9b198743110667c6b66f8581ecded4414f09c Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Tue, 10 Sep 2024 16:23:07 -0700 Subject: [PATCH 3/4] Revert platform_isolate_test for now. --- testing/dart/platform_isolate_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/dart/platform_isolate_test.dart b/testing/dart/platform_isolate_test.dart index bcc3d3abb98a0..e6046beb557ef 100644 --- a/testing/dart/platform_isolate_test.dart +++ b/testing/dart/platform_isolate_test.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'dart:isolate'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; int counter = 0; From cdb4d2318af0a8278e472e1bda26ddd6973e8a43 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Wed, 11 Sep 2024 14:06:18 -0700 Subject: [PATCH 4/4] Only tests that trivially pass with package:test. --- testing/dart/assets_test.dart | 20 +++----- testing/dart/color_test.dart | 50 ++++++++++--------- testing/dart/compositing_test.dart | 2 +- testing/dart/fragment_shader_test.dart | 2 +- testing/dart/geometry_test.dart | 8 +-- testing/dart/image_filter_test.dart | 6 +-- testing/dart/image_shader_test.dart | 8 +-- testing/dart/lerp_test.dart | 7 +-- testing/dart/paragraph_test.dart | 3 +- .../dart/platform_isolate_shutdown_test.dart | 6 +-- testing/dart/plugin_utilities_test.dart | 12 ++--- testing/dart/pubspec.yaml | 1 + testing/dart/run_test.sh | 10 ++++ testing/dart/serialized_test_suite.dart | 4 +- testing/dart/spawn_test.dart | 4 +- testing/dart/task_order_test.dart | 2 +- 16 files changed, 72 insertions(+), 73 deletions(-) create mode 100755 testing/dart/run_test.sh diff --git a/testing/dart/assets_test.dart b/testing/dart/assets_test.dart index f831d77b3794b..8626c6cd3fce9 100644 --- a/testing/dart/assets_test.dart +++ b/testing/dart/assets_test.dart @@ -33,30 +33,26 @@ void main() { }); test('returns the bytes of a bundled asset', () async { - final ImmutableBuffer buffer = - await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); + final ImmutableBuffer buffer = await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); expect(buffer.length == 354679, true); }); test('returns the bytes of a file', () async { - final ImmutableBuffer buffer = await ImmutableBuffer.fromFilePath( - 'flutter/lib/ui/fixtures/DashInNooglerHat.jpg'); + final ImmutableBuffer buffer = await ImmutableBuffer.fromFilePath('flutter/lib/ui/fixtures/DashInNooglerHat.jpg'); expect(buffer.length == 354679, true); }); test('Can load an asset with a space in the key', () async { // This assets actual path is "fixtures/DashInNooglerHat%20WithSpace.jpg" - final ImmutableBuffer buffer = - await ImmutableBuffer.fromAsset('DashInNooglerHat WithSpace.jpg'); + final ImmutableBuffer buffer = await ImmutableBuffer.fromAsset('DashInNooglerHat WithSpace.jpg'); expect(buffer.length == 354679, true); }); test('can dispose immutable buffer', () async { - final ImmutableBuffer buffer = - await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); + final ImmutableBuffer buffer = await ImmutableBuffer.fromAsset('DashInNooglerHat.jpg'); buffer.dispose(); }); @@ -72,11 +68,9 @@ void main() { test('Tester can still load through dart:ui', () async { /// Manually load font asset through dart. - final Uint8List encoded = - utf8.encode(Uri(path: Uri.encodeFull('Roboto-Medium.ttf')).path); + final Uint8List encoded = utf8.encode(Uri(path: Uri.encodeFull('Roboto-Medium.ttf')).path); final Completer result = Completer(); - PlatformDispatcher.instance.sendPlatformMessage( - 'flutter/assets', encoded.buffer.asByteData(), (ByteData? data) { + PlatformDispatcher.instance.sendPlatformMessage('flutter/assets', encoded.buffer.asByteData(), (ByteData? data) { result.complete(data!.buffer.asUint8List()); }); @@ -87,7 +81,7 @@ void main() { final List bundledFontImage = await _createPictureFromFont('Roboto2'); // Bundling fonts is disabled, so the font selected in both cases should be ahem. // Therefore each buffer will contain identical contents. - expect(ahemImage, isNot(equals(bundledFontImage))); + expect(ahemImage, isNot(bundledFontImage)); }); } diff --git a/testing/dart/color_test.dart b/testing/dart/color_test.dart index a467252d2e1f5..56e8766f103b2 100644 --- a/testing/dart/color_test.dart +++ b/testing/dart/color_test.dart @@ -4,12 +4,16 @@ import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; class NotAColor extends Color { const NotAColor(super.value); } +Matcher approxEquals(dynamic o) => (v) { + Expect.approxEquals(o as num, v as num); +}; + void main() { test('color accessors should work', () { const Color foo = Color(0x12345678); @@ -40,11 +44,10 @@ void main() { test('two colors are only == if they have the same runtime type', () { expect(const Color(0x12345678), equals(const Color(0x12345678))); - expect(const Color(0x12345678), - equals(Color(0x12345678))); // ignore: prefer_const_constructors - expect(const Color(0x12345678), isNot(const Color(0x87654321))); - expect(const Color(0x12345678), isNot(const NotAColor(0x12345678))); - expect(const NotAColor(0x12345678), isNot(const Color(0x12345678))); + expect(const Color(0x12345678), equals(Color(0x12345678))); // ignore: prefer_const_constructors + expect(const Color(0x12345678), notEquals(const Color(0x87654321))); + expect(const Color(0x12345678), notEquals(const NotAColor(0x12345678))); + expect(const NotAColor(0x12345678), notEquals(const Color(0x12345678))); expect(const NotAColor(0x12345678), equals(const NotAColor(0x12345678))); }); @@ -87,7 +90,8 @@ void main() { green: 0, blue: 0, colorSpace: ColorSpace.displayP3), - const Color.from(alpha: 1, red: 1, green: 0, blue: 0), + const Color.from( + alpha: 1, red: 1, green: 0, blue: 0), 0.0); } catch (ex) { didThrow = true; @@ -240,9 +244,9 @@ void main() { alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); final Color srgb = p3.withValues(colorSpace: ColorSpace.extendedSRGB); expect(srgb.a, equals(1.0)); - expect(srgb.r, closeTo(1.0931, 1e-4)); - expect(srgb.g, closeTo(-0.22684034705162098, 1e-4)); - expect(srgb.b, closeTo(-0.15007957816123998, 1e-4)); + expect(srgb.r, approxEquals(1.0931)); + expect(srgb.g, approxEquals(-0.22684034705162098)); + expect(srgb.b, approxEquals(-0.15007957816123998)); expect(srgb.colorSpace, equals(ColorSpace.extendedSRGB)); }); @@ -251,9 +255,9 @@ void main() { alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); final Color srgb = p3.withValues(colorSpace: ColorSpace.sRGB); expect(srgb.a, equals(1.0)); - expect(srgb.r, closeTo(1, 1e-4)); - expect(srgb.g, closeTo(0, 1e-4)); - expect(srgb.b, closeTo(0, 1e-4)); + expect(srgb.r, approxEquals(1)); + expect(srgb.g, approxEquals(0)); + expect(srgb.b, approxEquals(0)); expect(srgb.colorSpace, equals(ColorSpace.sRGB)); }); @@ -266,9 +270,9 @@ void main() { colorSpace: ColorSpace.extendedSRGB); final Color p3 = srgb.withValues(colorSpace: ColorSpace.displayP3); expect(p3.a, equals(1.0)); - expect(p3.r, closeTo(1, 1e-4)); - expect(p3.g, closeTo(0, 1e-4)); - expect(p3.b, closeTo(0, 1e-4)); + expect(p3.r, approxEquals(1)); + expect(p3.g, approxEquals(0)); + expect(p3.b, approxEquals(0)); expect(p3.colorSpace, equals(ColorSpace.displayP3)); }); @@ -290,17 +294,19 @@ void main() { }); test('hash considers colorspace', () { - const Color srgb = Color.from(alpha: 1, red: 1, green: 0, blue: 0); + const Color srgb = Color.from( + alpha: 1, red: 1, green: 0, blue: 0); const Color p3 = Color.from( alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); - expect(srgb.hashCode, isNot(p3.hashCode)); + expect(srgb.hashCode, notEquals(p3.hashCode)); }); test('equality considers colorspace', () { - const Color srgb = Color.from(alpha: 1, red: 1, green: 0, blue: 0); + const Color srgb = Color.from( + alpha: 1, red: 1, green: 0, blue: 0); const Color p3 = Color.from( alpha: 1, red: 1, green: 0, blue: 0, colorSpace: ColorSpace.displayP3); - expect(srgb, isNot(p3)); + expect(srgb, notEquals(p3)); }); // Regression test for https://github.com/flutter/flutter/issues/41257 @@ -314,9 +320,7 @@ void main() { } class DynamicColorClass extends Color { - const DynamicColorClass(int newValue) - : _newValue = newValue, - super(0); + const DynamicColorClass(int newValue) : _newValue = newValue, super(0); final int _newValue; diff --git a/testing/dart/compositing_test.dart b/testing/dart/compositing_test.dart index 8b5c1447869b0..de6fc952e0f41 100644 --- a/testing/dart/compositing_test.dart +++ b/testing/dart/compositing_test.dart @@ -76,7 +76,7 @@ void main() { if (assertsEnabled) { expect( () => builder.addPicture(Offset.zero, picture), - throwsA(isInstanceOf()), + throwsA(const isInstanceOf()), ); } else { builder.addPicture(Offset.zero, picture); diff --git a/testing/dart/fragment_shader_test.dart b/testing/dart/fragment_shader_test.dart index 354dfccd7e355..4d339029ce301 100644 --- a/testing/dart/fragment_shader_test.dart +++ b/testing/dart/fragment_shader_test.dart @@ -9,8 +9,8 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; +import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; -import 'package:test/test.dart'; import 'impeller_enabled.dart'; import 'shader_test_file_utils.dart'; diff --git a/testing/dart/geometry_test.dart b/testing/dart/geometry_test.dart index 75a3545242b40..2d1d0213d60d7 100644 --- a/testing/dart/geometry_test.dart +++ b/testing/dart/geometry_test.dart @@ -392,28 +392,28 @@ void main() { const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0), topLeft: const Radius.circular(-1), ); - }, throwsA(isInstanceOf())); + }, throwsA(const isInstanceOf())); expect(() { RRect.fromRectAndCorners( const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0), topRight: const Radius.circular(-2), ); - }, throwsA(isInstanceOf())); + }, throwsA(const isInstanceOf())); expect(() { RRect.fromRectAndCorners( const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0), bottomLeft: const Radius.circular(-3), ); - }, throwsA(isInstanceOf())); + }, throwsA(const isInstanceOf())); expect(() { RRect.fromRectAndCorners( const Rect.fromLTRB(10.0, 20.0, 30.0, 40.0), bottomRight: const Radius.circular(-4), ); - }, throwsA(isInstanceOf())); + }, throwsA(const isInstanceOf())); }); test('RRect.inflate clamps when deflating past zero', () { diff --git a/testing/dart/image_filter_test.dart b/testing/dart/image_filter_test.dart index 8c0cbe0bf4998..0200d6f2d45cd 100644 --- a/testing/dart/image_filter_test.dart +++ b/testing/dart/image_filter_test.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; import 'goldens.dart'; import 'impeller_enabled.dart'; @@ -133,9 +133,9 @@ void main() async { expect(a[i].hashCode, equals(b[j].hashCode)); expect(a[i].toString(), equals(b[j].toString())); } else { - expect(a[i], isNot(b[j])); + expect(a[i], notEquals(b[j])); // No expectations on hashCode if objects are not equal - expect(a[i].toString(), isNot(b[j].toString())); + expect(a[i].toString(), notEquals(b[j].toString())); } } } diff --git a/testing/dart/image_shader_test.dart b/testing/dart/image_shader_test.dart index c79049908d8f1..6124e5746d5ab 100644 --- a/testing/dart/image_shader_test.dart +++ b/testing/dart/image_shader_test.dart @@ -5,7 +5,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; import 'canvas_test.dart' show createImage, testCanvas; void main() { @@ -38,9 +38,9 @@ void main() { image.dispose(); if (assertsEnabled) { - expect(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16)), throwsA(isA())); + expectAssertion(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16))); } else { - expect(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16)), throwsException); + throwsException(() => ImageShader(image, TileMode.clamp, TileMode.clamp, Float64List(16))); } }); @@ -50,7 +50,7 @@ void main() { shader.dispose(); if (assertsEnabled) { - expect(() => Paint()..shader = shader, throwsA(isA())); + expectAssertion(() => Paint()..shader = shader); return; } final Paint paint = Paint()..shader = shader; diff --git a/testing/dart/lerp_test.dart b/testing/dart/lerp_test.dart index cb5cd25a45e05..e02aa660758eb 100644 --- a/testing/dart/lerp_test.dart +++ b/testing/dart/lerp_test.dart @@ -6,12 +6,7 @@ import 'dart:ui'; import 'package:test/test.dart'; -/// The epsilon of tolerable double precision error. -/// -/// This is used in various places in the framework to allow for floating point -/// precision loss in calculations. Differences below this threshold are safe -/// to disregard. -const double precisionErrorTolerance = 1e-10; +const precisionErrorTolerance = 1e-4; // These tests should be kept in sync with the web tests in // lib/web_ui/test/lerp_test.dart. diff --git a/testing/dart/paragraph_test.dart b/testing/dart/paragraph_test.dart index ccc2658bf0275..d307f5a1b05f8 100644 --- a/testing/dart/paragraph_test.dart +++ b/testing/dart/paragraph_test.dart @@ -326,7 +326,8 @@ void main() { final Canvas canvas = Canvas(recorder); void callback() { canvas.drawParagraph(paragraph, Offset.zero); } - expect(callback, throwsA(isA())); + + expect(callback, throwsA(isA())); }); test('rounding hack disabled', () { diff --git a/testing/dart/platform_isolate_shutdown_test.dart b/testing/dart/platform_isolate_shutdown_test.dart index 20e5c65700ae6..0f6fe58ff045d 100644 --- a/testing/dart/platform_isolate_shutdown_test.dart +++ b/testing/dart/platform_isolate_shutdown_test.dart @@ -10,8 +10,7 @@ import 'dart:ui'; import 'package:test/test.dart'; void main() { - test('PlatformIsolate runOnPlatformThread, cancels pending jobs if shutdown', - () async { + test('PlatformIsolate runOnPlatformThread, cancels pending jobs if shutdown', () async { final Future slowTask = runOnPlatformThread(() async { await Future.delayed(const Duration(seconds: 10)); return 123; @@ -26,8 +25,7 @@ void main() { try { await slowTask; } catch (error) { - expect( - error.toString(), contains('PlatformIsolate shutdown unexpectedly')); + expect(error.toString(), contains('PlatformIsolate shutdown unexpectedly')); throws = true; } expect(throws, true); diff --git a/testing/dart/plugin_utilities_test.dart b/testing/dart/plugin_utilities_test.dart index a7bbc2a68807f..a30c029ea073b 100644 --- a/testing/dart/plugin_utilities_test.dart +++ b/testing/dart/plugin_utilities_test.dart @@ -23,17 +23,14 @@ void main() { final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top)!; expect(hTop, isNot(0)); expect(PluginUtilities.getCallbackHandle(top), hTop); - final StringFunction topClosure = - PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction; + final StringFunction topClosure = PluginUtilities.getCallbackFromHandle(hTop)! as StringFunction; expect(topClosure(), 'top'); // Static method callback. - final CallbackHandle hGetInt = - PluginUtilities.getCallbackHandle(Foo.getInt)!; + final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt)!; expect(hGetInt, isNot(0)); expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt); - final IntFunction getIntClosure = - PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction; + final IntFunction getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt)! as IntFunction; expect(getIntClosure(), 1); // Instance method callbacks cannot be looked up. @@ -41,8 +38,7 @@ void main() { expect(PluginUtilities.getCallbackHandle(foo.getDouble), isNull); // Anonymous closures cannot be looked up. - // ignore: prefer_function_declarations_over_variables - final Function anon = (int a, int b) => a + b; + final Function anon = (int a, int b) => a + b; // ignore: prefer_function_declarations_over_variables expect(PluginUtilities.getCallbackHandle(anon), isNull); }); } diff --git a/testing/dart/pubspec.yaml b/testing/dart/pubspec.yaml index 00920cf6c4be0..ab4fe966f6192 100644 --- a/testing/dart/pubspec.yaml +++ b/testing/dart/pubspec.yaml @@ -14,6 +14,7 @@ resolution: workspace dependencies: ffi: any + litetest: any path: any skia_gold_client: any sky_engine: any diff --git a/testing/dart/run_test.sh b/testing/dart/run_test.sh new file mode 100755 index 0000000000000..b981fcb8c9051 --- /dev/null +++ b/testing/dart/run_test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +FILE=$1 +COMPILE_TARGET=compile_$FILE.dart +DART_FILTER=$FILE.dart + +ninja -C ../out/host_debug_unopt_arm64 $COMPILE_TARGET +./testing/run_tests.py --type=dart --dart-filter=$DART_FILTER --variant=host_debug_unopt_arm64 diff --git a/testing/dart/serialized_test_suite.dart b/testing/dart/serialized_test_suite.dart index 99f9ff508440e..416f599dfd532 100644 --- a/testing/dart/serialized_test_suite.dart +++ b/testing/dart/serialized_test_suite.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import 'package:test/test.dart' as pkg_test; +import 'package:litetest/litetest.dart' as litetest; // A group of tests that must be run without concurrency. // This is useful for tests that modify global state. @@ -22,6 +22,6 @@ class SerializedTestSuite { await body(); currentTestCompleter.complete(); } - pkg_test.test(name, wrappedBody); + litetest.test(name, wrappedBody); } } diff --git a/testing/dart/spawn_test.dart b/testing/dart/spawn_test.dart index 81b2db99f6a77..a3f87b2a979b5 100644 --- a/testing/dart/spawn_test.dart +++ b/testing/dart/spawn_test.dart @@ -7,7 +7,7 @@ import 'dart:isolate'; import 'dart:ui'; import 'package:ffi/ffi.dart'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; // This import is used in a test, but not in a way that the analyzer can understand. // ignore: unused_import @@ -83,5 +83,5 @@ void main() { final Pointer fakePath = 'fake-path'.toNativeUtf8(); expect(_loadLibraryFromKernel(fakePath), null); malloc.free(fakePath); - }, skip: kProfileMode || kReleaseMode); + }, skip: kProfileMode || kReleaseMode); // ignore: avoid_redundant_argument_values } diff --git a/testing/dart/task_order_test.dart b/testing/dart/task_order_test.dart index b4fe2e090a442..018c2bee857f4 100644 --- a/testing/dart/task_order_test.dart +++ b/testing/dart/task_order_test.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('Message loop flushes microtasks between iterations', () async {