Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'dart:async'; |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 6 | |
| 7 | import 'package:args/command_runner.dart'; |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 8 | import 'package:flutter_tools/src/base/file_system.dart' hide IOSink; |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 9 | import 'package:flutter_tools/src/base/io.dart'; |
jcollins-g | ca67701 | 2018-02-21 09:54:07 -0800 | [diff] [blame] | 10 | import 'package:flutter_tools/src/base/utils.dart'; |
Todd Volkert | 83d411f | 2017-03-10 09:39:01 -0800 | [diff] [blame] | 11 | import 'package:flutter_tools/src/cache.dart'; |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 12 | import 'package:flutter_tools/src/commands/packages.dart'; |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 13 | import 'package:flutter_tools/src/dart/pub.dart'; |
xster | ba26f92 | 2019-11-05 12:38:42 -0800 | [diff] [blame] | 14 | import 'package:flutter_tools/src/features.dart'; |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 15 | import 'package:flutter_tools/src/reporting/reporting.dart'; |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 16 | import 'package:process/process.dart'; |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 17 | |
Ian Hickson | d919e69 | 2019-07-13 11:51:44 -0700 | [diff] [blame] | 18 | import '../../src/common.dart'; |
| 19 | import '../../src/context.dart'; |
| 20 | import '../../src/mocks.dart' show MockProcessManager, MockStdio, PromptingProcess; |
xster | ba26f92 | 2019-11-05 12:38:42 -0800 | [diff] [blame] | 21 | import '../../src/testbed.dart'; |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 22 | |
jcollins-g | ca67701 | 2018-02-21 09:54:07 -0800 | [diff] [blame] | 23 | class AlwaysTrueBotDetector implements BotDetector { |
| 24 | const AlwaysTrueBotDetector(); |
| 25 | |
| 26 | @override |
| 27 | bool get isRunningOnBot => true; |
| 28 | } |
| 29 | |
| 30 | |
| 31 | class AlwaysFalseBotDetector implements BotDetector { |
| 32 | const AlwaysFalseBotDetector(); |
| 33 | |
| 34 | @override |
| 35 | bool get isRunningOnBot => false; |
| 36 | } |
| 37 | |
| 38 | |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 39 | void main() { |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 40 | Cache.disableLocking(); |
| 41 | group('packages get/upgrade', () { |
Ian Hickson | 3dec6a6 | 2018-08-17 13:17:23 -0700 | [diff] [blame] | 42 | Directory tempDir; |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 43 | |
| 44 | setUp(() { |
Ian Hickson | 3dec6a6 | 2018-08-17 13:17:23 -0700 | [diff] [blame] | 45 | tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.'); |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 46 | }); |
| 47 | |
| 48 | tearDown(() { |
Ian Hickson | 3dec6a6 | 2018-08-17 13:17:23 -0700 | [diff] [blame] | 49 | tryToDelete(tempDir); |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 50 | }); |
| 51 | |
Alexandre Ardhuin | 5169ab5 | 2019-02-21 09:27:07 +0100 | [diff] [blame] | 52 | Future<String> createProjectWithPlugin(String plugin, { List<String> arguments }) async { |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 53 | final String projectPath = await createProject(tempDir, arguments: arguments); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 54 | final File pubspec = fs.file(fs.path.join(projectPath, 'pubspec.yaml')); |
| 55 | String content = await pubspec.readAsString(); |
| 56 | content = content.replaceFirst( |
| 57 | '\ndependencies:\n', |
| 58 | '\ndependencies:\n $plugin:\n', |
| 59 | ); |
| 60 | await pubspec.writeAsString(content, flush: true); |
| 61 | return projectPath; |
| 62 | } |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 63 | |
Emmanuel Garcia | 3bbdf01 | 2019-05-29 20:56:28 -0700 | [diff] [blame] | 64 | Future<PackagesCommand> runCommandIn(String projectPath, String verb, { List<String> args }) async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 65 | final PackagesCommand command = PackagesCommand(); |
Alexandre Ardhuin | 2d3ff10 | 2018-10-05 07:54:56 +0200 | [diff] [blame] | 66 | final CommandRunner<void> runner = createTestCommandRunner(command); |
Alexandre Ardhuin | 758009b | 2019-07-02 21:11:56 +0200 | [diff] [blame] | 67 | await runner.run(<String>[ |
| 68 | 'packages', |
| 69 | verb, |
| 70 | ...?args, |
| 71 | projectPath, |
| 72 | ]); |
Emmanuel Garcia | 3bbdf01 | 2019-05-29 20:56:28 -0700 | [diff] [blame] | 73 | return command; |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Michael Goderbauer | ca4d721 | 2017-05-08 14:08:59 -0700 | [diff] [blame] | 76 | void expectExists(String projectPath, String relPath) { |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 77 | expect( |
| 78 | fs.isFileSync(fs.path.join(projectPath, relPath)), |
| 79 | true, |
| 80 | reason: '$projectPath/$relPath should exist, but does not', |
| 81 | ); |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 84 | void expectContains(String projectPath, String relPath, String substring) { |
| 85 | expectExists(projectPath, relPath); |
| 86 | expect( |
| 87 | fs.file(fs.path.join(projectPath, relPath)).readAsStringSync(), |
| 88 | contains(substring), |
Alexandre Ardhuin | 387f885 | 2019-03-01 08:17:55 +0100 | [diff] [blame] | 89 | reason: '$projectPath/$relPath has unexpected content', |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 90 | ); |
| 91 | } |
| 92 | |
| 93 | void expectNotExists(String projectPath, String relPath) { |
| 94 | expect( |
| 95 | fs.isFileSync(fs.path.join(projectPath, relPath)), |
| 96 | false, |
| 97 | reason: '$projectPath/$relPath should not exist, but does', |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | void expectNotContains(String projectPath, String relPath, String substring) { |
| 102 | expectExists(projectPath, relPath); |
| 103 | expect( |
| 104 | fs.file(fs.path.join(projectPath, relPath)).readAsStringSync(), |
| 105 | isNot(contains(substring)), |
| 106 | reason: '$projectPath/$relPath has unexpected content', |
| 107 | ); |
| 108 | } |
| 109 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 110 | const List<String> pubOutput = <String>[ |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 111 | '.packages', |
| 112 | 'pubspec.lock', |
| 113 | ]; |
| 114 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 115 | const List<String> pluginRegistrants = <String>[ |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 116 | 'ios/Runner/GeneratedPluginRegistrant.h', |
| 117 | 'ios/Runner/GeneratedPluginRegistrant.m', |
| 118 | 'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java', |
| 119 | ]; |
| 120 | |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 121 | const List<String> modulePluginRegistrants = <String>[ |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 122 | '.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.h', |
| 123 | '.ios/Flutter/FlutterPluginRegistrant/Classes/GeneratedPluginRegistrant.m', |
| 124 | '.android/Flutter/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java', |
| 125 | ]; |
| 126 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 127 | const List<String> pluginWitnesses = <String>[ |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 128 | '.flutter-plugins', |
| 129 | 'ios/Podfile', |
| 130 | ]; |
| 131 | |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 132 | const List<String> modulePluginWitnesses = <String>[ |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 133 | '.flutter-plugins', |
| 134 | '.ios/Podfile', |
| 135 | ]; |
| 136 | |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 137 | const Map<String, String> pluginContentWitnesses = <String, String>{ |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 138 | 'ios/Flutter/Debug.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"', |
| 139 | 'ios/Flutter/Release.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"', |
| 140 | }; |
| 141 | |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 142 | const Map<String, String> modulePluginContentWitnesses = <String, String>{ |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 143 | '.ios/Config/Debug.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"', |
| 144 | '.ios/Config/Release.xcconfig': '#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"', |
| 145 | }; |
| 146 | |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 147 | void expectDependenciesResolved(String projectPath) { |
| 148 | for (String output in pubOutput) { |
| 149 | expectExists(projectPath, output); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void expectZeroPluginsInjected(String projectPath) { |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 154 | for (final String registrant in modulePluginRegistrants) { |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 155 | expectExists(projectPath, registrant); |
| 156 | } |
| 157 | for (final String witness in pluginWitnesses) { |
| 158 | expectNotExists(projectPath, witness); |
| 159 | } |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 160 | modulePluginContentWitnesses.forEach((String witness, String content) { |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 161 | expectNotContains(projectPath, witness, content); |
| 162 | }); |
| 163 | } |
| 164 | |
| 165 | void expectPluginInjected(String projectPath) { |
| 166 | for (final String registrant in pluginRegistrants) { |
| 167 | expectExists(projectPath, registrant); |
| 168 | } |
| 169 | for (final String witness in pluginWitnesses) { |
| 170 | expectExists(projectPath, witness); |
| 171 | } |
| 172 | pluginContentWitnesses.forEach((String witness, String content) { |
| 173 | expectContains(projectPath, witness, content); |
| 174 | }); |
| 175 | } |
| 176 | |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 177 | void expectModulePluginInjected(String projectPath) { |
| 178 | for (final String registrant in modulePluginRegistrants) { |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 179 | expectExists(projectPath, registrant); |
| 180 | } |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 181 | for (final String witness in modulePluginWitnesses) { |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 182 | expectExists(projectPath, witness); |
| 183 | } |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 184 | modulePluginContentWitnesses.forEach((String witness, String content) { |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 185 | expectContains(projectPath, witness, content); |
| 186 | }); |
| 187 | } |
| 188 | |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 189 | void removeGeneratedFiles(String projectPath) { |
| 190 | final Iterable<String> allFiles = <List<String>>[ |
| 191 | pubOutput, |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 192 | modulePluginRegistrants, |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 193 | pluginWitnesses, |
Alexandre Ardhuin | f62afdc | 2018-10-01 21:29:08 +0200 | [diff] [blame] | 194 | ].expand<String>((List<String> list) => list); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 195 | for (String path in allFiles) { |
| 196 | final File file = fs.file(fs.path.join(projectPath, path)); |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 197 | if (file.existsSync()) { |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 198 | file.deleteSync(); |
Zachary Anderson | e2340c6 | 2019-09-13 14:51:35 -0700 | [diff] [blame] | 199 | } |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | testUsingContext('get fetches packages', () async { |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 204 | final String projectPath = await createProject(tempDir, |
| 205 | arguments: <String>['--no-pub', '--template=module']); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 206 | removeGeneratedFiles(projectPath); |
| 207 | |
| 208 | await runCommandIn(projectPath, 'get'); |
| 209 | |
| 210 | expectDependenciesResolved(projectPath); |
| 211 | expectZeroPluginsInjected(projectPath); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 212 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 213 | Pub: () => const Pub(), |
| 214 | }); |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 215 | |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 216 | testUsingContext('get --offline fetches packages', () async { |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 217 | final String projectPath = await createProject(tempDir, |
| 218 | arguments: <String>['--no-pub', '--template=module']); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 219 | removeGeneratedFiles(projectPath); |
| 220 | |
| 221 | await runCommandIn(projectPath, 'get', args: <String>['--offline']); |
| 222 | |
| 223 | expectDependenciesResolved(projectPath); |
| 224 | expectZeroPluginsInjected(projectPath); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 225 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 226 | Pub: () => const Pub(), |
| 227 | }); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 228 | |
Emmanuel Garcia | 3bbdf01 | 2019-05-29 20:56:28 -0700 | [diff] [blame] | 229 | testUsingContext('set the number of plugins as usage value', () async { |
| 230 | final String projectPath = await createProject(tempDir, |
| 231 | arguments: <String>['--no-pub', '--template=module']); |
| 232 | removeGeneratedFiles(projectPath); |
| 233 | |
| 234 | final PackagesCommand command = await runCommandIn(projectPath, 'get'); |
| 235 | final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand; |
| 236 | |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 237 | expect(await getCommand.usageValues, |
| 238 | containsPair(CustomDimensions.commandPackagesNumberPlugins, '0')); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 239 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 240 | Pub: () => const Pub(), |
| 241 | }); |
Emmanuel Garcia | 3bbdf01 | 2019-05-29 20:56:28 -0700 | [diff] [blame] | 242 | |
| 243 | testUsingContext('indicate that the project is not a module in usage value', () async { |
| 244 | final String projectPath = await createProject(tempDir, |
| 245 | arguments: <String>['--no-pub']); |
| 246 | removeGeneratedFiles(projectPath); |
| 247 | |
| 248 | final PackagesCommand command = await runCommandIn(projectPath, 'get'); |
| 249 | final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand; |
| 250 | |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 251 | expect(await getCommand.usageValues, |
| 252 | containsPair(CustomDimensions.commandPackagesProjectModule, 'false')); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 253 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 254 | Pub: () => const Pub(), |
| 255 | }); |
Emmanuel Garcia | 3bbdf01 | 2019-05-29 20:56:28 -0700 | [diff] [blame] | 256 | |
| 257 | testUsingContext('indicate that the project is a module in usage value', () async { |
| 258 | final String projectPath = await createProject(tempDir, |
| 259 | arguments: <String>['--no-pub', '--template=module']); |
| 260 | removeGeneratedFiles(projectPath); |
| 261 | |
| 262 | final PackagesCommand command = await runCommandIn(projectPath, 'get'); |
| 263 | final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand; |
| 264 | |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 265 | expect(await getCommand.usageValues, |
| 266 | containsPair(CustomDimensions.commandPackagesProjectModule, 'true')); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 267 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 268 | Pub: () => const Pub(), |
| 269 | }); |
Emmanuel Garcia | 3bbdf01 | 2019-05-29 20:56:28 -0700 | [diff] [blame] | 270 | |
xster | ba26f92 | 2019-11-05 12:38:42 -0800 | [diff] [blame] | 271 | testUsingContext('indicate that Android project reports v1 in usage value', () async { |
| 272 | final String projectPath = await createProject(tempDir, |
| 273 | arguments: <String>['--no-pub']); |
| 274 | removeGeneratedFiles(projectPath); |
| 275 | |
| 276 | final PackagesCommand command = await runCommandIn(projectPath, 'get'); |
| 277 | final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand; |
| 278 | |
| 279 | expect(await getCommand.usageValues, |
| 280 | containsPair(CustomDimensions.commandPackagesAndroidEmbeddingVersion, 'v1')); |
| 281 | }, overrides: <Type, Generator>{ |
| 282 | FeatureFlags: () => TestFeatureFlags(isAndroidEmbeddingV2Enabled: false), |
| 283 | Pub: () => const Pub(), |
| 284 | }); |
| 285 | |
| 286 | testUsingContext('indicate that Android project reports v2 in usage value', () async { |
| 287 | final String projectPath = await createProject(tempDir, |
| 288 | arguments: <String>['--no-pub']); |
| 289 | removeGeneratedFiles(projectPath); |
| 290 | |
| 291 | final PackagesCommand command = await runCommandIn(projectPath, 'get'); |
| 292 | final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand; |
| 293 | |
| 294 | expect(await getCommand.usageValues, |
| 295 | containsPair(CustomDimensions.commandPackagesAndroidEmbeddingVersion, 'v2')); |
| 296 | }, overrides: <Type, Generator>{ |
| 297 | FeatureFlags: () => TestFeatureFlags(isAndroidEmbeddingV2Enabled: true), |
| 298 | Pub: () => const Pub(), |
| 299 | }); |
| 300 | |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 301 | testUsingContext('upgrade fetches packages', () async { |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 302 | final String projectPath = await createProject(tempDir, |
| 303 | arguments: <String>['--no-pub', '--template=module']); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 304 | removeGeneratedFiles(projectPath); |
| 305 | |
| 306 | await runCommandIn(projectPath, 'upgrade'); |
| 307 | |
| 308 | expectDependenciesResolved(projectPath); |
| 309 | expectZeroPluginsInjected(projectPath); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 310 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 311 | Pub: () => const Pub(), |
| 312 | }); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 313 | |
| 314 | testUsingContext('get fetches packages and injects plugin', () async { |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 315 | final String projectPath = await createProjectWithPlugin('path_provider', |
| 316 | arguments: <String>['--no-pub', '--template=module']); |
Mikkel Nygaard Ravn | 2000435 | 2018-02-16 10:17:28 +0100 | [diff] [blame] | 317 | removeGeneratedFiles(projectPath); |
| 318 | |
| 319 | await runCommandIn(projectPath, 'get'); |
| 320 | |
| 321 | expectDependenciesResolved(projectPath); |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 322 | expectModulePluginInjected(projectPath); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 323 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 324 | Pub: () => const Pub(), |
| 325 | }); |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 326 | |
Mikkel Nygaard Ravn | f526805 | 2018-02-17 21:25:13 +0100 | [diff] [blame] | 327 | testUsingContext('get fetches packages and injects plugin in plugin project', () async { |
| 328 | final String projectPath = await createProject( |
Ian Hickson | 3dec6a6 | 2018-08-17 13:17:23 -0700 | [diff] [blame] | 329 | tempDir, |
Greg Spencer | 9f23866 | 2018-10-04 13:03:20 -0700 | [diff] [blame] | 330 | arguments: <String>['--template=plugin', '--no-pub'], |
Mikkel Nygaard Ravn | f526805 | 2018-02-17 21:25:13 +0100 | [diff] [blame] | 331 | ); |
| 332 | final String exampleProjectPath = fs.path.join(projectPath, 'example'); |
| 333 | removeGeneratedFiles(projectPath); |
| 334 | removeGeneratedFiles(exampleProjectPath); |
| 335 | |
| 336 | await runCommandIn(projectPath, 'get'); |
| 337 | |
| 338 | expectDependenciesResolved(projectPath); |
| 339 | |
| 340 | await runCommandIn(exampleProjectPath, 'get'); |
| 341 | |
| 342 | expectDependenciesResolved(exampleProjectPath); |
| 343 | expectPluginInjected(exampleProjectPath); |
Ian Hickson | 124dc66 | 2019-10-18 16:35:39 -0700 | [diff] [blame] | 344 | }, overrides: <Type, Generator>{ |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 345 | Pub: () => const Pub(), |
| 346 | }); |
Dan Rubel | 194a9ef | 2016-08-25 22:37:48 -0400 | [diff] [blame] | 347 | }); |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 348 | |
| 349 | group('packages test/pub', () { |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 350 | MockProcessManager mockProcessManager; |
| 351 | MockStdio mockStdio; |
| 352 | |
| 353 | setUp(() { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 354 | mockProcessManager = MockProcessManager(); |
| 355 | mockStdio = MockStdio(); |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 356 | }); |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 357 | |
jcollins-g | ca67701 | 2018-02-21 09:54:07 -0800 | [diff] [blame] | 358 | testUsingContext('test without bot', () async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 359 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'test']); |
jcollins-g | ca67701 | 2018-02-21 09:54:07 -0800 | [diff] [blame] | 360 | final List<String> commands = mockProcessManager.commands; |
| 361 | expect(commands, hasLength(3)); |
| 362 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
| 363 | expect(commands[1], 'run'); |
| 364 | expect(commands[2], 'test'); |
| 365 | }, overrides: <Type, Generator>{ |
| 366 | ProcessManager: () => mockProcessManager, |
| 367 | Stdio: () => mockStdio, |
| 368 | BotDetector: () => const AlwaysFalseBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 369 | Pub: () => const Pub(), |
jcollins-g | ca67701 | 2018-02-21 09:54:07 -0800 | [diff] [blame] | 370 | }); |
| 371 | |
| 372 | testUsingContext('test with bot', () async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 373 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'test']); |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 374 | final List<String> commands = mockProcessManager.commands; |
Ian Hickson | 89566fe | 2017-09-29 17:56:25 -0700 | [diff] [blame] | 375 | expect(commands, hasLength(4)); |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 376 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Ian Hickson | 89566fe | 2017-09-29 17:56:25 -0700 | [diff] [blame] | 377 | expect(commands[1], '--trace'); |
| 378 | expect(commands[2], 'run'); |
| 379 | expect(commands[3], 'test'); |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 380 | }, overrides: <Type, Generator>{ |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 381 | ProcessManager: () => mockProcessManager, |
| 382 | Stdio: () => mockStdio, |
jcollins-g | ca67701 | 2018-02-21 09:54:07 -0800 | [diff] [blame] | 383 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 384 | Pub: () => const Pub(), |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 385 | }); |
| 386 | |
| 387 | testUsingContext('run', () async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 388 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', '--verbose', 'pub', 'run', '--foo', 'bar']); |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 389 | final List<String> commands = mockProcessManager.commands; |
| 390 | expect(commands, hasLength(4)); |
| 391 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
| 392 | expect(commands[1], 'run'); |
| 393 | expect(commands[2], '--foo'); |
| 394 | expect(commands[3], 'bar'); |
| 395 | }, overrides: <Type, Generator>{ |
| 396 | ProcessManager: () => mockProcessManager, |
| 397 | Stdio: () => mockStdio, |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 398 | Pub: () => const Pub(), |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 399 | }); |
| 400 | |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 401 | testUsingContext('pub publish', () async { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 402 | final PromptingProcess process = PromptingProcess(); |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 403 | mockProcessManager.processFactory = (List<String> commands) => process; |
Michael Thomsen | 79d8967 | 2019-08-19 08:02:13 +0100 | [diff] [blame] | 404 | final Future<void> runPackages = createTestCommandRunner(PackagesCommand()).run(<String>['pub', 'publish']); |
Alexandre Ardhuin | 2d3ff10 | 2018-10-05 07:54:56 +0200 | [diff] [blame] | 405 | final Future<void> runPrompt = process.showPrompt('Proceed (y/n)? ', <String>['hello', 'world']); |
| 406 | final Future<void> simulateUserInput = Future<void>(() { |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 407 | mockStdio.simulateStdin('y'); |
| 408 | }); |
Alexandre Ardhuin | 2d3ff10 | 2018-10-05 07:54:56 +0200 | [diff] [blame] | 409 | await Future.wait<void>(<Future<void>>[runPackages, runPrompt, simulateUserInput]); |
Mikkel Nygaard Ravn | 8303fff | 2017-09-06 11:53:39 +0200 | [diff] [blame] | 410 | final List<String> commands = mockProcessManager.commands; |
| 411 | expect(commands, hasLength(2)); |
| 412 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
| 413 | expect(commands[1], 'publish'); |
| 414 | final List<String> stdout = mockStdio.writtenToStdout; |
| 415 | expect(stdout, hasLength(4)); |
| 416 | expect(stdout.sublist(0, 2), contains('Proceed (y/n)? ')); |
| 417 | expect(stdout.sublist(0, 2), contains('y\n')); |
| 418 | expect(stdout[2], 'hello\n'); |
| 419 | expect(stdout[3], 'world\n'); |
| 420 | }, overrides: <Type, Generator>{ |
| 421 | ProcessManager: () => mockProcessManager, |
| 422 | Stdio: () => mockStdio, |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 423 | Pub: () => const Pub(), |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 424 | }); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 425 | |
| 426 | testUsingContext('publish', () async { |
Michael Thomsen | 79d8967 | 2019-08-19 08:02:13 +0100 | [diff] [blame] | 427 | await createTestCommandRunner(PackagesCommand()).run(<String>['pub', 'publish']); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 428 | final List<String> commands = mockProcessManager.commands; |
Michael Thomsen | 79d8967 | 2019-08-19 08:02:13 +0100 | [diff] [blame] | 429 | expect(commands, hasLength(2)); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 430 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Michael Thomsen | 79d8967 | 2019-08-19 08:02:13 +0100 | [diff] [blame] | 431 | expect(commands[1], 'publish'); |
| 432 | }, overrides: <Type, Generator>{ |
| 433 | ProcessManager: () => mockProcessManager, |
| 434 | Stdio: () => mockStdio, |
| 435 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 436 | Pub: () => const Pub(), |
Michael Thomsen | 79d8967 | 2019-08-19 08:02:13 +0100 | [diff] [blame] | 437 | }); |
| 438 | |
| 439 | testUsingContext('packages publish', () async { |
| 440 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'pub', 'publish']); |
| 441 | final List<String> commands = mockProcessManager.commands; |
| 442 | expect(commands, hasLength(2)); |
| 443 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
| 444 | expect(commands[1], 'publish'); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 445 | }, overrides: <Type, Generator>{ |
| 446 | ProcessManager: () => mockProcessManager, |
| 447 | Stdio: () => mockStdio, |
| 448 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 449 | Pub: () => const Pub(), |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 450 | }); |
| 451 | |
| 452 | testUsingContext('deps', () async { |
| 453 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'deps']); |
| 454 | final List<String> commands = mockProcessManager.commands; |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 455 | expect(commands, hasLength(2)); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 456 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 457 | expect(commands[1], 'deps'); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 458 | }, overrides: <Type, Generator>{ |
| 459 | ProcessManager: () => mockProcessManager, |
| 460 | Stdio: () => mockStdio, |
| 461 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 462 | Pub: () => const Pub(), |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 463 | }); |
| 464 | |
| 465 | testUsingContext('cache', () async { |
| 466 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'cache']); |
| 467 | final List<String> commands = mockProcessManager.commands; |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 468 | expect(commands, hasLength(2)); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 469 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 470 | expect(commands[1], 'cache'); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 471 | }, overrides: <Type, Generator>{ |
| 472 | ProcessManager: () => mockProcessManager, |
| 473 | Stdio: () => mockStdio, |
| 474 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 475 | Pub: () => const Pub(), |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 476 | }); |
| 477 | |
| 478 | testUsingContext('version', () async { |
| 479 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'version']); |
| 480 | final List<String> commands = mockProcessManager.commands; |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 481 | expect(commands, hasLength(2)); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 482 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 483 | expect(commands[1], 'version'); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 484 | }, overrides: <Type, Generator>{ |
| 485 | ProcessManager: () => mockProcessManager, |
| 486 | Stdio: () => mockStdio, |
| 487 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 488 | Pub: () => const Pub(), |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 489 | }); |
| 490 | |
| 491 | testUsingContext('uploader', () async { |
| 492 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'uploader']); |
| 493 | final List<String> commands = mockProcessManager.commands; |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 494 | expect(commands, hasLength(2)); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 495 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 496 | expect(commands[1], 'uploader'); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 497 | }, overrides: <Type, Generator>{ |
| 498 | ProcessManager: () => mockProcessManager, |
| 499 | Stdio: () => mockStdio, |
| 500 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 501 | Pub: () => const Pub(), |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 502 | }); |
| 503 | |
| 504 | testUsingContext('global', () async { |
| 505 | await createTestCommandRunner(PackagesCommand()).run(<String>['packages', 'global', 'list']); |
| 506 | final List<String> commands = mockProcessManager.commands; |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 507 | expect(commands, hasLength(3)); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 508 | expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub')); |
Michael Thomsen | 01a5d11 | 2019-08-23 11:16:30 +0200 | [diff] [blame] | 509 | expect(commands[1], 'global'); |
| 510 | expect(commands[2], 'list'); |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 511 | }, overrides: <Type, Generator>{ |
| 512 | ProcessManager: () => mockProcessManager, |
| 513 | Stdio: () => mockStdio, |
| 514 | BotDetector: () => const AlwaysTrueBotDetector(), |
Jonah Williams | fde2675 | 2019-10-08 14:53:28 -0700 | [diff] [blame] | 515 | Pub: () => const Pub(), |
Michael Thomsen | 811f1ad | 2019-04-09 17:03:09 +0200 | [diff] [blame] | 516 | }); |
Ian Hickson | 292abf7 | 2017-05-12 15:40:35 -0700 | [diff] [blame] | 517 | }); |
| 518 | } |