Add tests for migrate command methods (#103466)
This commit is contained in:
@@ -2,38 +2,20 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// import 'package:process/process.dart';
|
||||
|
||||
// import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
// import '../base/platform.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../migrate/migrate_utils.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
// TODO(garyq): Add each of these back in as they land.
|
||||
// import 'migrate_abandon.dart';
|
||||
// import 'migrate_apply.dart';
|
||||
// import 'migrate_resolve_conflicts.dart';
|
||||
// import 'migrate_start.dart';
|
||||
// import 'migrate_status.dart';
|
||||
|
||||
|
||||
/// Base command for the migration tool.
|
||||
class MigrateCommand extends FlutterCommand {
|
||||
MigrateCommand({
|
||||
// bool verbose = false,
|
||||
required this.logger,
|
||||
// TODO(garyq): Add each of these back in as they land.
|
||||
// required FileSystem fileSystem,
|
||||
// required Terminal terminal,
|
||||
// required Platform platform,
|
||||
// required ProcessManager processManager,
|
||||
// TODO(garyq): Add each parameters in as subcommands land.
|
||||
}) {
|
||||
// TODO(garyq): Add each of these back in as they land.
|
||||
// addSubcommand(MigrateAbandonCommand(logger: logger, fileSystem: fileSystem, terminal: terminal, platform: platform, processManager: processManager));
|
||||
// addSubcommand(MigrateApplyCommand(verbose: verbose, logger: logger, fileSystem: fileSystem, terminal: terminal, platform: platform, processManager: processManager));
|
||||
// addSubcommand(MigrateResolveConflictsCommand(logger: logger, fileSystem: fileSystem, terminal: terminal));
|
||||
// addSubcommand(MigrateStartCommand(verbose: verbose, logger: logger, fileSystem: fileSystem, platform: platform, processManager: processManager));
|
||||
// addSubcommand(MigrateStatusCommand(verbose: verbose, logger: logger, fileSystem: fileSystem, platform: platform, processManager: processManager));
|
||||
// TODO(garyq): Add subcommands.
|
||||
}
|
||||
|
||||
final Logger logger;
|
||||
|
||||
@@ -242,32 +242,32 @@ class MigrateUtils {
|
||||
bool exit = true,
|
||||
bool silent = false
|
||||
}) {
|
||||
if (!allowedExitCodes.contains(result.exitCode) && !allowedExitCodes.contains(-1)) {
|
||||
if (!silent) {
|
||||
_logger.printError('Command encountered an error with exit code ${result.exitCode}.');
|
||||
if (commandDescription != null) {
|
||||
_logger.printError('Command:');
|
||||
_logger.printError(commandDescription, indent: 2);
|
||||
}
|
||||
_logger.printError('Stdout:');
|
||||
_logger.printError(result.stdout, indent: 2);
|
||||
_logger.printError('Stderr:');
|
||||
_logger.printError(result.stderr, indent: 2);
|
||||
}
|
||||
if (exit) {
|
||||
throwToolExit('Command failed with exit code ${result.exitCode}', exitCode: result.exitCode);
|
||||
}
|
||||
return false;
|
||||
if (allowedExitCodes.contains(result.exitCode) || allowedExitCodes.contains(-1)) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
if (!silent) {
|
||||
_logger.printError('Command encountered an error with exit code ${result.exitCode}.');
|
||||
if (commandDescription != null) {
|
||||
_logger.printError('Command:');
|
||||
_logger.printError(commandDescription, indent: 2);
|
||||
}
|
||||
_logger.printError('Stdout:');
|
||||
_logger.printError(result.stdout, indent: 2);
|
||||
_logger.printError('Stderr:');
|
||||
_logger.printError(result.stderr, indent: 2);
|
||||
}
|
||||
if (exit) {
|
||||
throwToolExit('Command failed with exit code ${result.exitCode}', exitCode: result.exitCode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Returns true if the file does not contain any git conflit markers.
|
||||
bool conflictsResolved(String contents) {
|
||||
if (contents.contains('>>>>>>>') && contents.contains('=======') && contents.contains('<<<<<<<')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
final bool hasMarker = contents.contains('>>>>>>>') ||
|
||||
contents.contains('=======') ||
|
||||
contents.contains('<<<<<<<');
|
||||
return !hasMarker;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user