fix tests on windows

remove a runInShell arg on windows when launching pub
This commit is contained in:
Devon Carew 2015-10-23 16:01:09 -07:00
parent 6b2d6fdc8c
commit 5dbeb8f018
6 changed files with 24 additions and 11 deletions

View file

@ -9,6 +9,8 @@ import 'package:args/command_runner.dart';
import 'package:mustache4dart/mustache4dart.dart' as mustache; import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import '../process.dart';
class InitCommand extends Command { class InitCommand extends Command {
final String name = 'init'; final String name = 'init';
final String description = 'Create a new Flutter project.'; final String description = 'Create a new Flutter project.';
@ -43,8 +45,8 @@ class InitCommand extends Command {
if (argResults['pub']) { if (argResults['pub']) {
print("Running pub get..."); print("Running pub get...");
Process process = Process process = await Process.start(
await Process.start('pub', ['get'], workingDirectory: out.path); sdkBinaryName('pub'), ['get'], workingDirectory: out.path);
stdout.addStream(process.stdout); stdout.addStream(process.stdout);
stderr.addStream(process.stderr); stderr.addStream(process.stderr);
int code = await process.exitCode; int code = await process.exitCode;

View file

@ -773,8 +773,8 @@ class AndroidDevice extends Device {
[adbPath, 'forward', observatoryPortString, observatoryPortString]); [adbPath, 'forward', observatoryPortString, observatoryPortString]);
// Actually start the server. // Actually start the server.
await Process.start('pub', ['run', 'sky_tools:sky_server', _serverPort], await Process.start(sdkBinaryName('pub'), ['run', 'sky_tools:sky_server', _serverPort],
workingDirectory: serverRoot, mode: ProcessStartMode.DETACHED, runInShell: Platform.isWindows); workingDirectory: serverRoot, mode: ProcessStartMode.DETACHED);
// Set up reverse port-forwarding so that the Android app can reach the // Set up reverse port-forwarding so that the Android app can reach the
// server running on localhost. // server running on localhost.

View file

@ -64,6 +64,12 @@ String runCheckedSync(List<String> cmd) =>
/// Run cmd and return stdout. /// Run cmd and return stdout.
String runSync(List<String> cmd) => _runWithLoggingSync(cmd); String runSync(List<String> cmd) => _runWithLoggingSync(cmd);
/// Return the platform specific name for the given Dart SDK binary. So, `pub`
/// ==> `pub.bat`.
String sdkBinaryName(String name) {
return Platform.isWindows ? '${name}.bat' : name;
}
String _runWithLoggingSync(List<String> cmd, {bool checked: false}) { String _runWithLoggingSync(List<String> cmd, {bool checked: false}) {
_logging.info(cmd.join(' ')); _logging.info(cmd.join(' '));
ProcessResult results = ProcessResult results =

View file

@ -12,6 +12,7 @@ dependencies:
args: ^0.13.0 args: ^0.13.0
asn1lib: ^0.4.1 asn1lib: ^0.4.1
cipher: ^0.7.1 cipher: ^0.7.1
crypto: ^0.9.1
mustache4dart: ^1.0.0 mustache4dart: ^1.0.0
path: ^1.3.0 path: ^1.3.0
shelf_route: ^0.13.4 shelf_route: ^0.13.4
@ -19,7 +20,6 @@ dependencies:
shelf: ^0.6.2 shelf: ^0.6.2
test: ">=0.12.4+5 <0.12.5" test: ">=0.12.4+5 <0.12.5"
yaml: ^2.1.3 yaml: ^2.1.3
crypto: ^0.9.1
dev_dependencies: dev_dependencies:
mockito: "^0.10.1" mockito: "^0.10.1"

View file

@ -11,6 +11,7 @@ import 'dart:io';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:sky_tools/src/commands/init.dart'; import 'package:sky_tools/src/commands/init.dart';
import 'package:sky_tools/src/process.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
main() => defineTests(); main() => defineTests();
@ -38,7 +39,7 @@ defineTests() {
String path = p.join(temp.path, 'lib', 'main.dart'); String path = p.join(temp.path, 'lib', 'main.dart');
expect(new File(path).existsSync(), true); expect(new File(path).existsSync(), true);
ProcessResult exec = Process.runSync( ProcessResult exec = Process.runSync(
'dartanalyzer', ['--fatal-warnings', path], sdkBinaryName('dartanalyzer'), ['--fatal-warnings', path],
workingDirectory: temp.path); workingDirectory: temp.path);
if (exec.exitCode != 0) { if (exec.exitCode != 0) {
print(exec.stdout); print(exec.stdout);

View file

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:io';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:sky_tools/src/commands/list.dart'; import 'package:sky_tools/src/commands/list.dart';
@ -14,23 +16,25 @@ main() => defineTests();
defineTests() { defineTests() {
group('list', () { group('list', () {
test('returns 0 when called', () { test('returns 0 when called', () {
final String mockCommand = Platform.isWindows ? 'cmd /c echo' : 'echo';
ListCommand command = new ListCommand(); ListCommand command = new ListCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockDeviceStore mockDevices = command.devices;
// Avoid relying on adb being installed on the test system. // Avoid relying on adb being installed on the test system.
// Instead, cause the test to run the echo command. // Instead, cause the test to run the echo command.
when(mockDevices.android.adbPath).thenReturn('echo'); when(mockDevices.android.adbPath).thenReturn(mockCommand);
// Avoid relying on idevice* being installed on the test system. // Avoid relying on idevice* being installed on the test system.
// Instead, cause the test to run the echo command. // Instead, cause the test to run the echo command.
when(mockDevices.iOS.informerPath).thenReturn('echo'); when(mockDevices.iOS.informerPath).thenReturn(mockCommand);
when(mockDevices.iOS.installerPath).thenReturn('echo'); when(mockDevices.iOS.installerPath).thenReturn(mockCommand);
when(mockDevices.iOS.listerPath).thenReturn('echo'); when(mockDevices.iOS.listerPath).thenReturn(mockCommand);
// Avoid relying on xcrun being installed on the test system. // Avoid relying on xcrun being installed on the test system.
// Instead, cause the test to run the echo command. // Instead, cause the test to run the echo command.
when(mockDevices.iOSSimulator.xcrunPath).thenReturn('echo'); when(mockDevices.iOSSimulator.xcrunPath).thenReturn(mockCommand);
CommandRunner runner = new CommandRunner('test_flutter', '') CommandRunner runner = new CommandRunner('test_flutter', '')