Unverified Commit 43afac1e authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

Reduce usage of testUsingContext (#131078)

Part of https://github.com/flutter/flutter/issues/47161
parent f2ba0a2b
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
import 'package:pub_semver/pub_semver.dart'; import 'package:pub_semver/pub_semver.dart';
import 'base/logger.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'cmake_project.dart'; import 'cmake_project.dart';
import 'globals.dart' as globals;
/// Extracts the `BINARY_NAME` from a project's CMake file. /// Extracts the `BINARY_NAME` from a project's CMake file.
/// ///
...@@ -41,12 +41,12 @@ String _determineVersionString(CmakeBasedProject project, BuildInfo buildInfo) { ...@@ -41,12 +41,12 @@ String _determineVersionString(CmakeBasedProject project, BuildInfo buildInfo) {
: buildName; : buildName;
} }
Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo) { Version _determineVersion(CmakeBasedProject project, BuildInfo buildInfo, Logger logger) {
final String version = _determineVersionString(project, buildInfo); final String version = _determineVersionString(project, buildInfo);
try { try {
return Version.parse(version); return Version.parse(version);
} on FormatException { } on FormatException {
globals.printWarning('Warning: could not parse version $version, defaulting to 1.0.0.'); logger.printWarning('Warning: could not parse version $version, defaulting to 1.0.0.');
return Version(1, 0, 0); return Version(1, 0, 0);
} }
...@@ -74,25 +74,27 @@ void writeGeneratedCmakeConfig( ...@@ -74,25 +74,27 @@ void writeGeneratedCmakeConfig(
String flutterRoot, String flutterRoot,
CmakeBasedProject project, CmakeBasedProject project,
BuildInfo buildInfo, BuildInfo buildInfo,
Map<String, String> environment) { Map<String, String> environment,
Logger logger,
) {
// Only a limited set of variables are needed by the CMake files themselves, // Only a limited set of variables are needed by the CMake files themselves,
// the rest are put into a list to pass to the re-entrant build step. // the rest are put into a list to pass to the re-entrant build step.
final String escapedFlutterRoot = _escapeBackslashes(flutterRoot); final String escapedFlutterRoot = _escapeBackslashes(flutterRoot);
final String escapedProjectDir = _escapeBackslashes(project.parent.directory.path); final String escapedProjectDir = _escapeBackslashes(project.parent.directory.path);
final Version version = _determineVersion(project, buildInfo); final Version version = _determineVersion(project, buildInfo, logger);
final int? buildVersion = _tryDetermineBuildVersion(version); final int? buildVersion = _tryDetermineBuildVersion(version);
// Since complex Dart build identifiers cannot be converted into integers, // Since complex Dart build identifiers cannot be converted into integers,
// different Dart versions may be converted into the same Windows numeric version. // different Dart versions may be converted into the same Windows numeric version.
// Warn the user as some Windows installers, like MSI, don't update files if their versions are equal. // Warn the user as some Windows installers, like MSI, don't update files if their versions are equal.
if (buildVersion == null && project is WindowsProject) { if (buildVersion == null && project is WindowsProject) {
final String buildIdentifier = version.build.join('.'); final String buildIdentifier = version.build.join('.');
globals.printWarning( logger.printWarning(
'Warning: build identifier $buildIdentifier in version $version is not numeric ' 'Warning: build identifier $buildIdentifier in version $version is not numeric '
'and cannot be converted into a Windows build version number. Defaulting to 0.\n' 'and cannot be converted into a Windows build version number. Defaulting to 0.\n'
'This may cause issues with Windows installers.' 'This may cause issues with Windows installers.'
); );
} }
final StringBuffer buffer = StringBuffer(''' final StringBuffer buffer = StringBuffer('''
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import '../base/analyze_size.dart'; import '../base/analyze_size.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/logger.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
...@@ -83,18 +85,20 @@ class BuildLinuxCommand extends BuildSubCommand { ...@@ -83,18 +85,20 @@ class BuildLinuxCommand extends BuildSubCommand {
'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.'); 'Cross-build from Linux x64 host to Linux arm64 target is not currently supported.');
} }
displayNullSafetyMode(buildInfo); displayNullSafetyMode(buildInfo);
final Logger logger = globals.logger;
await buildLinux( await buildLinux(
flutterProject.linux, flutterProject.linux,
buildInfo, buildInfo,
target: targetFile, target: targetFile,
sizeAnalyzer: SizeAnalyzer( sizeAnalyzer: SizeAnalyzer(
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: logger,
flutterUsage: globals.flutterUsage, flutterUsage: globals.flutterUsage,
), ),
needCrossBuild: needCrossBuild, needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform, targetPlatform: targetPlatform,
targetSysroot: stringArg('target-sysroot')!, targetSysroot: stringArg('target-sysroot')!,
logger: logger,
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -29,12 +29,13 @@ final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:er ...@@ -29,12 +29,13 @@ final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:er
Future<void> buildLinux( Future<void> buildLinux(
LinuxProject linuxProject, LinuxProject linuxProject,
BuildInfo buildInfo, { BuildInfo buildInfo, {
String? target, String? target,
SizeAnalyzer? sizeAnalyzer, SizeAnalyzer? sizeAnalyzer,
bool needCrossBuild = false, bool needCrossBuild = false,
required TargetPlatform targetPlatform, required TargetPlatform targetPlatform,
String targetSysroot = '/', String targetSysroot = '/',
}) async { required Logger logger,
}) async {
target ??= 'lib/main.dart'; target ??= 'lib/main.dart';
if (!linuxProject.cmakeFile.existsSync()) { if (!linuxProject.cmakeFile.existsSync()) {
throwToolExit('No Linux desktop project configured. See ' throwToolExit('No Linux desktop project configured. See '
...@@ -43,7 +44,7 @@ Future<void> buildLinux( ...@@ -43,7 +44,7 @@ Future<void> buildLinux(
} }
final List<ProjectMigrator> migrators = <ProjectMigrator>[ final List<ProjectMigrator> migrators = <ProjectMigrator>[
CmakeCustomCommandMigration(linuxProject, globals.logger), CmakeCustomCommandMigration(linuxProject, logger),
]; ];
final ProjectMigration migration = ProjectMigration(migrators); final ProjectMigration migration = ProjectMigration(migrators);
...@@ -59,11 +60,11 @@ Future<void> buildLinux( ...@@ -59,11 +60,11 @@ Future<void> buildLinux(
environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); environmentConfig['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environmentConfig['LOCAL_ENGINE'] = localEngineInfo.localEngineName; environmentConfig['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
} }
writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig); writeGeneratedCmakeConfig(Cache.flutterRoot!, linuxProject, buildInfo, environmentConfig, logger);
createPluginSymlinks(linuxProject.parent); createPluginSymlinks(linuxProject.parent);
final Status status = globals.logger.startProgress( final Status status = logger.startProgress(
'Building Linux application...', 'Building Linux application...',
); );
try { try {
...@@ -97,13 +98,13 @@ Future<void> buildLinux( ...@@ -97,13 +98,13 @@ Future<void> buildLinux(
.childDirectory('.flutter-devtools'), 'linux-code-size-analysis', 'json', .childDirectory('.flutter-devtools'), 'linux-code-size-analysis', 'json',
)..writeAsStringSync(jsonEncode(output)); )..writeAsStringSync(jsonEncode(output));
// This message is used as a sentinel in analyze_apk_size_test.dart // This message is used as a sentinel in analyze_apk_size_test.dart
globals.printStatus( logger.printStatus(
'A summary of your Linux bundle analysis can be found at: ${outputFile.path}', 'A summary of your Linux bundle analysis can be found at: ${outputFile.path}',
); );
// DevTools expects a file path relative to the .flutter-devtools/ dir. // DevTools expects a file path relative to the .flutter-devtools/ dir.
final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim(); final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim();
globals.printStatus( logger.printStatus(
'\nTo analyze your app size in Dart DevTools, run the following command:\n' '\nTo analyze your app size in Dart DevTools, run the following command:\n'
'dart devtools --appSizeBase=$relativeAppSizePath' 'dart devtools --appSizeBase=$relativeAppSizePath'
); );
......
...@@ -25,6 +25,7 @@ class LinuxDevice extends DesktopDevice { ...@@ -25,6 +25,7 @@ class LinuxDevice extends DesktopDevice {
required FileSystem fileSystem, required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
}) : _operatingSystemUtils = operatingSystemUtils, }) : _operatingSystemUtils = operatingSystemUtils,
_logger = logger,
super( super(
'linux', 'linux',
platformType: PlatformType.linux, platformType: PlatformType.linux,
...@@ -36,6 +37,7 @@ class LinuxDevice extends DesktopDevice { ...@@ -36,6 +37,7 @@ class LinuxDevice extends DesktopDevice {
); );
final OperatingSystemUtils _operatingSystemUtils; final OperatingSystemUtils _operatingSystemUtils;
final Logger _logger;
@override @override
bool isSupported() => true; bool isSupported() => true;
...@@ -66,6 +68,7 @@ class LinuxDevice extends DesktopDevice { ...@@ -66,6 +68,7 @@ class LinuxDevice extends DesktopDevice {
buildInfo, buildInfo,
target: mainPath, target: mainPath,
targetPlatform: await targetPlatform, targetPlatform: await targetPlatform,
logger: _logger,
); );
} }
......
...@@ -54,7 +54,9 @@ class HotEvent extends UsageEvent { ...@@ -54,7 +54,9 @@ class HotEvent extends UsageEvent {
this.scannedSourcesCount, this.scannedSourcesCount,
this.reassembleTimeInMs, this.reassembleTimeInMs,
this.reloadVMTimeInMs, this.reloadVMTimeInMs,
}) : super('hot', parameter, flutterUsage: globals.flutterUsage); // TODO(fujino): make this required
Usage? usage,
}) : super('hot', parameter, flutterUsage: usage ?? globals.flutterUsage);
final String? reason; final String? reason;
final String targetPlatform; final String targetPlatform;
......
...@@ -950,6 +950,7 @@ class HotRunner extends ResidentRunner { ...@@ -950,6 +950,7 @@ class HotRunner extends ResidentRunner {
sdkName, sdkName,
emulator, emulator,
reason, reason,
globals.flutterUsage,
); );
if (result.code != 0) { if (result.code != 0) {
return result; return result;
...@@ -1172,6 +1173,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function( ...@@ -1172,6 +1173,7 @@ typedef ReloadSourcesHelper = Future<OperationResult> Function(
String? sdkName, String? sdkName,
bool? emulator, bool? emulator,
String? reason, String? reason,
Usage usage,
); );
@visibleForTesting @visibleForTesting
...@@ -1184,6 +1186,7 @@ Future<OperationResult> defaultReloadSourcesHelper( ...@@ -1184,6 +1186,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
String? sdkName, String? sdkName,
bool? emulator, bool? emulator,
String? reason, String? reason,
Usage usage,
) async { ) async {
final Stopwatch vmReloadTimer = Stopwatch()..start(); final Stopwatch vmReloadTimer = Stopwatch()..start();
const String entryPath = 'main.dart.incremental.dill'; const String entryPath = 'main.dart.incremental.dill';
...@@ -1223,6 +1226,7 @@ Future<OperationResult> defaultReloadSourcesHelper( ...@@ -1223,6 +1226,7 @@ Future<OperationResult> defaultReloadSourcesHelper(
fullRestart: false, fullRestart: false,
reason: reason, reason: reason,
fastReassemble: false, fastReassemble: false,
usage: usage,
).send(); ).send();
// Reset devFS lastCompileTime to ensure the file will still be marked // Reset devFS lastCompileTime to ensure the file will still be marked
// as dirty on subsequent reloads. // as dirty on subsequent reloads.
......
...@@ -242,7 +242,7 @@ void _writeGeneratedFlutterConfig( ...@@ -242,7 +242,7 @@ void _writeGeneratedFlutterConfig(
environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environment['LOCAL_ENGINE'] = localEngineInfo.localEngineName; environment['LOCAL_ENGINE'] = localEngineInfo.localEngineName;
} }
writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment); writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, buildInfo, environment, globals.logger);
} }
// Works around the Visual Studio 17.1.0 CMake bug described in // Works around the Visual Studio 17.1.0 CMake bug described in
......
...@@ -11,23 +11,20 @@ import 'package:flutter_tools/src/cmake.dart'; ...@@ -11,23 +11,20 @@ import 'package:flutter_tools/src/cmake.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart';
const String _kTestFlutterRoot = '/flutter'; const String _kTestFlutterRoot = '/flutter';
const String _kTestWindowsFlutterRoot = r'C:\flutter'; const String _kTestWindowsFlutterRoot = r'C:\flutter';
void main() { void main() {
late FileSystem fileSystem; late FileSystem fileSystem;
late ProcessManager processManager;
late BufferLogger logger; late BufferLogger logger;
setUp(() { setUp(() {
processManager = FakeProcessManager.any();
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
logger = BufferLogger.test(); logger = BufferLogger.test();
}); });
testUsingContext('parses executable name from cmake file', () async { testWithoutContext('parses executable name from cmake file', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
...@@ -38,24 +35,18 @@ void main() { ...@@ -38,24 +35,18 @@ void main() {
final String? name = getCmakeExecutableName(cmakeProject); final String? name = getCmakeExecutableName(cmakeProject);
expect(name, 'hello'); expect(name, 'hello');
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('defaults executable name to null if cmake config does not exist', () async { testWithoutContext('defaults executable name to null if cmake config does not exist', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
final String? name = getCmakeExecutableName(cmakeProject); final String? name = getCmakeExecutableName(cmakeProject);
expect(name, isNull); expect(name, isNull);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generates config', () async { testWithoutContext('generates config', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, treeShakeIcons: false); const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, treeShakeIcons: false);
...@@ -66,6 +57,7 @@ void main() { ...@@ -66,6 +57,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -91,12 +83,9 @@ void main() { ...@@ -91,12 +83,9 @@ void main() {
r' "PROJECT_DIR=/"', r' "PROJECT_DIR=/"',
r')', r')',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('config escapes backslashes', () async { testWithoutContext('config escapes backslashes', () async {
fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
...@@ -112,6 +101,7 @@ void main() { ...@@ -112,6 +101,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -138,12 +128,9 @@ void main() { ...@@ -138,12 +128,9 @@ void main() {
r' "TEST=hello\\world"', r' "TEST=hello\\world"',
r')', r')',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses pubspec version', () async { testWithoutContext('generated config uses pubspec version', () async {
fileSystem.file('pubspec.yaml') fileSystem.file('pubspec.yaml')
..createSync() ..createSync()
..writeAsStringSync('version: 1.2.3+4'); ..writeAsStringSync('version: 1.2.3+4');
...@@ -158,6 +145,7 @@ void main() { ...@@ -158,6 +145,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -173,12 +161,9 @@ void main() { ...@@ -173,12 +161,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses build name', () async { testWithoutContext('generated config uses build name', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -194,6 +179,7 @@ void main() { ...@@ -194,6 +179,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -209,12 +195,9 @@ void main() { ...@@ -209,12 +195,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses build number', () async { testWithoutContext('generated config uses build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -230,6 +213,7 @@ void main() { ...@@ -230,6 +213,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -245,12 +229,9 @@ void main() { ...@@ -245,12 +229,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 0 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses build name and build number', () async { testWithoutContext('generated config uses build name and build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -267,6 +248,7 @@ void main() { ...@@ -267,6 +248,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -282,12 +264,9 @@ void main() { ...@@ -282,12 +264,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses build name over pubspec version', () async { testWithoutContext('generated config uses build name over pubspec version', () async {
fileSystem.file('pubspec.yaml') fileSystem.file('pubspec.yaml')
..createSync() ..createSync()
..writeAsStringSync('version: 9.9.9+9'); ..writeAsStringSync('version: 9.9.9+9');
...@@ -307,6 +286,7 @@ void main() { ...@@ -307,6 +286,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -322,12 +302,9 @@ void main() { ...@@ -322,12 +302,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses build number over pubspec version', () async { testWithoutContext('generated config uses build number over pubspec version', () async {
fileSystem.file('pubspec.yaml') fileSystem.file('pubspec.yaml')
..createSync() ..createSync()
..writeAsStringSync('version: 1.2.3+4'); ..writeAsStringSync('version: 1.2.3+4');
...@@ -347,6 +324,7 @@ void main() { ...@@ -347,6 +324,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -362,12 +340,9 @@ void main() { ...@@ -362,12 +340,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 5 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 5 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config uses build name and build number over pubspec version', () async { testWithoutContext('generated config uses build name and build number over pubspec version', () async {
fileSystem.file('pubspec.yaml') fileSystem.file('pubspec.yaml')
..createSync() ..createSync()
..writeAsStringSync('version: 9.9.9+9'); ..writeAsStringSync('version: 9.9.9+9');
...@@ -388,6 +363,7 @@ void main() { ...@@ -388,6 +363,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -403,12 +379,9 @@ void main() { ...@@ -403,12 +379,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 4 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
}); });
testUsingContext('generated config ignores invalid build name', () async { testWithoutContext('generated config ignores invalid build name', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -424,6 +397,7 @@ void main() { ...@@ -424,6 +397,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -441,13 +415,9 @@ void main() { ...@@ -441,13 +415,9 @@ void main() {
])); ]));
expect(logger.warningText, contains('Warning: could not parse version hello.world, defaulting to 1.0.0.')); expect(logger.warningText, contains('Warning: could not parse version hello.world, defaulting to 1.0.0.'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Logger: () => logger,
}); });
testUsingContext('generated config ignores invalid build number', () async { testWithoutContext('generated config ignores invalid build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -464,6 +434,7 @@ void main() { ...@@ -464,6 +434,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
final File cmakeConfig = cmakeProject.generatedCmakeConfigFile; final File cmakeConfig = cmakeProject.generatedCmakeConfigFile;
...@@ -481,13 +452,9 @@ void main() { ...@@ -481,13 +452,9 @@ void main() {
])); ]));
expect(logger.warningText, contains('Warning: could not parse version 1.2.3+foo_bar, defaulting to 1.0.0.')); expect(logger.warningText, contains('Warning: could not parse version 1.2.3+foo_bar, defaulting to 1.0.0.'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Logger: () => logger,
}); });
testUsingContext('generated config handles non-numeric build number', () async { testWithoutContext('generated config handles non-numeric build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -504,6 +471,7 @@ void main() { ...@@ -504,6 +471,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
expect(logger.warningText, isEmpty); expect(logger.warningText, isEmpty);
...@@ -521,13 +489,9 @@ void main() { ...@@ -521,13 +489,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Logger: () => logger,
}); });
testUsingContext('generated config handles complex build number', () async { testWithoutContext('generated config handles complex build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project); final CmakeBasedProject cmakeProject = _FakeProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -544,6 +508,7 @@ void main() { ...@@ -544,6 +508,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
expect(logger.warningText, isEmpty); expect(logger.warningText, isEmpty);
...@@ -561,13 +526,9 @@ void main() { ...@@ -561,13 +526,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Logger: () => logger,
}); });
testUsingContext('generated config warns on Windows project with non-numeric build number', () async { testWithoutContext('generated config warns on Windows project with non-numeric build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = WindowsProject.fromFlutter(project); final CmakeBasedProject cmakeProject = WindowsProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -584,6 +545,7 @@ void main() { ...@@ -584,6 +545,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
expect(logger.warningText, contains( expect(logger.warningText, contains(
...@@ -605,13 +567,9 @@ void main() { ...@@ -605,13 +567,9 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Logger: () => logger,
}); });
testUsingContext('generated config warns on Windows project with complex build number', () async { testWithoutContext('generated config warns on Windows project with complex build number', () async {
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory); final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final CmakeBasedProject cmakeProject = WindowsProject.fromFlutter(project); final CmakeBasedProject cmakeProject = WindowsProject.fromFlutter(project);
const BuildInfo buildInfo = BuildInfo( const BuildInfo buildInfo = BuildInfo(
...@@ -628,6 +586,7 @@ void main() { ...@@ -628,6 +586,7 @@ void main() {
cmakeProject, cmakeProject,
buildInfo, buildInfo,
environment, environment,
logger,
); );
expect(logger.warningText, contains( expect(logger.warningText, contains(
...@@ -649,10 +608,6 @@ void main() { ...@@ -649,10 +608,6 @@ void main() {
'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)', 'set(FLUTTER_VERSION_PATCH 3 PARENT_SCOPE)',
'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)', 'set(FLUTTER_VERSION_BUILD 0 PARENT_SCOPE)',
])); ]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Logger: () => logger,
}); });
} }
......
...@@ -366,6 +366,7 @@ void main() { ...@@ -366,6 +366,7 @@ void main() {
String? sdkName, String? sdkName,
bool? emulator, bool? emulator,
String? reason, String? reason,
Usage usage,
) async { ) async {
firstReloadDetails['finalLibraryCount'] = 2; firstReloadDetails['finalLibraryCount'] = 2;
firstReloadDetails['receivedLibraryCount'] = 3; firstReloadDetails['receivedLibraryCount'] = 3;
......
...@@ -3,16 +3,18 @@ ...@@ -3,16 +3,18 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/resident_runner.dart'; import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart'; import 'package:flutter_tools/src/run_hot.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:test/fake.dart'; import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
import '../src/context.dart'; //import '../src/context.dart';
import '../src/common.dart';
void main() { void main() {
testUsingContext('defaultReloadSourcesHelper() handles empty DeviceReloadReports)', () { testWithoutContext('defaultReloadSourcesHelper() handles empty DeviceReloadReports)', () {
defaultReloadSourcesHelper( defaultReloadSourcesHelper(
_FakeHotRunner(), _FakeHotRunner(),
<FlutterDevice?>[_FakeFlutterDevice()], <FlutterDevice?>[_FakeFlutterDevice()],
...@@ -22,6 +24,7 @@ void main() { ...@@ -22,6 +24,7 @@ void main() {
'flutter-sdk', 'flutter-sdk',
false, false,
'test-reason', 'test-reason',
TestUsage(),
); );
}); });
} }
......
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