[framework] dont null assert in _debugVerifyIllFatedPopulation (#96551)

This commit is contained in:
Jonah Williams 2022-01-14 13:50:29 -08:00 committed by GitHub
parent 88327e3b72
commit e25e1f9037
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 3 deletions

View file

@ -710,6 +710,12 @@ Future<void> _runFrameworkTests() async {
options: <String>['--dart-define=dart.vm.product=true', ...soundNullSafetyOptions],
tests: <String>['test_release${path.separator}'],
);
// Run profile mode tests (see packages/flutter/test_profile/README.md)
await _runFlutterTest(
path.join(flutterRoot, 'packages', 'flutter'),
options: <String>['--dart-define=dart.vm.product=false', '--dart-define=dart.vm.profile=true', ...soundNullSafetyOptions],
tests: <String>['test_profile${path.separator}'],
);
}
Future<void> runLibraries() async {

View file

@ -2879,7 +2879,7 @@ class BuildOwner {
void _debugVerifyIllFatedPopulation() {
assert(() {
Map<GlobalKey, Set<Element>>? duplicates;
for (final Element element in _debugIllFatedElements!) {
for (final Element element in _debugIllFatedElements ?? const <Element>{}) {
if (element._lifecycleState != _ElementLifecycle.defunct) {
assert(element != null);
assert(element.widget != null);

View file

@ -0,0 +1,3 @@
This folder contains unit tests that are run with `kProfileMode` set to true. This can be used for unit testing code that is guarded by this boolean, such as in cases where debug code is intentionally ellided for performance or code size reasons. The unit tests are still run in the VM and are not otherwise precompiled.
To run these test from the command line, use the command: `flutter test --dart-define=dart.vm.profile=true test_release/`

View file

@ -0,0 +1,14 @@
// Copyright 2014 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.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can build widget tree in profile mode with asserts enabled', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: Center(child: Text('Hello World')))));
expect(tester.takeException(), isNull);
});
}

View file

@ -167,9 +167,10 @@ List<String> buildModeOptions(BuildMode mode, List<String> dartDefines) {
switch (mode) {
case BuildMode.debug:
return <String>[
'-Ddart.vm.profile=false',
// This allows the CLI to override the value of this define for unit
// These checks allow the CLI to override the value of this define for unit
// testing the framework.
if (!dartDefines.any((String define) => define.startsWith('dart.vm.profile')))
'-Ddart.vm.profile=false',
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
'-Ddart.vm.product=false',
'--enable-asserts',

View file

@ -88,4 +88,17 @@ void main() {
'--enable-asserts',
]);
});
testWithoutContext('buildModeOptions removes matching profile define', () {
expect(buildModeOptions(BuildMode.debug, <String>['dart.vm.profile=true']), <String>[
'-Ddart.vm.product=false',
'--enable-asserts',
]);
});
testWithoutContext('buildModeOptions removes both matching profile and release define', () {
expect(buildModeOptions(BuildMode.debug, <String>['dart.vm.profile=true', 'dart.vm.product=true']), <String>[
'--enable-asserts',
]);
});
}