Adds package:litetest, uses it instead of package:test under testing/dart (flutter/engine#26215)

This commit is contained in:
Zachary Anderson
2021-05-19 23:08:23 -07:00
committed by GitHub
parent f438f689bb
commit 740a85e9f0
45 changed files with 1037 additions and 237 deletions

9
DEPS
View File

@@ -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': [
{

View File

@@ -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" \

View File

@@ -1,2 +1,2 @@
Signature: 7af516b6fef310e37406f37cc6da30ae
Signature: 469fde92656a4a5e122b7601271cf2cb

View File

@@ -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);

View File

@@ -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);

View File

@@ -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(<int>[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>((Exception e) {
return e is Exception && e.toString().contains(m);
});
}

View File

@@ -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);

View File

@@ -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)));
});

View File

@@ -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<AssertionError>()),
expectAssertion,
);
return true;
}());
@@ -42,7 +42,7 @@ void main() {
assert(() {
expect(
() => builder.pushTransform(matrix4NaN),
throwsA(const TypeMatcher<AssertionError>()),
expectAssertion,
);
return true;
}());
@@ -56,7 +56,7 @@ void main() {
assert(() {
expect(
() => builder.pushTransform(matrix4Infinity),
throwsA(const TypeMatcher<AssertionError>()),
expectAssertion,
);
return true;
}());

View File

@@ -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() {

View File

@@ -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;

View File

@@ -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', () {

View File

@@ -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<AssertionError>()),
expectAssertion,
);
return true;
}());

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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()));
}
}
}

View File

@@ -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;

View File

@@ -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<void, dynamic>((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<void, dynamic>((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<void, dynamic>((dynamic message) {
// If we don't get this message, we timeout and fail.
expect(message, kPortName);
}));
receivePort.listen(expectAsync1<void, dynamic>((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);
}
});
}

View File

@@ -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 = Isolate.spawnUri(Uri.parse('http://127.0.0.1/foo.dart'), <String>[], null);
expect(() async => isolate, throwsA(const TypeMatcher<IsolateSpawnException>()));
bool threw = false;
try {
await Isolate.spawnUri(
Uri.parse('http://127.0.0.1/foo.dart'),
<String>[],
null,
);
} on IsolateSpawnException {
threw = true;
}
expect(threw, true);
});
}

View File

@@ -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<AssertionError>());

View File

@@ -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 \'\'', () {

View File

@@ -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<void> completer = Completer<void>();
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();
});
}

View File

@@ -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.

View File

@@ -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.

View File

@@ -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', () {

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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

View File

@@ -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() {

View File

@@ -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 {

View File

@@ -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);
}

View File

@@ -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', () {

View File

@@ -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', () {

View File

@@ -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.

View File

@@ -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);
}

View File

@@ -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<AssertionError>())(callback);
}
}
/// Asserts that `callback` throws an [ArgumentError].
void expectArgumentError(dynamic callback) {
throwsA(isInstanceOf<ArgumentError>())(callback);
}
/// Asserts that `callback` throws some [Exception].
void throwsException(dynamic callback) {
throwsA(isInstanceOf<Exception>())(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<Iterable<dynamic>>());
Expect.isEmpty(d as Iterable<dynamic>);
}
/// 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<Iterable<dynamic>>());
Expect.isNotEmpty(d as Iterable<dynamic>);
}
/// 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<num>());
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<String>());
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<Iterable<dynamic>>());
expect((d as Iterable<dynamic>).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<String>());
final String h = d as String;
if (!h.startsWith(s)) {
Expect.fail('Expected "$h" to start with "$s"');
}
};

View File

@@ -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<void>(() 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;
}
}

View File

@@ -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<String> _groupStack = Queue<String>();
bool _testQueuePrimed = false;
final Queue<Test> _testQueue = Queue<Test>();
final Map<String, Test> _runningTests = <String, Test>{};
/// 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<Test> tests);
}
class _DefaultLifecycle implements Lifecycle {
final ReceivePort _suitePort = ReceivePort('Suite port');
Queue<Test>? _tests;
@override
void onStart() {
_suitePort.listen((dynamic msg) {
_suitePort.close();
_processResults();
});
}
@override
void onDone(Queue<Test> 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);
}
}
}

View File

@@ -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

View File

@@ -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<void> 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<void> completer = Completer<void>();
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<void> completer = Completer<void>();
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<void>(() 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<bool> _testCompleter = Completer<bool>();
Future<bool> get result => _testCompleter.future;
@override
void onStart() {}
@override
void onDone(Queue<Test> tests) {
bool testsSucceeded = true;
for (final Test t in tests) {
testsSucceeded = testsSucceeded && (t.state == TestState.succeeded);
}
_testCompleter.complete(testsSucceeded);
}
}

View File

@@ -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."

View File

@@ -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', () {

View File

@@ -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

View File

@@ -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

View File

@@ -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"),