From 740a85e9f0c35aadafce25feda8903b3eec45e9a Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Wed, 19 May 2021 23:08:23 -0700 Subject: [PATCH] Adds package:litetest, uses it instead of package:test under testing/dart (flutter/engine#26215) --- DEPS | 9 + engine/src/flutter/ci/analyze.sh | 15 +- .../flutter/ci/licenses_golden/tool_signature | 2 +- .../src/flutter/testing/dart/canvas_test.dart | 6 +- .../testing/dart/channel_buffers_test.dart | 6 +- .../src/flutter/testing/dart/codec_test.dart | 22 +- .../testing/dart/color_filter_test.dart | 2 +- .../src/flutter/testing/dart/color_test.dart | 8 +- .../testing/dart/compositing_test.dart | 8 +- .../src/flutter/testing/dart/dart_test.dart | 2 +- .../flutter/testing/dart/encoding_test.dart | 2 +- .../flutter/testing/dart/geometry_test.dart | 6 +- .../flutter/testing/dart/gradient_test.dart | 4 +- .../testing/dart/image_descriptor_test.dart | 2 +- .../testing/dart/image_dispose_test.dart | 2 +- .../testing/dart/image_filter_test.dart | 6 +- .../testing/dart/image_resize_test.dart | 2 +- .../dart/isolate_name_server_test.dart | 128 ++++---- .../flutter/testing/dart/isolate_test.dart | 16 +- .../src/flutter/testing/dart/lerp_test.dart | 6 +- .../src/flutter/testing/dart/locale_test.dart | 14 +- .../testing/dart/observatory/skp_test.dart | 19 +- .../testing/dart/paragraph_builder_test.dart | 2 +- .../flutter/testing/dart/paragraph_test.dart | 2 +- .../src/flutter/testing/dart/path_test.dart | 2 +- .../testing/dart/platform_view_test.dart | 2 +- .../testing/dart/plugin_utilities_test.dart | 6 +- engine/src/flutter/testing/dart/pubspec.yaml | 55 +++- .../flutter/testing/dart/semantics_test.dart | 3 +- .../flutter/testing/dart/task_order_test.dart | 2 +- .../src/flutter/testing/dart/test_util.dart | 51 ---- .../src/flutter/testing/dart/text_test.dart | 2 +- .../src/flutter/testing/dart/window_test.dart | 2 +- engine/src/flutter/testing/litetest/README.md | 14 + .../testing/litetest/lib/litetest.dart | 37 +++ .../testing/litetest/lib/src/matchers.dart | 114 +++++++ .../testing/litetest/lib/src/test.dart | 120 ++++++++ .../testing/litetest/lib/src/test_suite.dart | 133 +++++++++ .../src/flutter/testing/litetest/pubspec.yaml | 30 ++ .../testing/litetest/test/litetest_test.dart | 282 ++++++++++++++++++ engine/src/flutter/testing/run_tests.py | 87 ++++-- .../testing/smoke_test_failure/fail_test.dart | 5 +- .../testing/smoke_test_failure/pubspec.yaml | 29 +- .../src/flutter/tools/licenses/lib/main.dart | 5 +- engine/src/flutter/tools/pub_get_offline.py | 2 + 45 files changed, 1037 insertions(+), 237 deletions(-) delete mode 100644 engine/src/flutter/testing/dart/test_util.dart create mode 100644 engine/src/flutter/testing/litetest/README.md create mode 100644 engine/src/flutter/testing/litetest/lib/litetest.dart create mode 100644 engine/src/flutter/testing/litetest/lib/src/matchers.dart create mode 100644 engine/src/flutter/testing/litetest/lib/src/test.dart create mode 100644 engine/src/flutter/testing/litetest/lib/src/test_suite.dart create mode 100644 engine/src/flutter/testing/litetest/pubspec.yaml create mode 100644 engine/src/flutter/testing/litetest/test/litetest_test.dart diff --git a/DEPS b/DEPS index 5a9d584226..6c5ca9c9b4 100644 --- a/DEPS +++ b/DEPS @@ -401,6 +401,12 @@ deps = { 'src/third_party/pkg/file': Var('github_git') + '/google/file.dart.git' + '@' + '427bb20ccc852425d67f2880da2a9b4707c266b4', # 6.1.0 + 'src/third_party/pkg/image': + Var('github_git') + '/brendan-duncan/image.git' + '@' + '3.0.2', + + 'src/third_party/pkg/petitparser': + Var('github_git') + '/petitparser/dart-petitparser' + '@' + '4.1.0', + 'src/third_party/pkg/platform': Var('github_git') + '/google/platform.dart.git' + '@' + 'f63fd0bc3021354a0687dc935962c9acc003f47e', # 3.0.1 @@ -410,6 +416,9 @@ deps = { 'src/third_party/pkg/when': Var('dart_git') + '/when.git' + '@' + '0.2.0', + 'src/third_party/pkg/xml': + Var('github_git') + '/renggli/dart-xml' + '@' + '22a9e95c07c51429da368301047ffeba945b72a7', # 5.1.0 + 'src/third_party/android_tools/ndk': { 'packages': [ { diff --git a/engine/src/flutter/ci/analyze.sh b/engine/src/flutter/ci/analyze.sh index 832b479fcf..c71ffed0af 100755 --- a/engine/src/flutter/ci/analyze.sh +++ b/engine/src/flutter/ci/analyze.sh @@ -71,16 +71,27 @@ analyze \ "$FLUTTER_DIR/flutter_frontend_server" echo "Analyzing tools/licenses..." -(cd "$FLUTTER_DIR/tools/licenses" && "$PUB" get) analyze \ --packages="$FLUTTER_DIR/tools/licenses/.dart_tool/package_config.json" \ --options "$FLUTTER_DIR/tools/licenses/analysis_options.yaml" \ "$FLUTTER_DIR/tools/licenses" +echo "Analyzing testing/litetest" +analyze \ + --packages="$FLUTTER_DIR/testing/litetest/.dart_tool/package_config.json" \ + --options "$FLUTTER_DIR/analysis_options.yaml" \ + "$FLUTTER_DIR/testing/litetest" + +echo "Analyzing testing/smoke_test_failure" +analyze \ + --packages="$FLUTTER_DIR/testing/smoke_test_failure/.dart_tool/package_config.json" \ + --options "$FLUTTER_DIR/analysis_options.yaml" \ + "$FLUTTER_DIR/testing/smoke_test_failure" + echo "Analyzing testing/dart..." "$FLUTTER_DIR/tools/gn" --unoptimized autoninja -C "$SRC_DIR/out/host_debug_unopt" sky_engine sky_services -(cd "$FLUTTER_DIR/testing/dart" && "$PUB" get) +(cd "$FLUTTER_DIR/testing/dart" && "$PUB" get --offline) analyze \ --packages="$FLUTTER_DIR/testing/dart/.dart_tool/package_config.json" \ --options "$FLUTTER_DIR/analysis_options.yaml" \ diff --git a/engine/src/flutter/ci/licenses_golden/tool_signature b/engine/src/flutter/ci/licenses_golden/tool_signature index 953a12ba75..d51c685424 100644 --- a/engine/src/flutter/ci/licenses_golden/tool_signature +++ b/engine/src/flutter/ci/licenses_golden/tool_signature @@ -1,2 +1,2 @@ -Signature: 7af516b6fef310e37406f37cc6da30ae +Signature: 469fde92656a4a5e122b7601271cf2cb diff --git a/engine/src/flutter/testing/dart/canvas_test.dart b/engine/src/flutter/testing/dart/canvas_test.dart index 81208d10e5..9368de921a 100644 --- a/engine/src/flutter/testing/dart/canvas_test.dart +++ b/engine/src/flutter/testing/dart/canvas_test.dart @@ -7,12 +7,10 @@ import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; import 'dart:ui'; + import 'package:image/image.dart' as dart_image; - +import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; -import 'package:test/test.dart'; - -import 'test_util.dart'; typedef CanvasCallback = void Function(Canvas canvas); diff --git a/engine/src/flutter/testing/dart/channel_buffers_test.dart b/engine/src/flutter/testing/dart/channel_buffers_test.dart index 73032cda91..aa715d6a10 100644 --- a/engine/src/flutter/testing/dart/channel_buffers_test.dart +++ b/engine/src/flutter/testing/dart/channel_buffers_test.dart @@ -11,7 +11,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'dart:ui' as ui; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; ByteData _makeByteData(String str) { final Uint8List list = utf8.encode(str) as Uint8List; @@ -160,7 +160,7 @@ void main() { didCallCallback = true; } void twoCallback(ByteData responseData) { - throw TestFailure('wrong callback called'); + fail('wrong callback called'); } _resize(buffers, channel, 100); buffers.push(channel, one, oneCallback); @@ -181,7 +181,7 @@ void main() { didCallCallback = true; } void twoCallback(ByteData responseData) { - throw TestFailure('wrong callback called'); + fail('wrong callback called'); } _resize(buffers, channel, 1); buffers.push(channel, one, oneCallback); diff --git a/engine/src/flutter/testing/dart/codec_test.dart b/engine/src/flutter/testing/dart/codec_test.dart index 649aba4562..a06a579818 100644 --- a/engine/src/flutter/testing/dart/codec_test.dart +++ b/engine/src/flutter/testing/dart/codec_test.dart @@ -7,7 +7,7 @@ import 'dart:io'; import 'dart:typed_data'; import 'dart:ui' as ui; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; import 'package:path/path.dart' as path; void main() { @@ -28,10 +28,12 @@ void main() { test('Fails with invalid data', () async { final Uint8List data = Uint8List.fromList([1, 2, 3]); - expect( - () => ui.instantiateImageCodec(data), - throwsA(exceptionWithMessage('Invalid image data')) - ); + try { + await ui.instantiateImageCodec(data); + fail('exception not thrown'); + } on Exception catch (e) { + expect(e.toString(), contains('Invalid image data')); + } }); test('getNextFrame fails with invalid data', () async { @@ -41,8 +43,8 @@ void main() { try { await codec.getNextFrame(); fail('exception not thrown'); - } catch(e) { - expect(e, exceptionWithMessage('Codec failed')); + } on Exception catch (e) { + expect(e.toString(), contains('Codec failed')); } }); @@ -97,9 +99,3 @@ File _getSkiaResource(String fileName) { path.join('third_party', 'skia', 'resources', 'images', fileName); return File(assetPath); } - -Matcher exceptionWithMessage(String m) { - return predicate((Exception e) { - return e is Exception && e.toString().contains(m); - }); -} diff --git a/engine/src/flutter/testing/dart/color_filter_test.dart b/engine/src/flutter/testing/dart/color_filter_test.dart index 2dddc1a704..c804c47541 100644 --- a/engine/src/flutter/testing/dart/color_filter_test.dart +++ b/engine/src/flutter/testing/dart/color_filter_test.dart @@ -6,7 +6,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; const Color red = Color(0xFFAA0000); const Color green = Color(0xFF00AA00); diff --git a/engine/src/flutter/testing/dart/color_test.dart b/engine/src/flutter/testing/dart/color_test.dart index 81c786842c..f1a24b803e 100644 --- a/engine/src/flutter/testing/dart/color_test.dart +++ b/engine/src/flutter/testing/dart/color_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; class NotAColor extends Color { const NotAColor(int value) : super(value); @@ -50,9 +50,9 @@ 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(equals(const Color(0x87654321)))); - expect(const Color(0x12345678), isNot(equals(const NotAColor(0x12345678)))); - expect(const NotAColor(0x12345678), isNot(equals(const Color(0x12345678)))); + 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))); }); diff --git a/engine/src/flutter/testing/dart/compositing_test.dart b/engine/src/flutter/testing/dart/compositing_test.dart index 08aa9b84f0..48fe5b7756 100644 --- a/engine/src/flutter/testing/dart/compositing_test.dart +++ b/engine/src/flutter/testing/dart/compositing_test.dart @@ -6,7 +6,7 @@ import 'dart:typed_data' show Float64List; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('pushTransform validates the matrix', () { @@ -28,7 +28,7 @@ void main() { assert(() { expect( () => builder.pushTransform(matrix4WrongLength), - throwsA(const TypeMatcher()), + expectAssertion, ); return true; }()); @@ -42,7 +42,7 @@ void main() { assert(() { expect( () => builder.pushTransform(matrix4NaN), - throwsA(const TypeMatcher()), + expectAssertion, ); return true; }()); @@ -56,7 +56,7 @@ void main() { assert(() { expect( () => builder.pushTransform(matrix4Infinity), - throwsA(const TypeMatcher()), + expectAssertion, ); return true; }()); diff --git a/engine/src/flutter/testing/dart/dart_test.dart b/engine/src/flutter/testing/dart/dart_test.dart index 97735d9113..a380df9044 100644 --- a/engine/src/flutter/testing/dart/dart_test.dart +++ b/engine/src/flutter/testing/dart/dart_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:async'; -import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; +import 'package:litetest/litetest.dart'; /// Verifies Dart semantics governed by flags set by Flutter tooling. void main() { diff --git a/engine/src/flutter/testing/dart/encoding_test.dart b/engine/src/flutter/testing/dart/encoding_test.dart index eb4e48e636..f0b0ea3929 100644 --- a/engine/src/flutter/testing/dart/encoding_test.dart +++ b/engine/src/flutter/testing/dart/encoding_test.dart @@ -8,8 +8,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'; const int _kWidth = 10; const int _kRadius = 2; diff --git a/engine/src/flutter/testing/dart/geometry_test.dart b/engine/src/flutter/testing/dart/geometry_test.dart index 112b774188..ce43ed767c 100644 --- a/engine/src/flutter/testing/dart/geometry_test.dart +++ b/engine/src/flutter/testing/dart/geometry_test.dart @@ -7,7 +7,7 @@ import 'dart:math' as math show sqrt; import 'dart:math' show pi; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { group('Offset', () { @@ -46,8 +46,8 @@ void main() { test('OffsetBase.==', () { expect(const Offset(0, 0), equals(const Offset(0, 0))); - expect(const Offset(0, 0), isNot(equals(const Offset(1, 0)))); - expect(const Offset(0, 0), isNot(equals(const Offset(0, 1)))); + expect(const Offset(0, 0), notEquals(const Offset(1, 0))); + expect(const Offset(0, 0), notEquals(const Offset(0, 1))); }); test('Offset.direction', () { diff --git a/engine/src/flutter/testing/dart/gradient_test.dart b/engine/src/flutter/testing/dart/gradient_test.dart index f7fe984b81..0d5b32563b 100644 --- a/engine/src/flutter/testing/dart/gradient_test.dart +++ b/engine/src/flutter/testing/dart/gradient_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('Gradient.radial with no focal point', () { @@ -67,7 +67,7 @@ void main() { Offset.zero, 1.0, ), - throwsA(const TypeMatcher()), + expectAssertion, ); return true; }()); diff --git a/engine/src/flutter/testing/dart/image_descriptor_test.dart b/engine/src/flutter/testing/dart/image_descriptor_test.dart index 13b975d83f..499ace6ddf 100644 --- a/engine/src/flutter/testing/dart/image_descriptor_test.dart +++ b/engine/src/flutter/testing/dart/image_descriptor_test.dart @@ -8,8 +8,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/engine/src/flutter/testing/dart/image_dispose_test.dart b/engine/src/flutter/testing/dart/image_dispose_test.dart index b1963338af..4955d80de1 100644 --- a/engine/src/flutter/testing/dart/image_dispose_test.dart +++ b/engine/src/flutter/testing/dart/image_dispose_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/engine/src/flutter/testing/dart/image_filter_test.dart b/engine/src/flutter/testing/dart/image_filter_test.dart index fb5405915d..0abbe86b67 100644 --- a/engine/src/flutter/testing/dart/image_filter_test.dart +++ b/engine/src/flutter/testing/dart/image_filter_test.dart @@ -6,7 +6,7 @@ import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; const Color red = Color(0xFFAA0000); const Color green = Color(0xFF00AA00); @@ -127,9 +127,9 @@ void main() { 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/engine/src/flutter/testing/dart/image_resize_test.dart b/engine/src/flutter/testing/dart/image_resize_test.dart index 538a085fc7..cd2b090f95 100644 --- a/engine/src/flutter/testing/dart/image_resize_test.dart +++ b/engine/src/flutter/testing/dart/image_resize_test.dart @@ -8,8 +8,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/engine/src/flutter/testing/dart/isolate_name_server_test.dart b/engine/src/flutter/testing/dart/isolate_name_server_test.dart index 538c4b0f65..1e44bc22e9 100644 --- a/engine/src/flutter/testing/dart/isolate_name_server_test.dart +++ b/engine/src/flutter/testing/dart/isolate_name_server_test.dart @@ -6,7 +6,7 @@ import 'dart:isolate'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; const String kPortName = 'foobar'; const int kErrorCode = -1; @@ -44,78 +44,82 @@ void isolateSpawnEntrypoint(SendPort port) { } void main() { - tearDown(() { - IsolateNameServer.removePortNameMapping(kPortName); - }); - test('simple isolate name server', () { - // Mapping for 'foobar' isn't set. Check these cases to ensure correct - // negative response. - expect(IsolateNameServer.lookupPortByName(kPortName), isNull); - expect(IsolateNameServer.removePortNameMapping(kPortName), isFalse); + try { + // Mapping for 'foobar' isn't set. Check these cases to ensure correct + // negative response. + expect(IsolateNameServer.lookupPortByName(kPortName), isNull); + expect(IsolateNameServer.removePortNameMapping(kPortName), isFalse); - // Register a SendPort. - final ReceivePort receivePort = ReceivePort(); - final SendPort sendPort = receivePort.sendPort; - expect(IsolateNameServer.registerPortWithName(sendPort, kPortName), isTrue); - expect(IsolateNameServer.lookupPortByName(kPortName), sendPort); + // Register a 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 ReceivePort receivePort2 = ReceivePort(); - final SendPort sendPort2 = receivePort2.sendPort; - expect( - IsolateNameServer.registerPortWithName(sendPort2, kPortName), isFalse); - expect(IsolateNameServer.lookupPortByName(kPortName), sendPort); + // Check we can't register the same name twice. + final ReceivePort receivePort2 = ReceivePort(); + final SendPort sendPort2 = receivePort2.sendPort; + expect( + IsolateNameServer.registerPortWithName(sendPort2, kPortName), isFalse); + expect(IsolateNameServer.lookupPortByName(kPortName), sendPort); - // Remove the mapping. - expect(IsolateNameServer.removePortNameMapping(kPortName), isTrue); - expect(IsolateNameServer.lookupPortByName(kPortName), isNull); + // Remove the mapping. + expect(IsolateNameServer.removePortNameMapping(kPortName), isTrue); + expect(IsolateNameServer.lookupPortByName(kPortName), isNull); - // Ensure registering a new port with the old name returns the new port. - expect( - IsolateNameServer.registerPortWithName(sendPort2, kPortName), isTrue); - expect(IsolateNameServer.lookupPortByName(kPortName), sendPort2); + // Ensure registering a new port with the old name returns the new port. + expect( + IsolateNameServer.registerPortWithName(sendPort2, kPortName), isTrue); + expect(IsolateNameServer.lookupPortByName(kPortName), sendPort2); - // Close so the test runner doesn't hang. - receivePort.close(); - receivePort2.close(); + // Close so the test runner doesn't hang. + receivePort.close(); + receivePort2.close(); + } finally { + IsolateNameServer.removePortNameMapping(kPortName); + } }); test('isolate name server multi-isolate', () async { - // Register our send port with the name server. - final ReceivePort receivePort = ReceivePort(); - final SendPort sendPort = receivePort.sendPort; - expect(IsolateNameServer.registerPortWithName(sendPort, kPortName), isTrue); + try { + // Register our send port with the name server. + final ReceivePort receivePort = ReceivePort(); + final SendPort sendPort = receivePort.sendPort; + expect(IsolateNameServer.registerPortWithName(sendPort, kPortName), isTrue); - // Test driver. - final ReceivePort testReceivePort = ReceivePort(); - testReceivePort.listen(expectAsync1((dynamic response) { - final int code = response[0] as int; - final String message = response[1] as String; - switch (code) { - case kStartCode: - break; - case kCloseCode: - receivePort.close(); - break; - case kDeletedCode: - expect(IsolateNameServer.lookupPortByName(kPortName), isNull); - // Test is done, close the last ReceivePort. - testReceivePort.close(); - break; - case kErrorCode: - throw message; - default: - throw 'UNREACHABLE'; - } - }, count: 3)); + // Test driver. + final ReceivePort testReceivePort = ReceivePort(); + testReceivePort.listen(expectAsync1((dynamic response) { + final int code = response[0] as int; + final String message = response[1] as String; + switch (code) { + case kStartCode: + break; + case kCloseCode: + receivePort.close(); + break; + case kDeletedCode: + expect(IsolateNameServer.lookupPortByName(kPortName), isNull); + // Test is done, close the last ReceivePort. + testReceivePort.close(); + break; + case kErrorCode: + throw message; + default: + throw 'UNREACHABLE'; + } + }, count: 3)); - receivePort.listen(expectAsync1((dynamic message) { - // If we don't get this message, we timeout and fail. - expect(message, kPortName); - })); + receivePort.listen(expectAsync1((dynamic message) { + // If we don't get this message, we timeout and fail. + expect(message, kPortName); + })); - // Run the test. - await Isolate.spawn(isolateSpawnEntrypoint, testReceivePort.sendPort); + // Run the test. + await Isolate.spawn(isolateSpawnEntrypoint, testReceivePort.sendPort); + } finally { + IsolateNameServer.removePortNameMapping(kPortName); + } }); } diff --git a/engine/src/flutter/testing/dart/isolate_test.dart b/engine/src/flutter/testing/dart/isolate_test.dart index 9f1e4eff08..87a8081a1a 100644 --- a/engine/src/flutter/testing/dart/isolate_test.dart +++ b/engine/src/flutter/testing/dart/isolate_test.dart @@ -2,14 +2,22 @@ // 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 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('Invalid isolate URI', () async { - final Future isolate = Isolate.spawnUri(Uri.parse('http://127.0.0.1/foo.dart'), [], null); - expect(() async => isolate, throwsA(const TypeMatcher())); + bool threw = false; + try { + await Isolate.spawnUri( + Uri.parse('http://127.0.0.1/foo.dart'), + [], + null, + ); + } on IsolateSpawnException { + threw = true; + } + expect(threw, true); }); } diff --git a/engine/src/flutter/testing/dart/lerp_test.dart b/engine/src/flutter/testing/dart/lerp_test.dart index 9bc15f4f50..d096c1efef 100644 --- a/engine/src/flutter/testing/dart/lerp_test.dart +++ b/engine/src/flutter/testing/dart/lerp_test.dart @@ -5,9 +5,7 @@ // @dart = 2.10 import 'dart:ui'; -import 'package:test/test.dart'; - -import 'test_util.dart'; +import 'package:litetest/litetest.dart'; // These tests should be kept in sync with the web tests in // lib/web_ui/test/lerp_test.dart. @@ -126,5 +124,3 @@ void main() { expectAssertion(() => lerpDouble(0.0, -double.infinity, 5.0)); }); } - -final Matcher throwsAssertionError = throwsA(const TypeMatcher()); diff --git a/engine/src/flutter/testing/dart/locale_test.dart b/engine/src/flutter/testing/dart/locale_test.dart index 028de7a41d..064301ce97 100644 --- a/engine/src/flutter/testing/dart/locale_test.dart +++ b/engine/src/flutter/testing/dart/locale_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('Locale', () { @@ -47,19 +47,19 @@ void main() { test('Locale equality', () { expect(const Locale.fromSubtags(languageCode: 'en'), - isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); + notEquals(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn'))); expect(const Locale.fromSubtags(languageCode: 'en').hashCode, - isNot(const Locale.fromSubtags(languageCode: 'en', scriptCode: 'Latn').hashCode)); + notEquals(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', ''), 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'))); + 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'))); }); test('Locale toString does not include separator for \'\'', () { diff --git a/engine/src/flutter/testing/dart/observatory/skp_test.dart b/engine/src/flutter/testing/dart/observatory/skp_test.dart index 2b2e3e813e..574ac6a19c 100644 --- a/engine/src/flutter/testing/dart/observatory/skp_test.dart +++ b/engine/src/flutter/testing/dart/observatory/skp_test.dart @@ -10,31 +10,22 @@ import 'dart:developer' as developer; import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; import 'package:vm_service/vm_service.dart' as vms; import 'package:vm_service/vm_service_io.dart'; void main() { - late vms.VmService vmService; - - setUpAll(() async { - final developer.ServiceProtocolInfo info = - await developer.Service.getInfo(); + test('Capture an SKP ', () async { + final developer.ServiceProtocolInfo info = await developer.Service.getInfo(); if (info.serverUri == null) { fail('This test must not be run with --disable-observatory.'); } - vmService = await vmServiceConnectUri( + final vms.VmService vmService = await vmServiceConnectUri( 'ws://localhost:${info.serverUri!.port}${info.serverUri!.path}ws', ); - }); - tearDownAll(() async { - await vmService.dispose(); - }); - - test('Capture an SKP ', () async { final Completer completer = Completer(); window.onBeginFrame = (Duration timeStamp) { final PictureRecorder recorder = PictureRecorder(); @@ -63,5 +54,7 @@ void main() { expect(base64data, isNotEmpty); final Uint8List decoded = base64Decode(base64data); expect(decoded.sublist(0, 8), 'skiapict'.codeUnits); + + await vmService.dispose(); }); } diff --git a/engine/src/flutter/testing/dart/paragraph_builder_test.dart b/engine/src/flutter/testing/dart/paragraph_builder_test.dart index cf8ccce0bf..dc2fdeac54 100644 --- a/engine/src/flutter/testing/dart/paragraph_builder_test.dart +++ b/engine/src/flutter/testing/dart/paragraph_builder_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { // The actual values for font measurements will vary by platform slightly. diff --git a/engine/src/flutter/testing/dart/paragraph_test.dart b/engine/src/flutter/testing/dart/paragraph_test.dart index 66593cbfda..e95ede0fad 100644 --- a/engine/src/flutter/testing/dart/paragraph_test.dart +++ b/engine/src/flutter/testing/dart/paragraph_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { // Ahem font uses a constant ideographic/alphabetic baseline ratio. diff --git a/engine/src/flutter/testing/dart/path_test.dart b/engine/src/flutter/testing/dart/path_test.dart index e635ed87bd..cb754247ad 100644 --- a/engine/src/flutter/testing/dart/path_test.dart +++ b/engine/src/flutter/testing/dart/path_test.dart @@ -6,7 +6,7 @@ import 'dart:typed_data' show Float64List; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('path getBounds', () { diff --git a/engine/src/flutter/testing/dart/platform_view_test.dart b/engine/src/flutter/testing/dart/platform_view_test.dart index 9d363513a0..c234e63bb0 100644 --- a/engine/src/flutter/testing/dart/platform_view_test.dart +++ b/engine/src/flutter/testing/dart/platform_view_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('PlatformView layers do not emit errors from tester', () async { diff --git a/engine/src/flutter/testing/dart/plugin_utilities_test.dart b/engine/src/flutter/testing/dart/plugin_utilities_test.dart index ede388e2c9..e9be4f761b 100644 --- a/engine/src/flutter/testing/dart/plugin_utilities_test.dart +++ b/engine/src/flutter/testing/dart/plugin_utilities_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; String top() => 'top'; @@ -22,7 +22,7 @@ void main() { // Top level callback. final CallbackHandle hTop = PluginUtilities.getCallbackHandle(top); expect(hTop, isNotNull); - expect(hTop, isNot(0)); + expect(hTop, notEquals(0)); expect(PluginUtilities.getCallbackHandle(top), hTop); final Function topClosure = PluginUtilities.getCallbackFromHandle(hTop); expect(topClosure, isNotNull); @@ -31,7 +31,7 @@ void main() { // Static method callback. final CallbackHandle hGetInt = PluginUtilities.getCallbackHandle(Foo.getInt); expect(hGetInt, isNotNull); - expect(hGetInt, isNot(0)); + expect(hGetInt, notEquals(0)); expect(PluginUtilities.getCallbackHandle(Foo.getInt), hGetInt); final Function getIntClosure = PluginUtilities.getCallbackFromHandle(hGetInt); expect(getIntClosure, isNotNull); diff --git a/engine/src/flutter/testing/dart/pubspec.yaml b/engine/src/flutter/testing/dart/pubspec.yaml index 9033468103..f1bb13ff0d 100644 --- a/engine/src/flutter/testing/dart/pubspec.yaml +++ b/engine/src/flutter/testing/dart/pubspec.yaml @@ -1,16 +1,55 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + name: engine_tests +publish_to: none + +# Do not add any dependencies that require more than what is provided in +# //third_party/dart/pkg or //third_party/dart/third_party/pkg. +# In particular, package:test is not usable here. + +# If you do add packages here, make sure you can run `pub get --offline`, and +# check the .packages and .package_config to make sure all the paths are +# relative to this directory into //third_party/dart environment: sdk: '>=2.8.0 <3.0.0' dependencies: - test: 1.16.8 - path: 1.8.0 - image: 3.0.2 - vm_service: 6.2.0 + litetest: any + path: any + image: any + vm_service: any 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 + archive: + path: ../../../third_party/pkg/archive + async_helper: + path: ../../../third_party/dart/pkg/async_helper + collection: + path: ../../../third_party/dart/third_party/pkg/collection + crypto: + path: ../../../third_party/dart/third_party/pkg/crypto + expect: + path: ../../../third_party/dart/pkg/expect + image: + path: ../../../third_party/pkg/image + litetest: + path: ../litetest + meta: + path: ../../../third_party/dart/pkg/meta + path: + path: ../../../third_party/dart/third_party/pkg/path + petitparser: + path: ../../../third_party/pkg/petitparser/petitparser + sky_engine: + path: ../../../out/host_debug_unopt/gen/dart-pkg/sky_engine + sky_services: + path: ../../../out/host_debug_unopt/gen/dart-pkg/sky_services + typed_data: + path: ../../../third_party/dart/third_party/pkg/typed_data + vm_service: + path: ../../../third_party/dart/pkg/vm_service + xml: + path: ../../../third_party/pkg/xml diff --git a/engine/src/flutter/testing/dart/semantics_test.dart b/engine/src/flutter/testing/dart/semantics_test.dart index dbc4c3404e..27054d8195 100644 --- a/engine/src/flutter/testing/dart/semantics_test.dart +++ b/engine/src/flutter/testing/dart/semantics_test.dart @@ -4,7 +4,8 @@ // @dart = 2.6 import 'dart:ui'; -import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; + +import 'package:litetest/litetest.dart'; /// Verifies Semantics flags and actions. void main() { diff --git a/engine/src/flutter/testing/dart/task_order_test.dart b/engine/src/flutter/testing/dart/task_order_test.dart index 4bfd71702b..d759cf71ef 100644 --- a/engine/src/flutter/testing/dart/task_order_test.dart +++ b/engine/src/flutter/testing/dart/task_order_test.dart @@ -5,7 +5,7 @@ // @dart = 2.6 import 'dart:async'; -import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; +import 'package:litetest/litetest.dart'; void main() { test('Message loop flushes microtasks between iterations', () async { diff --git a/engine/src/flutter/testing/dart/test_util.dart b/engine/src/flutter/testing/dart/test_util.dart deleted file mode 100644 index 9ef1f2d25f..0000000000 --- a/engine/src/flutter/testing/dart/test_util.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// @dart = 2.6 - -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; - -/// Asserts that `callback` throws an [AssertionError]. -/// -/// When running in a VM in which assertions are enabled, asserts that the -/// specified callback throws an [AssertionError]. When asserts are not -/// enabled, such as when running using a release-mode VM with default -/// settings, this acts as a no-op. -void expectAssertion(Function callback) { - bool assertsEnabled = false; - assert(() { - assertsEnabled = true; - return true; - }()); - if (assertsEnabled) { - bool threw = false; - try { - callback(); - } catch (e) { - expect(e is AssertionError, true); - threw = true; - } - expect(threw, true); - } -} - -/// Asserts that `callback` throws an [ArgumentError]. -void expectArgumentError(Function callback) { - bool threw = false; - try { - callback(); - } catch (e) { - expect(e is ArgumentError, true); - threw = true; - } - expect(threw, true); -} - diff --git a/engine/src/flutter/testing/dart/text_test.dart b/engine/src/flutter/testing/dart/text_test.dart index 0151b731f1..67f62e8e24 100644 --- a/engine/src/flutter/testing/dart/text_test.dart +++ b/engine/src/flutter/testing/dart/text_test.dart @@ -7,7 +7,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { group('FontWeight.lerp', () { diff --git a/engine/src/flutter/testing/dart/window_test.dart b/engine/src/flutter/testing/dart/window_test.dart index d54f209f81..8b733328f9 100644 --- a/engine/src/flutter/testing/dart/window_test.dart +++ b/engine/src/flutter/testing/dart/window_test.dart @@ -7,7 +7,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'dart:ui'; -import 'package:test/test.dart'; +import 'package:litetest/litetest.dart'; void main() { test('window.sendPlatformMessage preserves callback zone', () { diff --git a/engine/src/flutter/testing/litetest/README.md b/engine/src/flutter/testing/litetest/README.md new file mode 100644 index 0000000000..5b68112d9f --- /dev/null +++ b/engine/src/flutter/testing/litetest/README.md @@ -0,0 +1,14 @@ +# package:litetest + +This is a wrapper around `package:async_helper` from the Dart SDK source repo +at `//pkg/async_helper` that works in the environment of `flutter_tester`. +This wrapper is needed to ensure that all tests run to completion before the +process exits. This is accomplished by opening a `ReceivePort` for each test, +which is only closed when the test finishes running. + +## Limitations + +This package is intended only for use in the `flutter/engine` repo by unit +tests that run on `flutter_tester`. Even though the API resembles the API +provided by `package:test`, it has all the same limitations that +`package:async_helper` has. diff --git a/engine/src/flutter/testing/litetest/lib/litetest.dart b/engine/src/flutter/testing/litetest/lib/litetest.dart new file mode 100644 index 0000000000..44866281dd --- /dev/null +++ b/engine/src/flutter/testing/litetest/lib/litetest.dart @@ -0,0 +1,37 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// @dart = 2.12 + +import 'package:async_helper/async_minitest.dart'; // ignore: unused_import +import 'package:expect/expect.dart'; // ignore: unused_import + +import 'src/matchers.dart'; // ignore: unused_import +import 'src/test_suite.dart'; + +export 'package:async_helper/async_minitest.dart' hide group, test; +export 'package:expect/expect.dart'; +export 'src/matchers.dart'; + +final TestSuite _testSuite = TestSuite(); + +/// Describes the test named [name] given by the function [body]. +/// +/// After all tests are described, they will be run. All calls to [test] must be +/// made in the same event as the program's `main()` function. +void test( + String name, + dynamic Function() body, { + bool skip = false, +}) { + _testSuite.test(name, body, skip: skip); +} + +/// Describes a group of tests whose names will be prefixed with [name]. +/// +/// All calls to [group] must be made in the same event as the program's +/// `main()` function. +void group(String name, void Function() body) { + _testSuite.group(name, body); +} diff --git a/engine/src/flutter/testing/litetest/lib/src/matchers.dart b/engine/src/flutter/testing/litetest/lib/src/matchers.dart new file mode 100644 index 0000000000..431ebcd9fe --- /dev/null +++ b/engine/src/flutter/testing/litetest/lib/src/matchers.dart @@ -0,0 +1,114 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// @dart = 2.12 + +import 'package:async_helper/async_minitest.dart'; +import 'package:expect/expect.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; + +/// Asserts that `callback` throws an [AssertionError]. +/// +/// When running in a VM in which assertions are enabled, asserts that the +/// specified callback throws an [AssertionError]. When asserts are not +/// enabled, such as when running using a release-mode VM with default +/// settings, this acts as a no-op. +void expectAssertion(dynamic callback) { + bool assertsEnabled = false; + assert(() { + assertsEnabled = true; + return true; + }()); + if (assertsEnabled) { + throwsA(isInstanceOf())(callback); + } +} + +/// Asserts that `callback` throws an [ArgumentError]. +void expectArgumentError(dynamic callback) { + throwsA(isInstanceOf())(callback); +} + +/// Asserts that `callback` throws some [Exception]. +void throwsException(dynamic callback) { + throwsA(isInstanceOf())(callback); +} + +/// A [Matcher] that matches empty [String]s and [Iterable]s. +void isEmpty(dynamic d) { + if (d is String) { + expect(d.isEmpty, true); + return; + } + expect(d, isInstanceOf>()); + Expect.isEmpty(d as Iterable); +} + +/// A [Matcher] that matches non-empty [String]s and [Iterable]s. +void isNotEmpty(dynamic d) { + if (d is String) { + expect(d.isNotEmpty, true); + return; + } + expect(d, isInstanceOf>()); + Expect.isNotEmpty(d as Iterable); +} + +/// Gives a [Matcher] that asserts that the value being matched is within +/// `tolerance` of `value`. +Matcher closeTo(num value, num tolerance) => (dynamic actual) { + Expect.approxEquals(value, actual as num, tolerance); +}; + +/// A [Matcher] that matches NaN. +void isNaN(dynamic v) { + expect(v, isInstanceOf()); + expect(double.nan.compareTo(v as num) == 0, true); +} + +/// Gives a [Matcher] that asserts that the value being matched is not equal to +/// `unexpected`. +Matcher notEquals(dynamic unexpected) => (dynamic actual) { + Expect.notEquals(unexpected, actual); +}; + +/// A [Matcher] that matches non-zero values. +void isNonZero(dynamic d) { + Expect.notEquals(0, d); +} + +/// A [Matcher] that matches functions that throw a [RangeError] when invoked. +void throwsRangeError(dynamic d) { + Expect.throwsRangeError(d as void Function()); +} + +/// Gives a [Matcher] that asserts that the value being matched is a [String] +/// that contains `s` as a substring. +Matcher contains(String s) => (dynamic d) { + expect(d, isInstanceOf()); + Expect.contains(s, d as String); +}; + +/// Gives a [Matcher] that asserts that the value being matched is an [Iterable] +/// of length `d`. +Matcher hasLength(int l) => (dynamic d) { + expect(d, isInstanceOf>()); + expect((d as Iterable).length, equals(l)); +}; + +/// Gives a matcher that asserts that the value being matched is a [String] that +/// starts with `s`. +Matcher startsWith(String s) => (dynamic d) { + expect(d, isInstanceOf()); + final String h = d as String; + if (!h.startsWith(s)) { + Expect.fail('Expected "$h" to start with "$s"'); + } +}; diff --git a/engine/src/flutter/testing/litetest/lib/src/test.dart b/engine/src/flutter/testing/litetest/lib/src/test.dart new file mode 100644 index 0000000000..5660ed77d8 --- /dev/null +++ b/engine/src/flutter/testing/litetest/lib/src/test.dart @@ -0,0 +1,120 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// @dart = 2.12 + +import 'dart:async'; +import 'dart:io' show stdout; +import 'dart:isolate'; + +import 'package:async_helper/async_minitest.dart' as m; +import 'package:expect/expect.dart' as e; + +/// The state that each [Test] may be in. +enum TestState { + /// Initial state of a [Test] after it has been allocated. + allocated, + + /// State of a [Test] when it is on the queue of a [TestSuite]. + queued, + + /// State of a [Test] when it has been started. + started, + + /// State of a [Test] when it has succeeded. + succeeded, + + /// State of a [Test] when it has failed. + failed, +} + +/// A test that a [TestSuite] can enqueue to run. +class Test { + /// Creates a [Test] with the given name, body, logger, and lifecycle. + Test( + this.name, + this.body, { + StringSink? logger, + TestLifecycle? lifecycle, + }) : + _logger = logger ?? stdout, + _lifecycle = lifecycle ?? _DefaultTestLifecycle(name); + + /// The name of the test. + final String name; + + /// The body of the test. + final dynamic Function() body; + + /// The logger that records information about the test. + final StringSink _logger; + + /// The state that the test is in. + TestState state = TestState.allocated; + + final TestLifecycle _lifecycle; + + /// Runs the test. + /// + /// Also signals the test's progress to the [TestLifecycle] object + /// that was provided when the [Test] was constructed, which will eventually + /// call the provided [onDone] callback. + void run({ + void Function()? onDone, + }) { + m.test(name, () async { + await Future(() async { + state = TestState.started; + _logger.writeln('Test "$name": Started'); + try { + await body(); + state = TestState.succeeded; + _logger.writeln('Test "$name": Passed'); + } on e.ExpectException catch (e, st) { + state = TestState.failed; + _logger.writeln('Test "$name": Failed\n$e\n$st'); + } finally { + _lifecycle.onDone(cleanup: onDone); + } + }); + }); + _lifecycle.onStart(); + } +} + +/// Callbacks for the lifecycle of a test. +abstract class TestLifecycle { + /// Called after a test has started. + void onStart(); + + /// Called when a test is finished. + /// + /// The callback should ensure that the [cleanup] function should run + /// eventually if provided. + void onDone({void Function()? cleanup}); +} + +class _DefaultTestLifecycle implements TestLifecycle { + _DefaultTestLifecycle(String name) : _port = ReceivePort(name); + + final ReceivePort _port; + + void Function()? _cleanup; + + @override + void onStart() { + _port.listen((dynamic msg) { + _port.close(); + if (_cleanup != null) { + _cleanup!(); + } + }); + } + + @override + void onDone({void Function()? cleanup}) { + _port.sendPort.send(null); + _cleanup = cleanup; + } +} diff --git a/engine/src/flutter/testing/litetest/lib/src/test_suite.dart b/engine/src/flutter/testing/litetest/lib/src/test_suite.dart new file mode 100644 index 0000000000..1f5a08f13d --- /dev/null +++ b/engine/src/flutter/testing/litetest/lib/src/test_suite.dart @@ -0,0 +1,133 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// @dart = 2.12 + +import 'dart:async'; +import 'dart:collection'; +import 'dart:io' show exit, stdout; +import 'dart:isolate'; + +import 'package:async_helper/async_minitest.dart' as m; + +import 'test.dart'; + +/// A suite of tests, added with the [group] and [test] methods, which will be +/// run in a following event. +class TestSuite { + /// Creates a new [TestSuite] with logs written to [logger] and callbacks + /// given by [lifecycle]. + TestSuite({ + StringSink? logger, + Lifecycle? lifecycle, + }) : + _logger = logger ?? stdout, + _lifecycle = lifecycle ?? _DefaultLifecycle(); + + + final Lifecycle _lifecycle; + final StringSink _logger; + final Queue _groupStack = Queue(); + bool _testQueuePrimed = false; + final Queue _testQueue = Queue(); + final Map _runningTests = {}; + + /// Adds a test to the test suite. + void test( + String name, + dynamic Function() body, { + bool skip = false, + }) { + if (_runningTests.isNotEmpty) { + throw StateError( + 'Test "$name" added after tests have started to run. ' + 'Calls to test() must be synchronous with main().', + ); + } + if (skip) { + _logger.writeln('Test $name: Skipped'); + return; + } + final String groupName = _groupStack.isEmpty + ? name + : '${_groupStack.first} $name'; + _pushTest(groupName, body); + } + + /// Adds a group of tests to the test suite. + void group(String name, void Function() body) { + final String current = _groupStack.isEmpty ? '' : '${_groupStack.first} '; + _groupStack.addFirst('$current$name'); + m.group(name, body); + _groupStack.removeFirst(); + } + + void _pushTest( + String name, + dynamic Function() body, + ) { + final Test newTest = Test(name, body, logger: _logger); + _testQueue.add(newTest); + newTest.state = TestState.queued; + if (!_testQueuePrimed) { + // All groups() and tests() should be added synchronously with main, so + // we can enqueue an event to start all tests to run after main() is done. + Timer.run(_startAllTests); + _testQueuePrimed = true; + } + } + + void _startAllTests() { + for (final Test t in _testQueue) { + _runningTests[t.name] = t; + t.run(onDone: () { + _runningTests.remove(t.name); + if (_runningTests.isEmpty) { + _lifecycle.onDone(_testQueue); + } + }); + } + _lifecycle.onStart(); + } +} + +/// Callbacks for the lifecycle of a [TestSuite]. +abstract class Lifecycle { + /// Called after a test suite has started. + void onStart(); + + /// Called after the last test in a test suite has completed. + void onDone(Queue tests); +} + +class _DefaultLifecycle implements Lifecycle { + final ReceivePort _suitePort = ReceivePort('Suite port'); + Queue? _tests; + + @override + void onStart() { + _suitePort.listen((dynamic msg) { + _suitePort.close(); + _processResults(); + }); + } + + @override + void onDone(Queue tests) { + _tests = tests; + _suitePort.sendPort.send(null); + } + + void _processResults() { + bool testsSucceeded = true; + for (final Test t in _tests!) { + testsSucceeded = testsSucceeded && (t.state == TestState.succeeded); + } + if (testsSucceeded) { + exit(0); + } else { + exit(1); + } + } +} diff --git a/engine/src/flutter/testing/litetest/pubspec.yaml b/engine/src/flutter/testing/litetest/pubspec.yaml new file mode 100644 index 0000000000..55c8b2f978 --- /dev/null +++ b/engine/src/flutter/testing/litetest/pubspec.yaml @@ -0,0 +1,30 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +name: litetest +publish_to: none + +# Do not add any dependencies that require more than what is provided in +# //third_party/dart/pkg or //third_party/dart/third_party/pkg. +# In particular, package:test is not usable here. + +# If you do add packages here, make sure you can run `pub get --offline`, and +# check the .packages and .package_config to make sure all the paths are +# relative to this directory into //third_party/dart + +environment: + sdk: '>=2.12.0 <3.0.0' + +dependencies: + async_helper: any + expect: any + meta: any + +dependency_overrides: + async_helper: + path: ../../../third_party/dart/pkg/async_helper + expect: + path: ../../../third_party/dart/pkg/expect + meta: + path: ../../../third_party/dart/pkg/meta diff --git a/engine/src/flutter/testing/litetest/test/litetest_test.dart b/engine/src/flutter/testing/litetest/test/litetest_test.dart new file mode 100644 index 0000000000..dddfdb3ad7 --- /dev/null +++ b/engine/src/flutter/testing/litetest/test/litetest_test.dart @@ -0,0 +1,282 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// @dart = 2.12 + +import 'dart:async'; +import 'dart:collection'; + +import 'package:async_helper/async_helper.dart'; +import 'package:async_helper/async_minitest.dart'; +import 'package:litetest/src/test.dart'; +import 'package:litetest/src/test_suite.dart'; + +Future main() async { + asyncStart(); + + test('test', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test', () { + expect(1, equals(1)); + }); + final bool result = await lifecycle.result; + + expect(result, true); + expect(buffer.toString(), equals( + 'Test "Test": Started\nTest "Test": Passed\n', + )); + }); + + test('multiple tests', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test1', () { + expect(1, equals(1)); + }); + ts.test('Test2', () { + expect(2, equals(2)); + }); + ts.test('Test3', () { + expect(3, equals(3)); + }); + final bool result = await lifecycle.result; + + expect(result, true); + expect(buffer.toString(), equals(''' +Test "Test1": Started +Test "Test1": Passed +Test "Test2": Started +Test "Test2": Passed +Test "Test3": Started +Test "Test3": Passed +''', + )); + }); + + test('multiple tests with failure', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test1', () { + expect(1, equals(1)); + }); + ts.test('Test2', () { + expect(2, equals(3)); + }); + ts.test('Test3', () { + expect(3, equals(3)); + }); + final bool result = await lifecycle.result; + final String output = buffer.toString(); + + expect(result, false); + expect(output.contains('Test "Test1": Started'), true); + expect(output.contains('Test "Test1": Passed'), true); + expect(output.contains('Test "Test2": Started'), true); + expect(output.contains('Test "Test2": Failed'), true); + expect(output.contains( + 'In test "Test2" Expect.deepEquals(expected: <3>, actual: <2>) fails.', + ), true); + expect(output.contains('Test "Test3": Started'), true); + expect(output.contains('Test "Test3": Passed'), true); + }); + + test('group', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.group('Group', () { + ts.test('Test', () { + expect(1, equals(1)); + }); + }); + final bool result = await lifecycle.result; + + expect(result, true); + expect(buffer.toString(), equals( + 'Test "Group Test": Started\nTest "Group Test": Passed\n', + )); + }); + + test('nested group', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.group('Outer group', () { + ts.group('Inner group', () { + ts.test('Test1', () { + expect(1, equals(1)); + }); + }); + ts.test('Test2', () { + expect(1, equals(1)); + }); + }); + final bool result = await lifecycle.result; + + expect(result, true); + expect(buffer.toString(), equals(''' +Test "Outer group Inner group Test1": Started +Test "Outer group Inner group Test1": Passed +Test "Outer group Test2": Started +Test "Outer group Test2": Passed +''', + )); + }); + + test('test fail', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test', () { + expect(1, equals(2)); + }); + final bool result = await lifecycle.result; + final String output = buffer.toString(); + + expect(result, false); + expect(output.contains('Test "Test": Started'), true); + expect(output.contains('Test "Test": Failed'), true); + expect( + output.contains( + 'In test "Test" Expect.deepEquals(expected: <2>, actual: <1>) fails.', + ), + true, + ); + }); + + test('async test', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test', () async { + final Completer completer = Completer(); + Timer.run(() { + completer.complete(); + }); + await completer.future; + expect(1, equals(1)); + }); + final bool result = await lifecycle.result; + + expect(result, true); + expect(buffer.toString(), equals( + 'Test "Test": Started\nTest "Test": Passed\n', + )); + }); + + test('async test fail', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test', () async { + final Completer completer = Completer(); + Timer.run(() { + completer.complete(); + }); + await completer.future; + expect(1, equals(2)); + }); + final bool result = await lifecycle.result; + final String output = buffer.toString(); + + expect(result, false); + expect(output.contains('Test "Test": Started'), true); + expect(output.contains('Test "Test": Failed'), true); + expect( + output.contains( + 'In test "Test" Expect.deepEquals(expected: <2>, actual: <1>) fails.', + ), + true, + ); + }); + + test('throws StateError on async test() call', () async { + final StringBuffer buffer = StringBuffer(); + final TestLifecycle lifecycle = TestLifecycle(); + final TestSuite ts = TestSuite( + logger: buffer, + lifecycle: lifecycle, + ); + + ts.test('Test', () { + expect(1, equals(1)); + }); + + bool caughtError = false; + try { + await Future(() async { + ts.test('Bad Test', () {}); + }); + } on StateError catch (e) { + caughtError = true; + expect(e.message.contains( + 'Test "Bad Test" added after tests have started to run.', + ), true); + } + expect(caughtError, true); + + final bool result = await lifecycle.result; + + expect(result, true); + expect(buffer.toString(), equals( + 'Test "Test": Started\nTest "Test": Passed\n', + )); + }); + + asyncEnd(); +} + +class TestLifecycle implements Lifecycle { + final Completer _testCompleter = Completer(); + + Future get result => _testCompleter.future; + + @override + void onStart() {} + + @override + void onDone(Queue tests) { + bool testsSucceeded = true; + for (final Test t in tests) { + testsSucceeded = testsSucceeded && (t.state == TestState.succeeded); + } + _testCompleter.complete(testsSucceeded); + } +} diff --git a/engine/src/flutter/testing/run_tests.py b/engine/src/flutter/testing/run_tests.py index f37904cee6..4f5226d5f5 100755 --- a/engine/src/flutter/testing/run_tests.py +++ b/engine/src/flutter/testing/run_tests.py @@ -20,18 +20,19 @@ out_dir = os.path.join(buildroot_dir, 'out') golden_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'resources') fonts_dir = os.path.join(buildroot_dir, 'flutter', 'third_party', 'txt', 'third_party', 'fonts') roboto_font_path = os.path.join(fonts_dir, 'Roboto-Regular.ttf') -dart_tests_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'dart',) font_subset_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'font-subset') fml_unittests_filter = '--gtest_filter=-*TimeSensitiveTest*' + def PrintDivider(char='='): print '\n' for _ in xrange(4): print(''.join([char for _ in xrange(80)])) print '\n' -def RunCmd(cmd, forbidden_output=[], **kwargs): + +def RunCmd(cmd, forbidden_output=[], expect_failure=False, **kwargs): command_string = ' '.join(cmd) PrintDivider('>') @@ -44,7 +45,7 @@ def RunCmd(cmd, forbidden_output=[], **kwargs): stdout, stderr = process.communicate() end_time = time.time() - if process.returncode != 0: + if process.returncode != 0 and not expect_failure: PrintDivider('!') print('Failed Command:\n\n%s\n\nExit Code: %d\n' % (command_string, process.returncode)) @@ -86,6 +87,7 @@ def IsWindows(): def ExecutableSuffix(): return '.exe' if IsWindows() else '' + def FindExecutablePath(path): if os.path.exists(path): return path @@ -102,7 +104,8 @@ def FindExecutablePath(path): raise Exception('Executable %s does not exist!' % path) -def RunEngineExecutable(build_dir, executable_name, filter, flags=[], cwd=buildroot_dir, forbidden_output=[]): +def RunEngineExecutable(build_dir, executable_name, filter, flags=[], + cwd=buildroot_dir, forbidden_output=[], expect_failure=False): if filter is not None and executable_name not in filter: print('Skipping %s due to filter.' % executable_name) return @@ -112,7 +115,7 @@ def RunEngineExecutable(build_dir, executable_name, filter, flags=[], cwd=buildr print('Running %s in %s' % (executable_name, cwd)) test_command = [ executable ] + flags print(' '.join(test_command)) - RunCmd(test_command, cwd=cwd, forbidden_output=forbidden_output) + RunCmd(test_command, cwd=cwd, forbidden_output=forbidden_output, expect_failure=expect_failure) def RunCCTests(build_dir, filter): @@ -202,14 +205,12 @@ def RunEngineBenchmarks(build_dir, filter): RunEngineExecutable(build_dir, 'txt_benchmarks', filter) - -def SnapshotTest(build_dir, dart_file, kernel_file_output, verbose_dart_snapshot): +def SnapshotTest(build_dir, test_packages, dart_file, kernel_file_output, verbose_dart_snapshot): print("Generating snapshot for test %s" % dart_file) dart = os.path.join(build_dir, 'dart-sdk', 'bin', 'dart') frontend_server = os.path.join(build_dir, 'gen', 'frontend_server.dart.snapshot') flutter_patched_sdk = os.path.join(build_dir, 'flutter_patched_sdk') - test_packages = os.path.join(dart_tests_dir, '.packages') assert os.path.exists(dart) assert os.path.exists(frontend_server) @@ -218,6 +219,7 @@ def SnapshotTest(build_dir, dart_file, kernel_file_output, verbose_dart_snapshot snapshot_command = [ dart, + '--disable-dart-dev', frontend_server, '--enable-experiment=non-nullable', '--no-sound-null-safety', @@ -246,11 +248,12 @@ def SnapshotTest(build_dir, dart_file, kernel_file_output, verbose_dart_snapshot assert os.path.exists(kernel_file_output) -def RunDartTest(build_dir, dart_file, verbose_dart_snapshot, multithreaded, enable_observatory=False): +def RunDartTest(build_dir, test_packages, dart_file, verbose_dart_snapshot, multithreaded, + enable_observatory=False, expect_failure=False): kernel_file_name = os.path.basename(dart_file) + '.kernel.dill' kernel_file_output = os.path.join(out_dir, kernel_file_name) - SnapshotTest(build_dir, dart_file, kernel_file_output, verbose_dart_snapshot) + SnapshotTest(build_dir, test_packages, dart_file, kernel_file_output, verbose_dart_snapshot) command_args = [] if not enable_observatory: @@ -269,16 +272,8 @@ def RunDartTest(build_dir, dart_file, verbose_dart_snapshot, multithreaded, enab print("Running test '%s' using 'flutter_tester' (%s)" % (kernel_file_name, threading)) forbidden_output = [] if 'unopt' in build_dir else ['[ERROR'] - RunEngineExecutable(build_dir, 'flutter_tester', None, command_args, forbidden_output=forbidden_output) - -def RunPubGet(build_dir, directory): - print("Running 'pub get' in the tests directory %s" % dart_tests_dir) - - pub_get_command = [ - os.path.join(build_dir, 'dart-sdk', 'bin', 'pub'), - 'get' - ] - RunCmd(pub_get_command, cwd=directory) + RunEngineExecutable(build_dir, 'flutter_tester', None, command_args, + forbidden_output=forbidden_output, expect_failure=expect_failure) def EnsureDebugUnoptSkyPackagesAreBuilt(): @@ -308,6 +303,7 @@ def EnsureDebugUnoptSkyPackagesAreBuilt(): RunCmd(gn_command, cwd=buildroot_dir) RunCmd(ninja_command, cwd=buildroot_dir) + def EnsureJavaTestsAreBuilt(android_out_dir): """Builds the engine variant and the test jar containing the JUnit tests""" ninja_command = [ @@ -336,6 +332,7 @@ def EnsureJavaTestsAreBuilt(android_out_dir): RunCmd(gn_command, cwd=buildroot_dir) RunCmd(ninja_command, cwd=buildroot_dir) + def EnsureIosTestsAreBuilt(ios_out_dir): """Builds the engine variant and the test dylib containing the XCTests""" ninja_command = [ @@ -365,6 +362,7 @@ def EnsureIosTestsAreBuilt(ios_out_dir): RunCmd(gn_command, cwd=buildroot_dir) RunCmd(ninja_command, cwd=buildroot_dir) + def AssertExpectedJavaVersion(): """Checks that the user has Java 8 which is the supported Java version for Android""" EXPECTED_VERSION = '1.8' @@ -374,6 +372,7 @@ def AssertExpectedJavaVersion(): message = "JUnit tests need to be run with Java %s. Check the `java -version` on your PATH." % EXPECTED_VERSION assert match, message + def AssertExpectedXcodeVersion(): """Checks that the user has a recent version of Xcode installed""" EXPECTED_MAJOR_VERSION = ['11', '12'] @@ -382,6 +381,7 @@ def AssertExpectedXcodeVersion(): message = "Xcode must be installed to run the iOS embedding unit tests" assert match.group(1) in EXPECTED_MAJOR_VERSION, message + def RunJavaTests(filter, android_variant='android_debug_unopt'): """Runs the Java JUnit unit tests for the Android embedding""" AssertExpectedJavaVersion() @@ -409,6 +409,7 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'): RunCmd(command) + def RunObjcTests(ios_variant='ios_debug_sim_unopt'): """Runs Objective-C XCTest unit tests for the iOS embedding""" AssertExpectedXcodeVersion() @@ -432,16 +433,25 @@ def RunObjcTests(ios_variant='ios_debug_sim_unopt'): RunCmd(command, cwd=ios_unit_test_dir, shell=True) def RunDartTests(build_dir, filter, verbose_dart_snapshot): + dart_tests_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'dart',) + # This one is a bit messy. The pubspec.yaml at flutter/testing/dart/pubspec.yaml # has dependencies that are hardcoded to point to the sky packages at host_debug_unopt/ # Before running Dart tests, make sure to run just that target (NOT the whole engine) EnsureDebugUnoptSkyPackagesAreBuilt() # Now that we have the Sky packages at the hardcoded location, run `pub get`. - RunEngineExecutable(build_dir, os.path.join('dart-sdk', 'bin', 'pub'), None, flags=['get'], cwd=dart_tests_dir) + RunEngineExecutable( + build_dir, + os.path.join('dart-sdk', 'bin', 'pub'), + None, + flags=['get', '--offline'], + cwd=dart_tests_dir, + ) dart_observatory_tests = glob.glob('%s/observatory/*_test.dart' % dart_tests_dir) dart_tests = glob.glob('%s/*_test.dart' % dart_tests_dir) + test_packages = os.path.join(dart_tests_dir, '.packages') if 'release' not in build_dir: for dart_test_file in dart_observatory_tests: @@ -449,16 +459,23 @@ def RunDartTests(build_dir, filter, verbose_dart_snapshot): print("Skipping %s due to filter." % dart_test_file) else: print("Testing dart file %s with observatory enabled" % dart_test_file) - RunDartTest(build_dir, dart_test_file, verbose_dart_snapshot, True, True) - RunDartTest(build_dir, dart_test_file, verbose_dart_snapshot, False, True) + RunDartTest(build_dir, test_packages, dart_test_file, verbose_dart_snapshot, True, True) + RunDartTest(build_dir, test_packages, dart_test_file, verbose_dart_snapshot, False, True) for dart_test_file in dart_tests: if filter is not None and os.path.basename(dart_test_file) not in filter: print("Skipping %s due to filter." % dart_test_file) else: print("Testing dart file %s" % dart_test_file) - RunDartTest(build_dir, dart_test_file, verbose_dart_snapshot, True) - RunDartTest(build_dir, dart_test_file, verbose_dart_snapshot, False) + RunDartTest(build_dir, test_packages, dart_test_file, verbose_dart_snapshot, True) + RunDartTest(build_dir, test_packages, dart_test_file, verbose_dart_snapshot, False) + + +def RunDartSmokeTest(build_dir, verbose_dart_snapshot): + smoke_test = os.path.join(buildroot_dir, "flutter", "testing", "smoke_test_failure", "fail_test.dart") + test_packages = os.path.join(buildroot_dir, "flutter", "testing", "smoke_test_failure", ".packages") + RunDartTest(build_dir, test_packages, smoke_test, verbose_dart_snapshot, True, expect_failure=True) + RunDartTest(build_dir, test_packages, smoke_test, verbose_dart_snapshot, False, expect_failure=True) def RunFrontEndServerTests(build_dir): @@ -466,6 +483,7 @@ def RunFrontEndServerTests(build_dir): dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = [ + '--disable-dart-dev', dart_test_file, os.path.join(build_dir, 'gen', 'frontend_server.dart.snapshot'), os.path.join(build_dir, 'flutter_patched_sdk')] @@ -480,11 +498,28 @@ def RunFrontEndServerTests(build_dir): def RunConstFinderTests(build_dir): test_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'const_finder', 'test') opts = [ + '--disable-dart-dev', os.path.join(test_dir, 'const_finder_test.dart'), os.path.join(build_dir, 'gen', 'frontend_server.dart.snapshot'), os.path.join(build_dir, 'flutter_patched_sdk')] RunEngineExecutable(build_dir, os.path.join('dart-sdk', 'bin', 'dart'), None, flags=opts, cwd=test_dir) + +def RunLitetestTests(build_dir): + test_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'litetest') + dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) + for dart_test_file in dart_tests: + opts = [ + '--disable-dart-dev', + dart_test_file] + RunEngineExecutable( + build_dir, + os.path.join('dart-sdk', 'bin', 'dart'), + None, + flags=opts, + cwd=test_dir) + + def main(): parser = argparse.ArgumentParser() @@ -524,9 +559,11 @@ def main(): if 'dart' in types: assert not IsWindows(), "Dart tests can't be run on windows. https://github.com/flutter/flutter/issues/36301." dart_filter = args.dart_filter.split(',') if args.dart_filter else None + RunDartSmokeTest(build_dir, args.verbose_dart_snapshot) RunDartTests(build_dir, dart_filter, args.verbose_dart_snapshot) RunConstFinderTests(build_dir) RunFrontEndServerTests(build_dir) + RunLitetestTests(build_dir) if 'java' in types: assert not IsWindows(), "Android engine files can't be compiled on Windows." diff --git a/engine/src/flutter/testing/smoke_test_failure/fail_test.dart b/engine/src/flutter/testing/smoke_test_failure/fail_test.dart index a6fe64be77..5c9419afb7 100644 --- a/engine/src/flutter/testing/smoke_test_failure/fail_test.dart +++ b/engine/src/flutter/testing/smoke_test_failure/fail_test.dart @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.6 -import 'package:test/test.dart'; +// @dart = 2.12 + +import 'package:litetest/litetest.dart'; void main() { test('test smoke test -- this test SHOULD FAIL', () { diff --git a/engine/src/flutter/testing/smoke_test_failure/pubspec.yaml b/engine/src/flutter/testing/smoke_test_failure/pubspec.yaml index 52402200f4..584f17c19b 100644 --- a/engine/src/flutter/testing/smoke_test_failure/pubspec.yaml +++ b/engine/src/flutter/testing/smoke_test_failure/pubspec.yaml @@ -1,6 +1,29 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + name: smoke_test_failure +publish_to: none environment: - sdk: '>=2.11.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' + +# Do not add any dependencies that require more than what is provided in +# //third_party/dart/pkg or //third_party/dart/third_party/pkg. +# In particular, package:test is not usable here. + +# If you do add packages here, make sure you can run `pub get --offline`, and +# check the .packages and .package_config to make sure all the paths are +# relative to this directory into //third_party/dart + dependencies: - test: 1.3.0 - path: 1.6.2 + litetest: any + +dependency_overrides: + async_helper: + path: ../../../third_party/dart/pkg/async_helper + expect: + path: ../../../third_party/dart/pkg/expect + litetest: + path: ../litetest + meta: + path: ../../../third_party/dart/pkg/meta diff --git a/engine/src/flutter/tools/licenses/lib/main.dart b/engine/src/flutter/tools/licenses/lib/main.dart index 20a9c64411..525e0092c7 100644 --- a/engine/src/flutter/tools/licenses/lib/main.dart +++ b/engine/src/flutter/tools/licenses/lib/main.dart @@ -1666,8 +1666,11 @@ class _RepositoryPkgDirectory extends _RepositoryDirectory { bool shouldRecurse(fs.IoNode entry) { return entry.name != 'archive' // contains nothing that ends up in the binary executable && entry.name != 'file' + && entry.name != 'image' + && entry.name != 'petitparser' && entry.name != 'platform' - && entry.name != 'process'; + && entry.name != 'process' + && entry.name != 'xml'; } @override diff --git a/engine/src/flutter/tools/pub_get_offline.py b/engine/src/flutter/tools/pub_get_offline.py index f93a9f06ba..b6e55883b0 100644 --- a/engine/src/flutter/tools/pub_get_offline.py +++ b/engine/src/flutter/tools/pub_get_offline.py @@ -16,6 +16,8 @@ import sys ALL_PACKAGES = [ os.path.join("src", "flutter", "flutter_frontend_server"), + os.path.join("src", "flutter", "testing", "litetest"), + os.path.join("src", "flutter", "testing", "smoke_test_failure"), os.path.join("src", "flutter", "tools", "android_lint"), os.path.join("src", "flutter", "tools", "const_finder"), os.path.join("src", "flutter", "tools", "licenses"),