Refactor all the commands to be Commands from the Args package. Also use CommandRunner for the top-level command.

This commit is contained in:
Ian Fischer
2015-09-24 11:13:20 -07:00
parent a49120c667
commit cae053c353
11 changed files with 221 additions and 357 deletions

View File

@@ -4,13 +4,11 @@
import 'dart:io';
import 'package:mockito/mockito.dart';
import 'package:args/command_runner.dart';
import 'package:path/path.dart' as p;
import 'package:sky_tools/src/init.dart';
import 'package:test/test.dart';
import 'src/common.dart';
main() => defineTests();
defineTests() {
@@ -27,14 +25,13 @@ defineTests() {
// Verify that we create a project that is well-formed.
test('init sky-simple', () async {
InitCommandHandler handler = new InitCommandHandler();
MockArgResults results = new MockArgResults();
when(results['help']).thenReturn(false);
when(results['pub']).thenReturn(true);
when(results.wasParsed('out')).thenReturn(true);
when(results['out']).thenReturn(temp.path);
await handler.processArgResults(results);
String path = p.join(temp.path, 'lib/main.dart');
InitCommand command = new InitCommand();
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
await runner.run(['init', '--out', temp.path])
.then((int code) => expect(code, equals(0)));
String path = p.join(temp.path, 'lib', 'main.dart');
expect(new File(path).existsSync(), true);
ProcessResult exec = Process.runSync(
'dartanalyzer', ['--fatal-warnings', path],

View File

@@ -4,9 +4,10 @@
library install_test;
import 'package:args/command_runner.dart';
import 'package:mockito/mockito.dart';
import 'package:sky_tools/src/install.dart';
import 'package:sky_tools/src/application_package.dart';
import 'package:sky_tools/src/install.dart';
import 'package:test/test.dart';
import 'src/common.dart';
@@ -23,12 +24,11 @@ defineTests() {
MockAndroidDevice android = new MockAndroidDevice();
when(android.isConnected()).thenReturn(true);
when(android.installApp(any)).thenReturn(true);
InstallCommandHandler handler = new InstallCommandHandler(android);
InstallCommand command = new InstallCommand(android);
MockArgResults results = new MockArgResults();
when(results['help']).thenReturn(false);
handler
.processArgResults(results)
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
runner.run(['install'])
.then((int code) => expect(code, equals(0)));
});
});

View File

@@ -2,15 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/args.dart';
import 'package:mockito/mockito.dart';
import 'package:sky_tools/src/device.dart';
class MockArgResults extends Mock implements ArgResults {
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}
class MockAndroidDevice extends Mock implements AndroidDevice {
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);