Unverified Commit 613a9598 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

only use code single path for verification of target file existence (#70962)

parent ffe5197e
...@@ -211,6 +211,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. ...@@ -211,6 +211,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
Future<void> _attachToDevice(Device device) async { Future<void> _attachToDevice(Device device) async {
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
Future<int> getDevicePort() async { Future<int> getDevicePort() async {
if (debugPort != null) { if (debugPort != null) {
return debugPort; return debugPort;
...@@ -388,7 +389,7 @@ known, it can be explicitly provided to attach via the command-line, e.g. ...@@ -388,7 +389,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
device, device,
fileSystemRoots: stringsArg('filesystem-root'), fileSystemRoots: stringsArg('filesystem-root'),
fileSystemScheme: stringArg('filesystem-scheme'), fileSystemScheme: stringArg('filesystem-scheme'),
target: stringArg('target'), target: targetFile,
targetModel: TargetModel(stringArg('target-model')), targetModel: TargetModel(stringArg('target-model')),
buildInfo: buildInfo, buildInfo: buildInfo,
userIdentifier: userIdentifier, userIdentifier: userIdentifier,
......
...@@ -447,6 +447,7 @@ class RunCommand extends RunCommandBase { ...@@ -447,6 +447,7 @@ class RunCommand extends RunCommandBase {
// debug mode. // debug mode.
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
final bool hotMode = shouldUseHotMode(buildInfo); final bool hotMode = shouldUseHotMode(buildInfo);
final String applicationBinaryPath = stringArg('use-application-binary');
writePidFile(stringArg('pid-file')); writePidFile(stringArg('pid-file'));
...@@ -464,7 +465,6 @@ class RunCommand extends RunCommandBase { ...@@ -464,7 +465,6 @@ class RunCommand extends RunCommandBase {
); );
AppInstance app; AppInstance app;
try { try {
final String applicationBinaryPath = stringArg('use-application-binary');
app = await daemon.appDomain.startApp( app = await daemon.appDomain.startApp(
devices.first, globals.fs.currentDirectory.path, targetFile, route, devices.first, globals.fs.currentDirectory.path, targetFile, route,
await createDebuggingOptions(), hotMode, await createDebuggingOptions(), hotMode,
...@@ -535,7 +535,7 @@ class RunCommand extends RunCommandBase { ...@@ -535,7 +535,7 @@ class RunCommand extends RunCommandBase {
fileSystemRoots: stringsArg('filesystem-root'), fileSystemRoots: stringsArg('filesystem-root'),
fileSystemScheme: stringArg('filesystem-scheme'), fileSystemScheme: stringArg('filesystem-scheme'),
experimentalFlags: expFlags, experimentalFlags: expFlags,
target: stringArg('target'), target: targetFile,
buildInfo: buildInfo, buildInfo: buildInfo,
userIdentifier: userIdentifier, userIdentifier: userIdentifier,
platform: globals.platform, platform: globals.platform,
...@@ -548,7 +548,6 @@ class RunCommand extends RunCommandBase { ...@@ -548,7 +548,6 @@ class RunCommand extends RunCommandBase {
await devices.single.targetPlatform == TargetPlatform.web_javascript; await devices.single.targetPlatform == TargetPlatform.web_javascript;
ResidentRunner runner; ResidentRunner runner;
final String applicationBinaryPath = stringArg('use-application-binary');
if (hotMode && !webMode) { if (hotMode && !webMode) {
runner = HotRunner( runner = HotRunner(
flutterDevices, flutterDevices,
......
...@@ -468,16 +468,6 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -468,16 +468,6 @@ class _ResidentWebRunner extends ResidentWebRunner {
globals.printStatus('This application is not configured to build on the web.'); globals.printStatus('This application is not configured to build on the web.');
globals.printStatus('To add web support to a project, run `flutter create .`.'); globals.printStatus('To add web support to a project, run `flutter create .`.');
} }
if (!globals.fs.isFileSync(mainPath)) {
String message = 'Tried to run $mainPath, but that file does not exist.';
if (target == null) {
message +=
'\nConsider using the -t option to specify the Dart file to start.';
}
globals.printError(message);
appFailedToStart();
return 1;
}
final String modeName = debuggingOptions.buildInfo.friendlyModeName; final String modeName = debuggingOptions.buildInfo.friendlyModeName;
globals.printStatus( globals.printStatus(
'Launching ${globals.fsUtils.getDisplayPath(target)} ' 'Launching ${globals.fsUtils.getDisplayPath(target)} '
......
...@@ -712,7 +712,7 @@ class FlutterDevice { ...@@ -712,7 +712,7 @@ class FlutterDevice {
abstract class ResidentRunner { abstract class ResidentRunner {
ResidentRunner( ResidentRunner(
this.flutterDevices, { this.flutterDevices, {
this.target, @required this.target,
@required this.debuggingOptions, @required this.debuggingOptions,
String projectRootPath, String projectRootPath,
this.ipv6, this.ipv6,
...@@ -720,7 +720,7 @@ abstract class ResidentRunner { ...@@ -720,7 +720,7 @@ abstract class ResidentRunner {
this.hotMode = true, this.hotMode = true,
String dillOutputPath, String dillOutputPath,
this.machine = false, this.machine = false,
}) : mainPath = findMainDartFile(target), }) : mainPath = globals.fs.path.absolute(target),
packagesFilePath = debuggingOptions.buildInfo.packagesPath, packagesFilePath = debuggingOptions.buildInfo.packagesPath,
projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path, projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path,
_dillOutputPath = dillOutputPath, _dillOutputPath = dillOutputPath,
...@@ -1367,17 +1367,6 @@ class OperationResult { ...@@ -1367,17 +1367,6 @@ class OperationResult {
static final OperationResult ok = OperationResult(0, ''); static final OperationResult ok = OperationResult(0, '');
} }
/// Given the value of the --target option, return the path of the Dart file
/// where the app's main function should be.
String findMainDartFile([ String target ]) {
target ??= '';
final String targetPath = globals.fs.path.absolute(target);
if (globals.fs.isDirectorySync(targetPath)) {
return globals.fs.path.join(targetPath, 'lib', 'main.dart');
}
return targetPath;
}
Future<String> getMissingPackageHintForPlatform(TargetPlatform platform) async { Future<String> getMissingPackageHintForPlatform(TargetPlatform platform) async {
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
......
...@@ -17,7 +17,7 @@ import 'vmservice.dart'; ...@@ -17,7 +17,7 @@ import 'vmservice.dart';
class ColdRunner extends ResidentRunner { class ColdRunner extends ResidentRunner {
ColdRunner( ColdRunner(
List<FlutterDevice> devices, { List<FlutterDevice> devices, {
String target, @required String target,
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
this.traceStartup = false, this.traceStartup = false,
this.awaitFirstFrameWhenTracing = true, this.awaitFirstFrameWhenTracing = true,
...@@ -52,18 +52,6 @@ class ColdRunner extends ResidentRunner { ...@@ -52,18 +52,6 @@ class ColdRunner extends ResidentRunner {
Completer<void> appStartedCompleter, Completer<void> appStartedCompleter,
String route, String route,
}) async { }) async {
final bool prebuiltMode = applicationBinary != null;
if (!prebuiltMode) {
if (!globals.fs.isFileSync(mainPath)) {
String message = 'Tried to run $mainPath, but that file does not exist.';
if (target == null) {
message += '\nConsider using the -t option to specify the Dart file to start.';
}
globals.printError(message);
return 1;
}
}
try { try {
for (final FlutterDevice device in flutterDevices) { for (final FlutterDevice device in flutterDevices) {
final int result = await device.runCold( final int result = await device.runCold(
......
...@@ -66,7 +66,7 @@ class DeviceReloadReport { ...@@ -66,7 +66,7 @@ class DeviceReloadReport {
class HotRunner extends ResidentRunner { class HotRunner extends ResidentRunner {
HotRunner( HotRunner(
List<FlutterDevice> devices, { List<FlutterDevice> devices, {
String target, @required String target,
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
this.benchmarkMode = false, this.benchmarkMode = false,
this.applicationBinary, this.applicationBinary,
...@@ -295,15 +295,6 @@ class HotRunner extends ResidentRunner { ...@@ -295,15 +295,6 @@ class HotRunner extends ResidentRunner {
Completer<void> appStartedCompleter, Completer<void> appStartedCompleter,
String route, String route,
}) async { }) async {
if (!globals.fs.isFileSync(mainPath)) {
String message = 'Tried to run $mainPath, but that file does not exist.';
if (target == null) {
message += '\nConsider using the -t option to specify the Dart file to start.';
}
globals.printError(message);
return 1;
}
firstBuildTime = DateTime.now(); firstBuildTime = DateTime.now();
final List<Future<bool>> startupTasks = <Future<bool>>[]; final List<Future<bool>> startupTasks = <Future<bool>>[];
......
...@@ -39,6 +39,7 @@ void main() { ...@@ -39,6 +39,7 @@ void main() {
final int exitCode = await ColdRunner(devices, final int exitCode = await ColdRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
).attach(); ).attach();
expect(exitCode, 2); expect(exitCode, 2);
}); });
...@@ -61,6 +62,7 @@ void main() { ...@@ -61,6 +62,7 @@ void main() {
await ColdRunner(devices, await ColdRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
).cleanupAtFinish(); ).cleanupAtFinish();
verify(mockDevice1.dispose()); verify(mockDevice1.dispose());
...@@ -71,21 +73,6 @@ void main() { ...@@ -71,21 +73,6 @@ void main() {
}); });
group('cold run', () { group('cold run', () {
testUsingContext('returns 1 if not prebuilt mode & mainPath does not exist', () async {
final MockDevice mockDevice = MockDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.device).thenReturn(mockDevice);
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final int result = await ColdRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
).run();
expect(result, 1);
expect(testLogger.errorText, matches(r'Tried to run .*, but that file does not exist\.'));
expect(testLogger.errorText, matches(r'Consider using the -t option to specify the Dart file to start\.'));
});
testUsingContext('calls runCold on attached device', () async { testUsingContext('calls runCold on attached device', () async {
final MockDevice mockDevice = MockDevice(); final MockDevice mockDevice = MockDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice(); final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
...@@ -100,6 +87,7 @@ void main() { ...@@ -100,6 +87,7 @@ void main() {
devices, devices,
applicationBinary: applicationBinary, applicationBinary: applicationBinary,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
).run(); ).run();
expect(result, 1); expect(result, 1);
......
...@@ -184,6 +184,7 @@ void main() { ...@@ -184,6 +184,7 @@ void main() {
final OperationResult result = await HotRunner( final OperationResult result = await HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
).restart(fullRestart: true); ).restart(fullRestart: true);
// Expect hot restart failed. // Expect hot restart failed.
expect(result.isOk, false); expect(result.isOk, false);
...@@ -214,7 +215,8 @@ void main() { ...@@ -214,7 +215,8 @@ void main() {
]; ];
final OperationResult result = await HotRunner( final OperationResult result = await HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug) debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
).restart(fullRestart: true); ).restart(fullRestart: true);
// Expect hot restart failed. // Expect hot restart failed.
expect(result.isOk, false); expect(result.isOk, false);
...@@ -317,6 +319,7 @@ void main() { ...@@ -317,6 +319,7 @@ void main() {
final HotRunner hotRunner = HotRunner( final HotRunner hotRunner = HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
); );
final OperationResult result = await hotRunner.restart(fullRestart: true); final OperationResult result = await hotRunner.restart(fullRestart: true);
// Expect hot restart was successful. // Expect hot restart was successful.
...@@ -345,6 +348,7 @@ void main() { ...@@ -345,6 +348,7 @@ void main() {
final OperationResult result = await HotRunner( final OperationResult result = await HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
).restart(fullRestart: true); ).restart(fullRestart: true);
expect(result.isOk, false); expect(result.isOk, false);
expect(result.message, 'setupHotRestart failed'); expect(result.message, 'setupHotRestart failed');
...@@ -410,6 +414,7 @@ void main() { ...@@ -410,6 +414,7 @@ void main() {
final HotRunner hotRunner = HotRunner( final HotRunner hotRunner = HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
); );
final OperationResult result = await hotRunner.restart(fullRestart: true); final OperationResult result = await hotRunner.restart(fullRestart: true);
// Expect hot restart successful. // Expect hot restart successful.
...@@ -446,7 +451,8 @@ void main() { ...@@ -446,7 +451,8 @@ void main() {
]; ];
await HotRunner( await HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug) debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
).cleanupAfterSignal(); ).cleanupAfterSignal();
expect(shutdownTestingConfig.shutdownHookCalled, true); expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -470,7 +476,8 @@ void main() { ...@@ -470,7 +476,8 @@ void main() {
]; ];
await HotRunner( await HotRunner(
devices, devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug) debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
).preExit(); ).preExit();
expect(shutdownTestingConfig.shutdownHookCalled, true); expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -514,6 +521,7 @@ void main() { ...@@ -514,6 +521,7 @@ void main() {
final int exitCode = await HotRunner(devices, final int exitCode = await HotRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
).attach(); ).attach();
expect(exitCode, 2); expect(exitCode, 2);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -546,6 +554,7 @@ void main() { ...@@ -546,6 +554,7 @@ void main() {
await HotRunner(devices, await HotRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
).cleanupAtFinish(); ).cleanupAtFinish();
verify(mockDevice1.dispose()); verify(mockDevice1.dispose());
......
...@@ -151,6 +151,7 @@ void main() { ...@@ -151,6 +151,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
}); });
mockFlutterDevice = MockFlutterDevice(); mockFlutterDevice = MockFlutterDevice();
...@@ -244,6 +245,7 @@ void main() { ...@@ -244,6 +245,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
when(mockFlutterDevice.generator).thenReturn(residentCompiler); when(mockFlutterDevice.generator).thenReturn(residentCompiler);
when(residentCompiler.recompile( when(residentCompiler.recompile(
...@@ -285,6 +287,7 @@ void main() { ...@@ -285,6 +287,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
when(mockFlutterDevice.generator).thenReturn(residentCompiler); when(mockFlutterDevice.generator).thenReturn(residentCompiler);
when(residentCompiler.recompile( when(residentCompiler.recompile(
...@@ -319,6 +322,7 @@ void main() { ...@@ -319,6 +322,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.release), debuggingOptions: DebuggingOptions.enabled(BuildInfo.release),
target: 'main.dart',
); );
when(mockFlutterDevice.runCold( when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'), coldRunner: anyNamed('coldRunner'),
...@@ -343,6 +347,7 @@ void main() { ...@@ -343,6 +347,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.release), debuggingOptions: DebuggingOptions.enabled(BuildInfo.release),
target: 'main.dart',
); );
when(mockFlutterDevice.runCold( when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'), coldRunner: anyNamed('coldRunner'),
...@@ -372,6 +377,7 @@ void main() { ...@@ -372,6 +377,7 @@ void main() {
applicationBinary: globals.fs.file('app.apk'), applicationBinary: globals.fs.file('app.apk'),
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
when(mockFlutterDevice.generator).thenReturn(residentCompiler); when(mockFlutterDevice.generator).thenReturn(residentCompiler);
when(residentCompiler.recompile( when(residentCompiler.recompile(
...@@ -461,6 +467,7 @@ void main() { ...@@ -461,6 +467,7 @@ void main() {
fastStart: true, fastStart: true,
startPaused: true, startPaused: true,
), ),
target: 'main.dart',
); );
final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync(); final Completer<DebugConnectionInfo> onConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> onAppStart = Completer<void>.sync(); final Completer<void> onAppStart = Completer<void>.sync();
...@@ -599,6 +606,7 @@ void main() { ...@@ -599,6 +606,7 @@ void main() {
mockFlutterDevice, mockFlutterDevice,
], ],
stayResident: false, stayResident: false,
target: 'main.dart',
debuggingOptions: DebuggingOptions.enabled(const BuildInfo( debuggingOptions: DebuggingOptions.enabled(const BuildInfo(
BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: <String>[ BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: <String>[
'--enable-experiment=non-nullable', '--enable-experiment=non-nullable',
...@@ -677,6 +685,7 @@ void main() { ...@@ -677,6 +685,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async { when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example'; return 'Example';
...@@ -1017,6 +1026,7 @@ void main() { ...@@ -1017,6 +1026,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async { when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async {
return 'Example'; return 'Example';
...@@ -1416,6 +1426,7 @@ void main() { ...@@ -1416,6 +1426,7 @@ void main() {
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
dillOutputPath: globals.fs.path.join('foobar', 'app.dill'), dillOutputPath: globals.fs.path.join('foobar', 'app.dill'),
target: 'main.dart',
); );
expect(otherRunner.artifactDirectory.path, contains('foobar')); expect(otherRunner.artifactDirectory.path, contains('foobar'));
})); }));
...@@ -1526,6 +1537,7 @@ void main() { ...@@ -1526,6 +1537,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
residentRunner.printHelp(details: true); residentRunner.printHelp(details: true);
...@@ -1663,6 +1675,7 @@ void main() { ...@@ -1663,6 +1675,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
await residentRunner.screenshot(mockFlutterDevice); await residentRunner.screenshot(mockFlutterDevice);
...@@ -1769,6 +1782,7 @@ void main() { ...@@ -1769,6 +1782,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
when(mockDevice.supportsScreenshot).thenReturn(true); when(mockDevice.supportsScreenshot).thenReturn(true);
when(mockDevice.takeScreenshot(any)) when(mockDevice.takeScreenshot(any))
...@@ -1917,6 +1931,7 @@ void main() { ...@@ -1917,6 +1931,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugDumpApp(), false); expect(await residentRunner.debugDumpApp(), false);
...@@ -1938,6 +1953,7 @@ void main() { ...@@ -1938,6 +1953,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugDumpRenderTree(), false); expect(await residentRunner.debugDumpRenderTree(), false);
...@@ -1959,6 +1975,7 @@ void main() { ...@@ -1959,6 +1975,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugDumpLayerTree(), false); expect(await residentRunner.debugDumpLayerTree(), false);
...@@ -1980,6 +1997,7 @@ void main() { ...@@ -1980,6 +1997,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugDumpSemanticsTreeInTraversalOrder(), false); expect(await residentRunner.debugDumpSemanticsTreeInTraversalOrder(), false);
...@@ -2001,6 +2019,7 @@ void main() { ...@@ -2001,6 +2019,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugDumpSemanticsTreeInInverseHitTestOrder(), false); expect(await residentRunner.debugDumpSemanticsTreeInInverseHitTestOrder(), false);
...@@ -2022,6 +2041,7 @@ void main() { ...@@ -2022,6 +2041,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleDebugPaintSizeEnabled(), false); expect(await residentRunner.debugToggleDebugPaintSizeEnabled(), false);
...@@ -2043,6 +2063,7 @@ void main() { ...@@ -2043,6 +2063,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleBrightness(), false); expect(await residentRunner.debugToggleBrightness(), false);
...@@ -2087,6 +2108,7 @@ void main() { ...@@ -2087,6 +2108,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleInvertOversizedImages(), false); expect(await residentRunner.debugToggleInvertOversizedImages(), false);
...@@ -2101,6 +2123,7 @@ void main() { ...@@ -2101,6 +2123,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile), debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleInvertOversizedImages(), false); expect(await residentRunner.debugToggleInvertOversizedImages(), false);
...@@ -2145,6 +2168,7 @@ void main() { ...@@ -2145,6 +2168,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleDebugCheckElevationsEnabled(), false); expect(await residentRunner.debugToggleDebugCheckElevationsEnabled(), false);
...@@ -2166,6 +2190,7 @@ void main() { ...@@ -2166,6 +2190,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugTogglePerformanceOverlayOverride(), false); expect(await residentRunner.debugTogglePerformanceOverlayOverride(), false);
...@@ -2188,6 +2213,7 @@ void main() { ...@@ -2188,6 +2213,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleWidgetInspector(), false); expect(await residentRunner.debugToggleWidgetInspector(), false);
...@@ -2209,6 +2235,7 @@ void main() { ...@@ -2209,6 +2235,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
target: 'main.dart',
); );
expect(await residentRunner.debugToggleProfileWidgetBuilds(), false); expect(await residentRunner.debugToggleProfileWidgetBuilds(), false);
...@@ -2229,6 +2256,7 @@ void main() { ...@@ -2229,6 +2256,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
target: 'main.dart',
); );
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
hotRunner: anyNamed('hotRunner'), hotRunner: anyNamed('hotRunner'),
...@@ -2255,6 +2283,7 @@ void main() { ...@@ -2255,6 +2283,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
...@@ -2289,6 +2318,7 @@ void main() { ...@@ -2289,6 +2318,7 @@ void main() {
dartDefines: <String>['a', 'b'], dartDefines: <String>['a', 'b'],
) )
), ),
target: 'main.dart',
); );
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
...@@ -2324,6 +2354,7 @@ void main() { ...@@ -2324,6 +2354,7 @@ void main() {
extraFrontEndOptions: <String>['--enable-experiment=non-nullable>'] extraFrontEndOptions: <String>['--enable-experiment=non-nullable>']
) )
), ),
target: 'main.dart',
); );
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
...@@ -2353,6 +2384,7 @@ void main() { ...@@ -2353,6 +2384,7 @@ void main() {
stayResident: false, stayResident: false,
dillOutputPath: 'test', dillOutputPath: 'test',
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
...@@ -2385,6 +2417,7 @@ void main() { ...@@ -2385,6 +2417,7 @@ void main() {
treeShakeIcons: false, treeShakeIcons: false,
trackWidgetCreation: true, trackWidgetCreation: true,
)), )),
target: 'main.dart',
); );
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
...@@ -2413,6 +2446,7 @@ void main() { ...@@ -2413,6 +2446,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
); );
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
hotRunner: anyNamed('hotRunner'), hotRunner: anyNamed('hotRunner'),
...@@ -2443,6 +2477,7 @@ void main() { ...@@ -2443,6 +2477,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'),
target: 'main.dart',
); );
when(mockFlutterDevice.runHot( when(mockFlutterDevice.runHot(
hotRunner: anyNamed('hotRunner'), hotRunner: anyNamed('hotRunner'),
...@@ -2471,6 +2506,7 @@ void main() { ...@@ -2471,6 +2506,7 @@ void main() {
], ],
stayResident: false, stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'), debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'),
target: 'main.dart',
); );
when(mockFlutterDevice.runCold( when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'), coldRunner: anyNamed('coldRunner'),
......
...@@ -248,33 +248,6 @@ void main() { ...@@ -248,33 +248,6 @@ void main() {
Platform: () => FakePlatform(operatingSystem: 'linux', environment: <String, String>{}), Platform: () => FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
}); });
testUsingContext('Exits on run if target file does not exist', () async {
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
final ResidentRunner residentWebRunner = DwdsWebRunnerFactory().createWebRunner(
mockFlutterDevice,
flutterProject: FlutterProject.current(),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true,
stayResident: true,
urlTunneller: null,
) as ResidentWebRunner;
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file(fileSystem.path.join('web', 'index.html'))
.createSync(recursive: true);
expect(await residentWebRunner.run(), 1);
final String absoluteMain = fileSystem.path.absolute(fileSystem.path.join('lib', 'main.dart'));
expect(testLogger.errorText, contains('Tried to run $absoluteMain, but that file does not exist.'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
Pub: () => MockPub(),
Platform: () => FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
});
testUsingContext('Can successfully run and connect to vmservice', () async { testUsingContext('Can successfully run and connect to vmservice', () async {
fileSystem.file('.packages') fileSystem.file('.packages')
..createSync(recursive: true) ..createSync(recursive: true)
......
...@@ -6,8 +6,10 @@ import 'dart:async'; ...@@ -6,8 +6,10 @@ import 'dart:async';
import 'dart:io' as io; import 'dart:io' as io;
import 'package:args/command_runner.dart'; 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/common.dart';
import 'package:flutter_tools/src/base/error_handling_io.dart'; import 'package:flutter_tools/src/base/error_handling_io.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/signals.dart'; import 'package:flutter_tools/src/base/signals.dart';
import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/time.dart';
...@@ -106,6 +108,40 @@ void main() { ...@@ -106,6 +108,40 @@ void main() {
await flutterCommand.run(); await flutterCommand.run();
}); });
testUsingContext('finds the target file with default values', () async {
globals.fs.file('lib/main.dart').createSync(recursive: true);
final FakeTargetCommand fakeTargetCommand = FakeTargetCommand();
final CommandRunner<void> runner = createTestCommandRunner(fakeTargetCommand);
await runner.run(<String>['test']);
expect(fakeTargetCommand.cachedTargetFile, 'lib/main.dart');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('finds the target file with specified value', () async {
globals.fs.file('lib/foo.dart').createSync(recursive: true);
final FakeTargetCommand fakeTargetCommand = FakeTargetCommand();
final CommandRunner<void> runner = createTestCommandRunner(fakeTargetCommand);
await runner.run(<String>['test', '-t', 'lib/foo.dart']);
expect(fakeTargetCommand.cachedTargetFile, 'lib/foo.dart');
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('throws tool exit if specified file does not exist', () async {
final FakeTargetCommand fakeTargetCommand = FakeTargetCommand();
final CommandRunner<void> runner = createTestCommandRunner(fakeTargetCommand);
expect(() async => await runner.run(<String>['test', '-t', 'lib/foo.dart']), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
void testUsingCommandContext(String testName, dynamic Function() testBody) { void testUsingCommandContext(String testName, dynamic Function() testBody) {
testUsingContext(testName, testBody, overrides: <Type, Generator>{ testUsingContext(testName, testBody, overrides: <Type, Generator>{
ProcessInfo: () => mockProcessInfo, ProcessInfo: () => mockProcessInfo,
...@@ -485,6 +521,26 @@ class FakeNullSafeCommand extends FlutterCommand { ...@@ -485,6 +521,26 @@ class FakeNullSafeCommand extends FlutterCommand {
} }
} }
class FakeTargetCommand extends FlutterCommand {
FakeTargetCommand() {
usesTargetOption();
}
@override
Future<FlutterCommandResult> runCommand() async {
cachedTargetFile = targetFile;
return FlutterCommandResult.success();
}
String cachedTargetFile;
@override
String get description => '';
@override
String get name => 'test';
}
class MockVersion extends Mock implements FlutterVersion {} class MockVersion extends Mock implements FlutterVersion {}
class MockProcessInfo extends Mock implements ProcessInfo {} class MockProcessInfo extends Mock implements ProcessInfo {}
class MockIoProcessSignal extends Mock implements io.ProcessSignal {} class MockIoProcessSignal extends Mock implements io.ProcessSignal {}
......
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