From 5dbeb8f018c4c247b37373a0a0bc155c2f5f0303 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 23 Oct 2015 16:01:09 -0700 Subject: [PATCH] fix tests on windows remove a runInShell arg on windows when launching pub --- packages/flutter_tools/lib/src/commands/init.dart | 6 ++++-- packages/flutter_tools/lib/src/device.dart | 4 ++-- packages/flutter_tools/lib/src/process.dart | 6 ++++++ packages/flutter_tools/pubspec.yaml | 2 +- packages/flutter_tools/test/init_test.dart | 3 ++- packages/flutter_tools/test/list_test.dart | 14 +++++++++----- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/init.dart b/packages/flutter_tools/lib/src/commands/init.dart index 91608e2f50e..4e3512df718 100644 --- a/packages/flutter_tools/lib/src/commands/init.dart +++ b/packages/flutter_tools/lib/src/commands/init.dart @@ -9,6 +9,8 @@ import 'package:args/command_runner.dart'; import 'package:mustache4dart/mustache4dart.dart' as mustache; import 'package:path/path.dart' as p; +import '../process.dart'; + class InitCommand extends Command { final String name = 'init'; final String description = 'Create a new Flutter project.'; @@ -43,8 +45,8 @@ class InitCommand extends Command { if (argResults['pub']) { print("Running pub get..."); - Process process = - await Process.start('pub', ['get'], workingDirectory: out.path); + Process process = await Process.start( + sdkBinaryName('pub'), ['get'], workingDirectory: out.path); stdout.addStream(process.stdout); stderr.addStream(process.stderr); int code = await process.exitCode; diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 19ab6cdd262..f3c22afc240 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -773,8 +773,8 @@ class AndroidDevice extends Device { [adbPath, 'forward', observatoryPortString, observatoryPortString]); // Actually start the server. - await Process.start('pub', ['run', 'sky_tools:sky_server', _serverPort], - workingDirectory: serverRoot, mode: ProcessStartMode.DETACHED, runInShell: Platform.isWindows); + await Process.start(sdkBinaryName('pub'), ['run', 'sky_tools:sky_server', _serverPort], + workingDirectory: serverRoot, mode: ProcessStartMode.DETACHED); // Set up reverse port-forwarding so that the Android app can reach the // server running on localhost. diff --git a/packages/flutter_tools/lib/src/process.dart b/packages/flutter_tools/lib/src/process.dart index 7e22f525984..a23c3db5b30 100644 --- a/packages/flutter_tools/lib/src/process.dart +++ b/packages/flutter_tools/lib/src/process.dart @@ -64,6 +64,12 @@ String runCheckedSync(List cmd) => /// Run cmd and return stdout. String runSync(List 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 cmd, {bool checked: false}) { _logging.info(cmd.join(' ')); ProcessResult results = diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index f2fe4cf6b09..b992a472c5a 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: args: ^0.13.0 asn1lib: ^0.4.1 cipher: ^0.7.1 + crypto: ^0.9.1 mustache4dart: ^1.0.0 path: ^1.3.0 shelf_route: ^0.13.4 @@ -19,7 +20,6 @@ dependencies: shelf: ^0.6.2 test: ">=0.12.4+5 <0.12.5" yaml: ^2.1.3 - crypto: ^0.9.1 dev_dependencies: mockito: "^0.10.1" diff --git a/packages/flutter_tools/test/init_test.dart b/packages/flutter_tools/test/init_test.dart index b69eaa74fc4..2d55c3f600a 100644 --- a/packages/flutter_tools/test/init_test.dart +++ b/packages/flutter_tools/test/init_test.dart @@ -11,6 +11,7 @@ import 'dart:io'; import 'package:args/command_runner.dart'; import 'package:path/path.dart' as p; import 'package:sky_tools/src/commands/init.dart'; +import 'package:sky_tools/src/process.dart'; import 'package:test/test.dart'; main() => defineTests(); @@ -38,7 +39,7 @@ defineTests() { String path = p.join(temp.path, 'lib', 'main.dart'); expect(new File(path).existsSync(), true); ProcessResult exec = Process.runSync( - 'dartanalyzer', ['--fatal-warnings', path], + sdkBinaryName('dartanalyzer'), ['--fatal-warnings', path], workingDirectory: temp.path); if (exec.exitCode != 0) { print(exec.stdout); diff --git a/packages/flutter_tools/test/list_test.dart b/packages/flutter_tools/test/list_test.dart index 83bf713fd02..0b01b075ff3 100644 --- a/packages/flutter_tools/test/list_test.dart +++ b/packages/flutter_tools/test/list_test.dart @@ -2,6 +2,8 @@ // 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:mockito/mockito.dart'; import 'package:sky_tools/src/commands/list.dart'; @@ -14,23 +16,25 @@ main() => defineTests(); defineTests() { group('list', () { test('returns 0 when called', () { + final String mockCommand = Platform.isWindows ? 'cmd /c echo' : 'echo'; + ListCommand command = new ListCommand(); applyMocksToCommand(command); MockDeviceStore mockDevices = command.devices; // Avoid relying on adb being installed on the test system. // 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. // Instead, cause the test to run the echo command. - when(mockDevices.iOS.informerPath).thenReturn('echo'); - when(mockDevices.iOS.installerPath).thenReturn('echo'); - when(mockDevices.iOS.listerPath).thenReturn('echo'); + 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('echo'); + when(mockDevices.iOSSimulator.xcrunPath).thenReturn(mockCommand); CommandRunner runner = new CommandRunner('test_flutter', '')