flutter/packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart
Ian Hickson 449f4a6673
License update (#45373)
* Update project.pbxproj files to say Flutter rather than Chromium

Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright.

* Update the copyright notice checker to require a standard notice on all files

* Update copyrights on Dart files. (This was a mechanical commit.)

* Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine.

Some were already marked "The Flutter Authors", not clear why. Their
dates have been normalized. Some were missing the blank line after the
license. Some were randomly different in trivial ways for no apparent
reason (e.g. missing the trailing period).

* Clean up the copyrights in non-Dart files. (Manual edits.)

Also, make sure templates don't have copyrights.

* Fix some more ORGANIZATIONNAMEs
2019-11-27 15:04:02 -08:00

241 lines
9.0 KiB
Dart

// 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:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/dart.dart';
import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_bundle.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/testbed.dart';
void main() {
Cache.disableLocking();
Directory tempDir;
MockBundleBuilder mockBundleBuilder;
setUp(() {
tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
mockBundleBuilder = MockBundleBuilder();
when(
mockBundleBuilder.build(
platform: anyNamed('platform'),
buildMode: anyNamed('buildMode'),
mainPath: anyNamed('mainPath'),
manifestPath: anyNamed('manifestPath'),
applicationKernelFilePath: anyNamed('applicationKernelFilePath'),
depfilePath: anyNamed('depfilePath'),
privateKeyPath: anyNamed('privateKeyPath'),
assetDirPath: anyNamed('assetDirPath'),
packagesPath: anyNamed('packagesPath'),
precompiledSnapshot: anyNamed('precompiledSnapshot'),
reportLicensedPackages: anyNamed('reportLicensedPackages'),
trackWidgetCreation: anyNamed('trackWidgetCreation'),
extraFrontEndOptions: anyNamed('extraFrontEndOptions'),
extraGenSnapshotOptions: anyNamed('extraGenSnapshotOptions'),
fileSystemRoots: anyNamed('fileSystemRoots'),
fileSystemScheme: anyNamed('fileSystemScheme'),
),
).thenAnswer((_) => Future<void>.value());
});
tearDown(() {
tryToDelete(tempDir);
});
Future<BuildBundleCommand> runCommandIn(String projectPath, { List<String> arguments }) async {
final BuildBundleCommand command = BuildBundleCommand(bundleBuilder: mockBundleBuilder);
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[
'bundle',
...?arguments,
'--target=$projectPath/lib/main.dart',
'--no-pub'
]);
return command;
}
testUsingContext('bundle getUsage indicate that project is a module', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);
final BuildBundleCommand command = await runCommandIn(projectPath);
expect(await command.usageValues,
containsPair(CustomDimensions.commandBuildBundleIsModule, 'true'));
});
testUsingContext('bundle getUsage indicate that project is not a module', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
final BuildBundleCommand command = await runCommandIn(projectPath);
expect(await command.usageValues,
containsPair(CustomDimensions.commandBuildBundleIsModule, 'false'));
});
testUsingContext('bundle getUsage indicate the target platform', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
final BuildBundleCommand command = await runCommandIn(projectPath);
expect(await command.usageValues,
containsPair(CustomDimensions.commandBuildBundleTargetPlatform, 'android-arm'));
});
testUsingContext('bundle fails to build for Windows if feature is disabled', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync(recursive: true);
fs.file('.packages').createSync(recursive: true);
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = MockBundleBuilder());
expect(() => runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=windows-x64',
]), throwsA(isInstanceOf<ToolExit>()));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: false),
});
testUsingContext('bundle fails to build for Linux if feature is disabled', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = MockBundleBuilder());
expect(() => runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=linux-x64',
]), throwsA(isInstanceOf<ToolExit>()));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
});
testUsingContext('bundle fails to build for macOS if feature is disabled', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = MockBundleBuilder());
expect(() => runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=darwin-x64',
]), throwsA(isInstanceOf<ToolExit>()));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false),
});
testUsingContext('bundle can build for Windows if feature is enabled', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = MockBundleBuilder());
await runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=windows-x64',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
});
testUsingContext('bundle can build for Linux if feature is enabled', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = MockBundleBuilder());
await runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=linux-x64',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
});
testUsingContext('bundle can build for macOS if feature is enabled', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand()
..bundleBuilder = MockBundleBuilder());
await runner.run(<String>[
'bundle',
'--no-pub',
'--target-platform=darwin-x64',
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
});
testUsingContext('passes track widget creation through', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
when(buildSystem.build(any, any)).thenAnswer((Invocation invocation) async {
final Environment environment = invocation.positionalArguments[1] as Environment;
expect(environment.defines, <String, String>{
kTargetFile: fs.path.join('lib', 'main.dart'),
kBuildMode: 'debug',
kTargetPlatform: 'android-arm',
kTrackWidgetCreation: 'true',
});
return BuildResult(success: true);
});
await runner.run(<String>[
'bundle',
'--no-pub',
'--debug',
'--target-platform=android-arm',
'--track-widget-creation'
]);
}, overrides: <Type, Generator>{
BuildSystem: () => MockBuildSystem(),
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => FakeProcessManager.any(),
});
}
class MockBundleBuilder extends Mock implements BundleBuilder {}
class MockBuildSystem extends Mock implements BuildSystem {}