[flutter_tools] stringArg refactor (#103231)

This commit is contained in:
Jesús S Guerrero
2022-05-09 09:54:12 -07:00
committed by GitHub
parent 95116386b7
commit 596e9d1c47
29 changed files with 195 additions and 160 deletions

View File

@@ -11,8 +11,22 @@ import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/testbed.dart';
class CommandDummy extends FlutterCommand{
@override
String get description => 'description';
@override
String get name => 'test';
@override
Future<FlutterCommandResult> runCommand() async {
return FlutterCommandResult.success();
}
}
void main() {
test('Help for command line arguments is consistently styled and complete', () => Testbed().run(() {
final FlutterCommandRunner runner = FlutterCommandRunner(verboseHelp: true);
@@ -22,6 +36,20 @@ void main() {
).forEach(runner.addCommand);
verifyCommandRunner(runner);
}));
testUsingContext('String? safe argResults', () async {
final CommandDummy command = CommandDummy();
final FlutterCommandRunner runner = FlutterCommandRunner(verboseHelp: true);
command.argParser.addOption('key');
runner.addCommand(command);
await runner.run(<String>['test', '--key=value']);
expect(command.stringArg('key'), 'value');
expect(command.stringArg('empty'), null);
expect(command.stringArgDeprecated('key'), 'value');
expect(() => command.stringArgDeprecated('empty'), throwsA(const TypeMatcher<ArgumentError>()));
});
}
void verifyCommandRunner(CommandRunner<Object> runner) {