Unverified Commit 7ab04428 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add testing shard for release mode guard (#71411)

parent a264c2be
...@@ -652,6 +652,13 @@ Future<void> _runFrameworkTests() async { ...@@ -652,6 +652,13 @@ Future<void> _runFrameworkTests() async {
tableData: bigqueryApi?.tabledata, 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 { Future<void> runLibraries() async {
......
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/`
// 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();
}
// 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 { ...@@ -146,12 +146,15 @@ class StdoutHandler {
} }
/// List the preconfigured build options for a given build mode. /// 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) { switch (mode) {
case BuildMode.debug: case BuildMode.debug:
return <String>[ return <String>[
'-Ddart.vm.profile=false', '-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', '--enable-asserts',
]; ];
case BuildMode.profile: case BuildMode.profile:
...@@ -241,7 +244,7 @@ class KernelCompiler { ...@@ -241,7 +244,7 @@ class KernelCompiler {
'-Ddart.developer.causal_async_stacks=${buildMode == BuildMode.debug}', '-Ddart.developer.causal_async_stacks=${buildMode == BuildMode.debug}',
for (final Object dartDefine in dartDefines) for (final Object dartDefine in dartDefines)
'-D$dartDefine', '-D$dartDefine',
...buildModeOptions(buildMode), ...buildModeOptions(buildMode, dartDefines),
if (trackWidgetCreation) '--track-widget-creation', if (trackWidgetCreation) '--track-widget-creation',
if (!linkPlatformKernelIn) '--no-link-platform', if (!linkPlatformKernelIn) '--no-link-platform',
if (aot) ...<String>[ if (aot) ...<String>[
...@@ -672,7 +675,7 @@ class DefaultResidentCompiler implements ResidentCompiler { ...@@ -672,7 +675,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
'--packages', '--packages',
packagesPath, packagesPath,
], ],
...buildModeOptions(buildMode), ...buildModeOptions(buildMode, dartDefines),
if (trackWidgetCreation) '--track-widget-creation', if (trackWidgetCreation) '--track-widget-creation',
if (fileSystemRoots != null) if (fileSystemRoots != null)
for (final String root in fileSystemRoots) ...<String>[ for (final String root in fileSystemRoots) ...<String>[
......
...@@ -90,7 +90,7 @@ void main() { ...@@ -90,7 +90,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=false', '-Ddart.developer.causal_async_stacks=false',
...buildModeOptions(BuildMode.profile), ...buildModeOptions(BuildMode.profile, <String>[]),
'--aot', '--aot',
'--tfa', '--tfa',
'--packages', '--packages',
...@@ -127,7 +127,7 @@ void main() { ...@@ -127,7 +127,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=false', '-Ddart.developer.causal_async_stacks=false',
...buildModeOptions(BuildMode.profile), ...buildModeOptions(BuildMode.profile, <String>[]),
'--aot', '--aot',
'--tfa', '--tfa',
'--packages', '--packages',
...@@ -164,7 +164,7 @@ void main() { ...@@ -164,7 +164,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=false', '-Ddart.developer.causal_async_stacks=false',
...buildModeOptions(BuildMode.profile), ...buildModeOptions(BuildMode.profile, <String>[]),
'--aot', '--aot',
'--tfa', '--tfa',
'--packages', '--packages',
...@@ -202,7 +202,7 @@ void main() { ...@@ -202,7 +202,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=false', '-Ddart.developer.causal_async_stacks=false',
...buildModeOptions(BuildMode.profile), ...buildModeOptions(BuildMode.profile, <String>[]),
'--aot', '--aot',
'--tfa', '--tfa',
'--packages', '--packages',
...@@ -242,7 +242,7 @@ void main() { ...@@ -242,7 +242,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=true', '-Ddart.developer.causal_async_stacks=true',
...buildModeOptions(BuildMode.debug), ...buildModeOptions(BuildMode.debug, <String>[]),
'--no-link-platform', '--no-link-platform',
'--packages', '--packages',
'/.dart_tool/package_config.json', '/.dart_tool/package_config.json',
...@@ -280,7 +280,7 @@ void main() { ...@@ -280,7 +280,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=true', '-Ddart.developer.causal_async_stacks=true',
...buildModeOptions(BuildMode.debug), ...buildModeOptions(BuildMode.debug, <String>[]),
'--packages', '--packages',
'/.dart_tool/package_config.json', '/.dart_tool/package_config.json',
'--output-dill', '--output-dill',
...@@ -330,7 +330,7 @@ void main() { ...@@ -330,7 +330,7 @@ void main() {
'--target=flutter', '--target=flutter',
'--no-print-incremental-dependencies', '--no-print-incremental-dependencies',
'-Ddart.developer.causal_async_stacks=true', '-Ddart.developer.causal_async_stacks=true',
...buildModeOptions(BuildMode.debug), ...buildModeOptions(BuildMode.debug, <String>[]),
'--track-widget-creation', '--track-widget-creation',
'--no-link-platform', '--no-link-platform',
'--packages', '--packages',
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/compile.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -43,4 +44,11 @@ void main() { ...@@ -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'), 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'); 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',
]);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment