Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class AppDomain extends Domain {
String isolateFilter,
}) async {
if (await device.isLocalEmulator && !options.buildInfo.supportsEmulator) {
throw '${toTitleCase(options.buildInfo.friendlyModeName)} mode is not supported for emulators.';
throw Exception('${toTitleCase(options.buildInfo.friendlyModeName)} mode is not supported for emulators.');
}
// We change the current working directory for the duration of the `start` command.
final Directory cwd = globals.fs.currentDirectory;
Expand Down
44 changes: 38 additions & 6 deletions packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/base/net.dart';
Expand Down Expand Up @@ -114,6 +115,38 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});

testUsingContext('Fails with toolExit run in profile mode on emulator with machine flag', () async {
globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').writeAsStringSync('\n');
globals.fs.file('lib/main.dart').createSync(recursive: true);
final FakeDevice device = FakeDevice(isLocalEmulator: true);
when(deviceManager.getAllConnectedDevices()).thenAnswer((Invocation invocation) async {
return <Device>[device];
});
when(deviceManager.getDevices()).thenAnswer((Invocation invocation) async {
return <Device>[device];
});
when(deviceManager.findTargetDevices(any)).thenAnswer((Invocation invocation) async {
return <Device>[device];
});
when(deviceManager.hasSpecifiedAllDevices).thenReturn(false);
when(deviceManager.deviceDiscoverers).thenReturn(<DeviceDiscovery>[]);

final RunCommand command = RunCommand();
applyMocksToCommand(command);
await expectLater(createTestCommandRunner(command).run(<String>[
'run',
'--no-pub',
'--machine',
'--profile',
]), throwsToolExit(message: 'not supported for emulators'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
DeviceManager: () => MockDeviceManager(),
Stdio: () => MockStdio(),
});

testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async {
globals.fs.currentDirectory = globals.fs.directory(globals.fs.path.join('a', 'b', 'c'))
..createSync(recursive: true);
Expand Down Expand Up @@ -572,23 +605,22 @@ class TestRunCommand extends RunCommand {
}
}

class MockStableFlutterVersion extends MockFlutterVersion {
@override
bool get isMaster => false;
}

class FakeDevice extends Fake implements Device {
FakeDevice({bool isLocalEmulator = false})
: _isLocalEmulator = isLocalEmulator;

static const int kSuccess = 1;
static const int kFailure = -1;
TargetPlatform _targetPlatform = TargetPlatform.ios;
final bool _isLocalEmulator;

@override
String get id => 'fake_device';

void _throwToolExit(int code) => throwToolExit(null, exitCode: code);

@override
Future<bool> get isLocalEmulator => Future<bool>.value(false);
Future<bool> get isLocalEmulator => Future<bool>.value(_isLocalEmulator);

@override
bool get supportsHotReload => false;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/test/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Matcher throwsToolExit({ int exitCode, Pattern message }) {
matcher = allOf(matcher, (ToolExit e) => e.exitCode == exitCode);
}
if (message != null) {
matcher = allOf(matcher, (ToolExit e) => e.message.contains(message));
matcher = allOf(matcher, (ToolExit e) => e.message?.contains(message) ?? false);
}
return throwsA(matcher);
}
Expand Down