mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add testing shard for release mode guard (#71411)
This commit is contained in:
parent
a264c2bee2
commit
7ab0442868
@ -652,6 +652,13 @@ Future<void> _runFrameworkTests() async {
|
||||
tableData: bigqueryApi?.tabledata,
|
||||
);
|
||||
}
|
||||
// Run release mode tests (see packages/flutter/test_release/README.md)
|
||||
await _runFlutterTest(
|
||||
path.join(flutterRoot, 'packages', 'flutter'),
|
||||
options: <String>['--dart-define=dart.vm.product=true', ...soundNullSafetyOptions],
|
||||
tableData: bigqueryApi?.tabledata,
|
||||
tests: <String>[ 'test_release' + path.separator ],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> runLibraries() async {
|
||||
|
3
packages/flutter/test_release/README.md
Normal file
3
packages/flutter/test_release/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
This folder contains unit tests that are run with `kReleaseMode` 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.product=true test_release/`
|
40
packages/flutter/test_release/diagnostics_test.dart
Normal file
40
packages/flutter/test_release/diagnostics_test.dart
Normal file
@ -0,0 +1,40 @@
|
||||
// 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/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('TextTreeRenderer returns an empty string in release mode', () {
|
||||
final TextTreeRenderer renderer = TextTreeRenderer();
|
||||
final TestDiagnosticsNode node = TestDiagnosticsNode();
|
||||
|
||||
expect(renderer.render(node), '');
|
||||
});
|
||||
}
|
||||
|
||||
class TestDiagnosticsNode extends DiagnosticsNode {
|
||||
TestDiagnosticsNode() : super(
|
||||
name: 'test',
|
||||
style: DiagnosticsTreeStyle.singleLine,
|
||||
);
|
||||
|
||||
@override
|
||||
List<DiagnosticsNode> getChildren() {
|
||||
return <DiagnosticsNode>[];
|
||||
}
|
||||
|
||||
@override
|
||||
List<DiagnosticsNode> getProperties() {
|
||||
return <DiagnosticsNode>[];
|
||||
}
|
||||
|
||||
@override
|
||||
String? toDescription({TextTreeConfiguration? parentConfiguration}) {
|
||||
return 'Test Description';
|
||||
}
|
||||
|
||||
@override
|
||||
final Object? value = Object();
|
||||
}
|
14
packages/flutter/test_release/precondition_test.dart
Normal file
14
packages/flutter/test_release/precondition_test.dart
Normal 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/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
// This test verifies that the test_release shard is configured correctly.
|
||||
// See README.md in this directory for more information.
|
||||
void main() {
|
||||
test('kReleaseMode is set to true', () {
|
||||
expect(kReleaseMode, true);
|
||||
});
|
||||
}
|
@ -146,12 +146,15 @@ class StdoutHandler {
|
||||
}
|
||||
|
||||
/// List the preconfigured build options for a given build mode.
|
||||
List<String> buildModeOptions(BuildMode mode) {
|
||||
List<String> buildModeOptions(BuildMode mode, List<String> dartDefines) {
|
||||
switch (mode) {
|
||||
case BuildMode.debug:
|
||||
return <String>[
|
||||
'-Ddart.vm.profile=false',
|
||||
'-Ddart.vm.product=false',
|
||||
// This allows the CLI to override the value of this define for unit
|
||||
// testing the framework.
|
||||
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
|
||||
'-Ddart.vm.product=false',
|
||||
'--enable-asserts',
|
||||
];
|
||||
case BuildMode.profile:
|
||||
@ -241,7 +244,7 @@ class KernelCompiler {
|
||||
'-Ddart.developer.causal_async_stacks=${buildMode == BuildMode.debug}',
|
||||
for (final Object dartDefine in dartDefines)
|
||||
'-D$dartDefine',
|
||||
...buildModeOptions(buildMode),
|
||||
...buildModeOptions(buildMode, dartDefines),
|
||||
if (trackWidgetCreation) '--track-widget-creation',
|
||||
if (!linkPlatformKernelIn) '--no-link-platform',
|
||||
if (aot) ...<String>[
|
||||
@ -672,7 +675,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
|
||||
'--packages',
|
||||
packagesPath,
|
||||
],
|
||||
...buildModeOptions(buildMode),
|
||||
...buildModeOptions(buildMode, dartDefines),
|
||||
if (trackWidgetCreation) '--track-widget-creation',
|
||||
if (fileSystemRoots != null)
|
||||
for (final String root in fileSystemRoots) ...<String>[
|
||||
|
@ -90,7 +90,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=false',
|
||||
...buildModeOptions(BuildMode.profile),
|
||||
...buildModeOptions(BuildMode.profile, <String>[]),
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--packages',
|
||||
@ -127,7 +127,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=false',
|
||||
...buildModeOptions(BuildMode.profile),
|
||||
...buildModeOptions(BuildMode.profile, <String>[]),
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--packages',
|
||||
@ -164,7 +164,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=false',
|
||||
...buildModeOptions(BuildMode.profile),
|
||||
...buildModeOptions(BuildMode.profile, <String>[]),
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--packages',
|
||||
@ -202,7 +202,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=false',
|
||||
...buildModeOptions(BuildMode.profile),
|
||||
...buildModeOptions(BuildMode.profile, <String>[]),
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--packages',
|
||||
@ -242,7 +242,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=true',
|
||||
...buildModeOptions(BuildMode.debug),
|
||||
...buildModeOptions(BuildMode.debug, <String>[]),
|
||||
'--no-link-platform',
|
||||
'--packages',
|
||||
'/.dart_tool/package_config.json',
|
||||
@ -280,7 +280,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=true',
|
||||
...buildModeOptions(BuildMode.debug),
|
||||
...buildModeOptions(BuildMode.debug, <String>[]),
|
||||
'--packages',
|
||||
'/.dart_tool/package_config.json',
|
||||
'--output-dill',
|
||||
@ -330,7 +330,7 @@ void main() {
|
||||
'--target=flutter',
|
||||
'--no-print-incremental-dependencies',
|
||||
'-Ddart.developer.causal_async_stacks=true',
|
||||
...buildModeOptions(BuildMode.debug),
|
||||
...buildModeOptions(BuildMode.debug, <String>[]),
|
||||
'--track-widget-creation',
|
||||
'--no-link-platform',
|
||||
'--packages',
|
||||
|
@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/compile.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
@ -43,4 +44,11 @@ void main() {
|
||||
expect(toMultiRootPath(Uri.parse('org-dartlang-app:///a/b/c'), null, <String>[], false), 'org-dartlang-app:///a/b/c');
|
||||
expect(toMultiRootPath(Uri.parse('org-dartlang-app:///a/b/c'), 'scheme', <String>['/d/b'], false), 'org-dartlang-app:///a/b/c');
|
||||
});
|
||||
|
||||
testWithoutContext('buildModeOptions removes matching product define', () {
|
||||
expect(buildModeOptions(BuildMode.debug, <String>['dart.vm.product=true']), <String>[
|
||||
'-Ddart.vm.profile=false',
|
||||
'--enable-asserts',
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user