@@ -169,6 +169,16 @@ void main() {
169
169
]));
170
170
});
171
171
172
+ test ('skips dart if --no-dart flag is provided' , () async {
173
+ const List <String > files = < String > [
174
+ 'lib/a.dart' ,
175
+ ];
176
+ createFakePlugin ('a_plugin' , packagesDir, extraFiles: files);
177
+
178
+ await runCapturingPrint (runner, < String > ['format' , '--no-dart' ]);
179
+ expect (processRunner.recordedCalls, orderedEquals (< ProcessCall > []));
180
+ });
181
+
172
182
test ('formats .java files' , () async {
173
183
const List <String > files = < String > [
174
184
'android/src/main/java/io/flutter/plugins/a_plugin/a.java' ,
@@ -220,7 +230,7 @@ void main() {
220
230
containsAllInOrder (< Matcher > [
221
231
contains (
222
232
'Unable to run "java". Make sure that it is in your path, or '
223
- 'provide a full path with --java.' ),
233
+ 'provide a full path with --java-path .' ),
224
234
]));
225
235
});
226
236
@@ -250,7 +260,7 @@ void main() {
250
260
]));
251
261
});
252
262
253
- test ('honors --java flag' , () async {
263
+ test ('honors --java-path flag' , () async {
254
264
const List <String > files = < String > [
255
265
'android/src/main/java/io/flutter/plugins/a_plugin/a.java' ,
256
266
'android/src/main/java/io/flutter/plugins/a_plugin/b.java' ,
@@ -261,7 +271,8 @@ void main() {
261
271
extraFiles: files,
262
272
);
263
273
264
- await runCapturingPrint (runner, < String > ['format' , '--java=/path/to/java' ]);
274
+ await runCapturingPrint (
275
+ runner, < String > ['format' , '--java-path=/path/to/java' ]);
265
276
266
277
expect (
267
278
processRunner.recordedCalls,
@@ -279,6 +290,16 @@ void main() {
279
290
]));
280
291
});
281
292
293
+ test ('skips Java if --no-java flag is provided' , () async {
294
+ const List <String > files = < String > [
295
+ 'android/src/main/java/io/flutter/plugins/a_plugin/a.java' ,
296
+ ];
297
+ createFakePlugin ('a_plugin' , packagesDir, extraFiles: files);
298
+
299
+ await runCapturingPrint (runner, < String > ['format' , '--no-java' ]);
300
+ expect (processRunner.recordedCalls, orderedEquals (< ProcessCall > []));
301
+ });
302
+
282
303
test ('formats c-ish files' , () async {
283
304
const List <String > files = < String > [
284
305
'ios/Classes/Foo.h' ,
@@ -332,7 +353,7 @@ void main() {
332
353
output,
333
354
containsAllInOrder (< Matcher > [
334
355
contains ('Unable to run "clang-format". Make sure that it is in your '
335
- 'path, or provide a full path with --clang-format.' ),
356
+ 'path, or provide a full path with --clang-format-path .' ),
336
357
]));
337
358
});
338
359
@@ -376,7 +397,7 @@ void main() {
376
397
]));
377
398
});
378
399
379
- test ('honors --clang-format flag' , () async {
400
+ test ('honors --clang-format-path flag' , () async {
380
401
const List <String > files = < String > [
381
402
'windows/foo_plugin.cpp' ,
382
403
];
@@ -386,8 +407,8 @@ void main() {
386
407
extraFiles: files,
387
408
);
388
409
389
- await runCapturingPrint (
390
- runner, < String > ['format' , '--clang-format=/path/to/clang-format' ]);
410
+ await runCapturingPrint (runner,
411
+ < String > ['format' , '--clang-format-path =/path/to/clang-format' ]);
391
412
392
413
expect (
393
414
processRunner.recordedCalls,
@@ -433,6 +454,16 @@ void main() {
433
454
]));
434
455
});
435
456
457
+ test ('skips clang-format if --no-clang-format flag is provided' , () async {
458
+ const List <String > files = < String > [
459
+ 'linux/foo_plugin.cc' ,
460
+ ];
461
+ createFakePlugin ('a_plugin' , packagesDir, extraFiles: files);
462
+
463
+ await runCapturingPrint (runner, < String > ['format' , '--no-clang-format' ]);
464
+ expect (processRunner.recordedCalls, orderedEquals (< ProcessCall > []));
465
+ });
466
+
436
467
group ('kotlin-format' , () {
437
468
test ('formats .kt files' , () async {
438
469
const List <String > files = < String > [
@@ -487,6 +518,16 @@ void main() {
487
518
contains ('Failed to format Kotlin files: exit code 1.' ),
488
519
]));
489
520
});
521
+
522
+ test ('skips Kotlin if --no-kotlin flag is provided' , () async {
523
+ const List <String > files = < String > [
524
+ 'android/src/main/kotlin/io/flutter/plugins/a_plugin/a.kt' ,
525
+ ];
526
+ createFakePlugin ('a_plugin' , packagesDir, extraFiles: files);
527
+
528
+ await runCapturingPrint (runner, < String > ['format' , '--no-kotlin' ]);
529
+ expect (processRunner.recordedCalls, orderedEquals (< ProcessCall > []));
530
+ });
490
531
});
491
532
492
533
group ('swift-format' , () {
@@ -500,20 +541,25 @@ void main() {
500
541
extraFiles: files,
501
542
);
502
543
503
- await runCapturingPrint (
504
- runner, < String > ['format' , '--swift-format=/path/to/swift-format' ]);
544
+ await runCapturingPrint (runner, < String > [
545
+ 'format' ,
546
+ '--swift' ,
547
+ '--swift-format-path=/path/to/swift-format'
548
+ ]);
505
549
506
550
expect (
507
551
processRunner.recordedCalls,
508
552
orderedEquals (< ProcessCall > [
553
+ const ProcessCall (
554
+ '/path/to/swift-format' , < String > ['--version' ], null ),
509
555
ProcessCall (
510
556
'/path/to/swift-format' ,
511
557
< String > ['-i' , ...getPackagesDirRelativePaths (plugin, files)],
512
558
packagesDir.path),
513
559
]));
514
560
});
515
561
516
- test ('skips Swift if --swift-format flag is not provided' , () async {
562
+ test ('skips Swift if --swift flag is not provided' , () async {
517
563
const List <String > files = < String > [
518
564
'macos/foo.swift' ,
519
565
];
@@ -528,6 +574,33 @@ void main() {
528
574
expect (processRunner.recordedCalls, orderedEquals (< ProcessCall > []));
529
575
});
530
576
577
+ test ('fails with a clear message if swift-format is not in the path' ,
578
+ () async {
579
+ const List <String > files = < String > [
580
+ 'macos/foo.swift' ,
581
+ ];
582
+ createFakePlugin ('a_plugin' , packagesDir, extraFiles: files);
583
+
584
+ processRunner.mockProcessesForExecutable['swift-format' ] =
585
+ < FakeProcessInfo > [
586
+ FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['--version' ]),
587
+ ];
588
+ Error ? commandError;
589
+ final List <String > output = await runCapturingPrint (
590
+ runner, < String > ['format' , '--swift' ], errorHandler: (Error e) {
591
+ commandError = e;
592
+ });
593
+
594
+ expect (commandError, isA <ToolExit >());
595
+ expect (
596
+ output,
597
+ containsAllInOrder (< Matcher > [
598
+ contains (
599
+ 'Unable to run "swift-format". Make sure that it is in your path, or '
600
+ 'provide a full path with --swift-format-path.' ),
601
+ ]));
602
+ });
603
+
531
604
test ('fails if swift-format fails' , () async {
532
605
const List <String > files = < String > [
533
606
'macos/foo.swift' ,
@@ -536,12 +609,16 @@ void main() {
536
609
537
610
processRunner.mockProcessesForExecutable['swift-format' ] =
538
611
< FakeProcessInfo > [
612
+ FakeProcessInfo (MockProcess (),
613
+ < String > ['--version' ]), // check for working swift-format
539
614
FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['-i' ]),
540
615
];
541
616
Error ? commandError;
542
- final List <String > output = await runCapturingPrint (
543
- runner, < String > ['format' , '--swift-format=swift-format' ],
544
- errorHandler: (Error e) {
617
+ final List <String > output = await runCapturingPrint (runner, < String > [
618
+ 'format' ,
619
+ '--swift' ,
620
+ '--swift-format-path=swift-format'
621
+ ], errorHandler: (Error e) {
545
622
commandError = e;
546
623
});
547
624
0 commit comments