allow any android sdk version

This commit is contained in:
Devon Carew
2016-02-13 12:00:41 -08:00
parent 5a167615d3
commit dcf0b7bae6
25 changed files with 426 additions and 220 deletions

View File

@@ -5,7 +5,7 @@
import 'package:flutter_tools/src/android/device_android.dart';
import 'package:test/test.dart';
import 'src/test_context.dart';
import 'src/context.dart';
main() => defineTests();

View File

@@ -11,7 +11,7 @@ import 'package:flutter_tools/src/commands/create.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'src/test_context.dart';
import 'src/context.dart';
main() => defineTests();

View File

@@ -16,11 +16,17 @@ import 'src/mocks.dart';
main() => defineTests();
defineTests() {
group('daemon', () {
Daemon daemon;
AppContext appContext;
NotifyingLogger notifyingLogger;
Daemon daemon;
AppContext appContext;
NotifyingLogger notifyingLogger;
void _testUsingContext(String description, dynamic testMethod()) {
test(description, () {
return appContext.runInZone(testMethod);
});
}
group('daemon', () {
setUp(() {
appContext = new AppContext();
notifyingLogger = new NotifyingLogger();
@@ -32,7 +38,7 @@ defineTests() {
return daemon.shutdown();
});
test('daemon.version', () async {
_testUsingContext('daemon.version', () async {
StreamController<Map<String, dynamic>> commands = new StreamController();
StreamController<Map<String, dynamic>> responses = new StreamController();
daemon = new Daemon(
@@ -47,7 +53,7 @@ defineTests() {
expect(response['result'] is String, true);
});
test('daemon.logMessage', () {
_testUsingContext('daemon.logMessage', () {
return appContext.runInZone(() async {
StreamController<Map<String, dynamic>> commands = new StreamController();
StreamController<Map<String, dynamic>> responses = new StreamController();
@@ -68,7 +74,7 @@ defineTests() {
});
});
test('daemon.shutdown', () async {
_testUsingContext('daemon.shutdown', () async {
StreamController<Map<String, dynamic>> commands = new StreamController();
StreamController<Map<String, dynamic>> responses = new StreamController();
daemon = new Daemon(
@@ -82,7 +88,7 @@ defineTests() {
});
});
test('daemon.stopAll', () async {
_testUsingContext('daemon.stopAll', () async {
DaemonCommand command = new DaemonCommand();
applyMocksToCommand(command);
@@ -112,7 +118,7 @@ defineTests() {
expect(response['result'], true);
});
test('device.getDevices', () async {
_testUsingContext('device.getDevices', () async {
StreamController<Map<String, dynamic>> commands = new StreamController();
StreamController<Map<String, dynamic>> responses = new StreamController();
daemon = new Daemon(

View File

@@ -5,7 +5,7 @@
import 'package:flutter_tools/src/device.dart';
import 'package:test/test.dart';
import 'src/test_context.dart';
import 'src/context.dart';
main() => defineTests();

View File

@@ -2,18 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/commands/install.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/mocks.dart';
main() => defineTests();
defineTests() {
group('install', () {
test('returns 0 when Android is connected and ready for an install', () {
testUsingContext('returns 0 when Android is connected and ready for an install', () {
InstallCommand command = new InstallCommand();
applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices;
@@ -30,13 +31,12 @@ defineTests() {
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
return runner.run(['install']).then((int code) => expect(code, equals(0)));
return createTestCommandRunner(command).run(['install']).then((int code) {
expect(code, equals(0));
});
});
test('returns 0 when iOS is connected and ready for an install', () {
testUsingContext('returns 0 when iOS is connected and ready for an install', () {
InstallCommand command = new InstallCommand();
applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices;
@@ -53,9 +53,9 @@ defineTests() {
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
return runner.run(['install']).then((int code) => expect(code, equals(0)));
return createTestCommandRunner(command).run(['install']).then((int code) {
expect(code, equals(0));
});
});
});
}

View File

@@ -2,43 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/commands/list.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:test/test.dart';
import 'src/mocks.dart';
import 'src/test_context.dart';
import 'src/common.dart';
import 'src/context.dart';
main() => defineTests();
defineTests() {
group('list', () {
testUsingContext('returns 0 when called', () {
final String mockCommand = Platform.isWindows ? 'cmd /c echo' : 'echo';
ListCommand command = new ListCommand();
applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices;
return createTestCommandRunner(command).run(['list']).then((int code) {
expect(code, equals(0));
});
});
// Avoid relying on adb being installed on the test system.
// Instead, cause the test to run the echo command.
when(mockDevices.android.adbPath).thenReturn(mockCommand);
// Avoid relying on idevice* being installed on the test system.
// Instead, cause the test to run the echo command.
when(mockDevices.iOS.informerPath).thenReturn(mockCommand);
when(mockDevices.iOS.installerPath).thenReturn(mockCommand);
when(mockDevices.iOS.listerPath).thenReturn(mockCommand);
// Avoid relying on xcrun being installed on the test system.
// Instead, cause the test to run the echo command.
when(mockDevices.iOSSimulator.xcrunPath).thenReturn(mockCommand);
CommandRunner runner = new CommandRunner('test_flutter', '')..addCommand(command);
return runner.run(['list']).then((int code) => expect(code, equals(0)));
testUsingContext('no error when no connected devices', () {
ListCommand command = new ListCommand();
return createTestCommandRunner(command).run(['list']).then((int code) {
expect(code, equals(0));
expect(testLogger.statusText, contains('No connected devices'));
});
}, overrides: <Type, dynamic>{
AndroidSdk: null,
DeviceManager: new DeviceManager()
});
});
}

View File

@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/commands/listen.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/mocks.dart';
import 'src/test_context.dart';
main() => defineTests();
@@ -24,8 +23,9 @@ defineTests() {
when(mockDevices.iOS.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
CommandRunner runner = new FlutterCommandRunner()..addCommand(command);
return runner.run(['listen']).then((int code) => expect(code, equals(0)));
return createTestCommandRunner(command).run(['listen']).then((int code) {
expect(code, equals(0));
});
});
});
}

View File

@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/commands/logs.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:test/test.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/mocks.dart';
import 'src/test_context.dart';
main() => defineTests();
@@ -17,8 +16,7 @@ defineTests() {
testUsingContext('fail with a bad device id', () {
LogsCommand command = new LogsCommand();
applyMocksToCommand(command);
CommandRunner runner = new FlutterCommandRunner()..addCommand(command);
return runner.run(<String>['-d', 'abc123', 'logs']).then((int code) {
return createTestCommandRunner(command).run(<String>['-d', 'abc123', 'logs']).then((int code) {
expect(code, equals(1));
});
});

View File

@@ -0,0 +1,11 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
CommandRunner createTestCommandRunner(FlutterCommand command) {
return new FlutterCommandRunner()..addCommand(command);
}

View File

@@ -9,12 +9,25 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:test/test.dart';
void testUsingContext(String description, dynamic testMethod(), { Timeout timeout }) {
/// Return the test logger. This assumes that the current Logger is a BufferLogger.
BufferLogger get testLogger => context[Logger];
void testUsingContext(String description, dynamic testMethod(), {
Timeout timeout,
Map<Type, dynamic> overrides: const <Type, dynamic>{}
}) {
test(description, () {
AppContext testContext = new AppContext();
testContext[Logger] = new BufferLogger();
testContext[DeviceManager] = new MockDeviceManager();
overrides.forEach((Type type, dynamic value) {
testContext[type] = value;
});
if (!overrides.containsKey(Logger))
testContext[Logger] = new BufferLogger();
if (!overrides.containsKey(DeviceManager))
testContext[DeviceManager] = new MockDeviceManager();
return testContext.runInZone(testMethod);
}, timeout: timeout);

View File

@@ -2,18 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/commands/stop.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/mocks.dart';
main() => defineTests();
defineTests() {
group('stop', () {
test('returns 0 when Android is connected and ready to be stopped', () {
testUsingContext('returns 0 when Android is connected and ready to be stopped', () {
StopCommand command = new StopCommand();
applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices;
@@ -27,12 +28,12 @@ defineTests() {
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
return runner.run(['stop']).then((int code) => expect(code, equals(0)));
return createTestCommandRunner(command).run(['stop']).then((int code) {
expect(code, equals(0));
});
});
test('returns 0 when iOS is connected and ready to be stopped', () {
testUsingContext('returns 0 when iOS is connected and ready to be stopped', () {
StopCommand command = new StopCommand();
applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices;
@@ -46,9 +47,9 @@ defineTests() {
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
return runner.run(['stop']).then((int code) => expect(code, equals(0)));
return createTestCommandRunner(command).run(['stop']).then((int code) {
expect(code, equals(0));
});
});
});
}

View File

@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/commands/trace.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'src/common.dart';
import 'src/context.dart';
import 'src/mocks.dart';
import 'src/test_context.dart';
main() => defineTests();
@@ -21,9 +21,9 @@ defineTests() {
when(mockDevices.android.isConnected()).thenReturn(false);
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
return runner.run(['trace']).then((int code) => expect(code, equals(1)));
return createTestCommandRunner(command).run(['trace']).then((int code) {
expect(code, equals(1));
});
});
});
}