Commit 7536404b authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Add --replay-from argument to Flutter tools (#7146)

This argument will enable mocking of os-layer process invocations,
where the mock behavior will come from replaying a previously-
recorded set of invocations. At the point of process invocation,
the key metadata for the invocation will be looked up in the
recording's manifest, and iff a matching record exists in the
manifest, the process will be mocked out with data derived from
the corresponding recorded process (e.g. stdout, stderr, exit code).
parent 93e662ab
......@@ -422,7 +422,8 @@ class IOSSimulator extends Device {
try {
await _setupUpdatedApplicationBundle(app);
} on ToolExit {
} on ToolExit catch (e) {
printError(e.message);
return new LaunchResult.failed();
}
} else {
......@@ -507,7 +508,7 @@ class IOSSimulator extends Device {
// Step 2: Assert that the Xcode project was successfully built.
IOSApp iosApp = app;
Directory bundle = new Directory(iosApp.simulatorBundlePath);
bool bundleExists = await bundle.exists();
bool bundleExists = bundle.existsSync();
if (!bundleExists)
throwToolExit('Could not find the built application bundle at ${bundle.path}.');
......
......@@ -10,6 +10,7 @@ import 'package:args/command_runner.dart';
import 'package:path/path.dart' as path;
import '../android/android_sdk.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/logger.dart';
import '../base/process.dart';
......@@ -102,6 +103,15 @@ class FlutterCommandRunner extends CommandRunner<Null> {
'If the location is a directory, a ZIP file named `recording.zip` '
'will be created in that directory. Otherwise, a ZIP file will be '
'created with the path specified in this flag.');
argParser.addOption('replay-from',
help:
'Enables mocking of process invocations by replaying their stdout, '
'stderr, and exit code from the specified recording (obtained '
'via --record-to).\n'
'If the location is a file, it is assumed to be a ZIP file '
'structured according to the output of --record-to. If the '
'location is a directory, it is assumed to be an unzipped version '
'of such a ZIP file.');
}
@override
......@@ -151,17 +161,28 @@ class FlutterCommandRunner extends CommandRunner<Null> {
context.setVariable(Logger, new VerboseLogger());
}
if (globalResults['record-to'] != null &&
globalResults['replay-from'] != null)
throwToolExit('--record-to and --replay-from cannot be used together.');
if (globalResults['record-to'] != null) {
// Turn on recording
String recordToPath = globalResults['record-to'].trim();
FileSystemEntity recordTo;
if (recordToPath.isNotEmpty) {
recordTo = await FileSystemEntity.isDirectory(recordToPath)
? new Directory(recordToPath)
: new File(recordToPath);
}
// Turn on recording.
String recordTo = globalResults['record-to'].trim();
if (recordTo.isEmpty)
recordTo = null;
context.setVariable(ProcessManager,
new RecordingProcessManager(recordTo: recordTo));
new RecordingProcessManager(recordTo));
}
if (globalResults['replay-from'] != null) {
// Turn on replay-based mocking.
try {
context.setVariable(ProcessManager, await ReplayProcessManager.create(
globalResults['replay-from'].trim(),
));
} on ArgumentError {
throwToolExit('--replay-from must specify a valid file or directory.');
}
}
logger.quiet = globalResults['quiet'];
......
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