Add tests for migrate command methods (#103466)

This commit is contained in:
Gary Qian
2022-05-11 11:09:08 -07:00
committed by GitHub
parent 5e85d23740
commit e997a3abd2
5 changed files with 243 additions and 42 deletions

View File

@@ -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;

View File

@@ -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;
}
}