@@ -104,6 +104,7 @@ void main() {
104104 debuggingOptions: anyNamed ('debuggingOptions' ),
105105 packagesFilePath: anyNamed ('packagesFilePath' ),
106106 usesTerminalUI: anyNamed ('usesTerminalUI' ),
107+ ipv6: false ,
107108 ),
108109 )..thenReturn (MockHotRunner ());
109110
@@ -134,6 +135,7 @@ void main() {
134135 debuggingOptions: anyNamed ('debuggingOptions' ),
135136 packagesFilePath: anyNamed ('packagesFilePath' ),
136137 usesTerminalUI: anyNamed ('usesTerminalUI' ),
138+ ipv6: false ,
137139 ),
138140 )..called (1 );
139141
@@ -150,6 +152,21 @@ void main() {
150152 }, overrides: < Type , Generator > {
151153 FileSystem : () => testFileSystem,
152154 });
155+
156+ testUsingContext ('exits when ipv6 is specified and debug-port is not' , () async {
157+ testDeviceManager.addDevice (device);
158+
159+ final AttachCommand command = AttachCommand ();
160+ await expectLater (
161+ createTestCommandRunner (command).run (< String > ['attach' , '--ipv6' ]),
162+ throwsToolExit (
163+ message: 'When the --debug-port is unknown, this command determines '
164+ 'the value of --ipv6 on its own.' ,
165+ ),
166+ );
167+ }, overrides: < Type , Generator > {
168+ FileSystem : () => testFileSystem,
169+ },);
153170 });
154171
155172
@@ -170,7 +187,8 @@ void main() {
170187 target: anyNamed ('target' ),
171188 debuggingOptions: anyNamed ('debuggingOptions' ),
172189 packagesFilePath: anyNamed ('packagesFilePath' ),
173- usesTerminalUI: anyNamed ('usesTerminalUI' ))).thenReturn (
190+ usesTerminalUI: anyNamed ('usesTerminalUI' ),
191+ ipv6: false )).thenReturn (
174192 MockHotRunner ());
175193
176194 testDeviceManager.addDevice (device);
@@ -199,33 +217,92 @@ void main() {
199217 target: foo.path,
200218 debuggingOptions: anyNamed ('debuggingOptions' ),
201219 packagesFilePath: anyNamed ('packagesFilePath' ),
202- usesTerminalUI: anyNamed ('usesTerminalUI' ))).called (1 );
220+ usesTerminalUI: anyNamed ('usesTerminalUI' ),
221+ ipv6: false )).called (1 );
203222 }, overrides: < Type , Generator > {
204223 FileSystem : () => testFileSystem,
205224 },);
206225
207- testUsingContext ( 'forwards to given port' , () async {
226+ group ( 'forwarding to given port' , () {
208227 const int devicePort = 499 ;
209228 const int hostPort = 42 ;
210- final MockPortForwarder portForwarder = MockPortForwarder () ;
211- final MockAndroidDevice device = MockAndroidDevice () ;
229+ MockPortForwarder portForwarder;
230+ MockAndroidDevice device;
212231
213- when (device.portForwarder).thenReturn (portForwarder);
214- when (portForwarder.forward (devicePort)).thenAnswer ((_) async => hostPort);
215- when (portForwarder.forwardedPorts).thenReturn (
216- < ForwardedPort > [ForwardedPort (hostPort, devicePort)]);
217- when (portForwarder.unforward (any)).thenAnswer ((_) async => null );
218- testDeviceManager.addDevice (device);
232+ setUp (() {
233+ portForwarder = MockPortForwarder ();
234+ device = MockAndroidDevice ();
219235
220- final AttachCommand command = AttachCommand ();
236+ when (device.portForwarder).thenReturn (portForwarder);
237+ when (portForwarder.forward (devicePort)).thenAnswer ((_) async => hostPort);
238+ when (portForwarder.forwardedPorts).thenReturn (
239+ < ForwardedPort > [ForwardedPort (hostPort, devicePort)]);
240+ when (portForwarder.unforward (any)).thenAnswer ((_) async => null );
241+ });
221242
222- await createTestCommandRunner (command).run (
223- < String > ['attach' , '--debug-port' , '$devicePort ' ]);
243+ testUsingContext ('succeeds in ipv4 mode' , () async {
244+ testDeviceManager.addDevice (device);
245+ final AttachCommand command = AttachCommand ();
224246
225- verify (portForwarder.forward (devicePort)).called (1 );
226- }, overrides: < Type , Generator > {
227- FileSystem : () => testFileSystem,
228- },);
247+ await createTestCommandRunner (command).run (
248+ < String > ['attach' , '--debug-port' , '$devicePort ' ]);
249+
250+ verify (portForwarder.forward (devicePort)).called (1 );
251+ }, overrides: < Type , Generator > {
252+ FileSystem : () => testFileSystem,
253+ });
254+
255+ testUsingContext ('succeeds in ipv6 mode' , () async {
256+ testDeviceManager.addDevice (device);
257+ final AttachCommand command = AttachCommand ();
258+
259+ await createTestCommandRunner (command).run (
260+ < String > ['attach' , '--debug-port' , '$devicePort ' , '--ipv6' ]);
261+
262+ verify (portForwarder.forward (devicePort)).called (1 );
263+ }, overrides: < Type , Generator > {
264+ FileSystem : () => testFileSystem,
265+ });
266+
267+ testUsingContext ('skips in ipv4 mode with a provided observatory port' , () async {
268+ testDeviceManager.addDevice (device);
269+ final AttachCommand command = AttachCommand ();
270+
271+ await createTestCommandRunner (command).run (
272+ < String > [
273+ 'attach' ,
274+ '--debug-port' ,
275+ '$devicePort ' ,
276+ '--observatory-port' ,
277+ '$hostPort ' ,
278+ ],
279+ );
280+
281+ verifyNever (portForwarder.forward (devicePort));
282+ }, overrides: < Type , Generator > {
283+ FileSystem : () => testFileSystem,
284+ });
285+
286+ testUsingContext ('skips in ipv6 mode with a provided observatory port' , () async {
287+ testDeviceManager.addDevice (device);
288+ final AttachCommand command = AttachCommand ();
289+
290+ await createTestCommandRunner (command).run (
291+ < String > [
292+ 'attach' ,
293+ '--debug-port' ,
294+ '$devicePort ' ,
295+ '--observatory-port' ,
296+ '$hostPort ' ,
297+ '--ipv6' ,
298+ ],
299+ );
300+
301+ verifyNever (portForwarder.forward (devicePort));
302+ }, overrides: < Type , Generator > {
303+ FileSystem : () => testFileSystem,
304+ });
305+ });
229306
230307 testUsingContext ('exits when no device connected' , () async {
231308 final AttachCommand command = AttachCommand ();
0 commit comments