@@ -169,6 +169,16 @@ void main() {
169169 ]));
170170 });
171171
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+
172182 test ('formats .java files' , () async {
173183 const List <String > files = < String > [
174184 'android/src/main/java/io/flutter/plugins/a_plugin/a.java' ,
@@ -220,7 +230,7 @@ void main() {
220230 containsAllInOrder (< Matcher > [
221231 contains (
222232 '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 .' ),
224234 ]));
225235 });
226236
@@ -250,7 +260,7 @@ void main() {
250260 ]));
251261 });
252262
253- test ('honors --java flag' , () async {
263+ test ('honors --java-path flag' , () async {
254264 const List <String > files = < String > [
255265 'android/src/main/java/io/flutter/plugins/a_plugin/a.java' ,
256266 'android/src/main/java/io/flutter/plugins/a_plugin/b.java' ,
@@ -261,7 +271,8 @@ void main() {
261271 extraFiles: files,
262272 );
263273
264- await runCapturingPrint (runner, < String > ['format' , '--java=/path/to/java' ]);
274+ await runCapturingPrint (
275+ runner, < String > ['format' , '--java-path=/path/to/java' ]);
265276
266277 expect (
267278 processRunner.recordedCalls,
@@ -279,6 +290,16 @@ void main() {
279290 ]));
280291 });
281292
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+
282303 test ('formats c-ish files' , () async {
283304 const List <String > files = < String > [
284305 'ios/Classes/Foo.h' ,
@@ -332,7 +353,7 @@ void main() {
332353 output,
333354 containsAllInOrder (< Matcher > [
334355 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 .' ),
336357 ]));
337358 });
338359
@@ -376,7 +397,7 @@ void main() {
376397 ]));
377398 });
378399
379- test ('honors --clang-format flag' , () async {
400+ test ('honors --clang-format-path flag' , () async {
380401 const List <String > files = < String > [
381402 'windows/foo_plugin.cpp' ,
382403 ];
@@ -386,8 +407,8 @@ void main() {
386407 extraFiles: files,
387408 );
388409
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' ]);
391412
392413 expect (
393414 processRunner.recordedCalls,
@@ -433,6 +454,16 @@ void main() {
433454 ]));
434455 });
435456
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+
436467 group ('kotlin-format' , () {
437468 test ('formats .kt files' , () async {
438469 const List <String > files = < String > [
@@ -487,6 +518,16 @@ void main() {
487518 contains ('Failed to format Kotlin files: exit code 1.' ),
488519 ]));
489520 });
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+ });
490531 });
491532
492533 group ('swift-format' , () {
@@ -500,20 +541,25 @@ void main() {
500541 extraFiles: files,
501542 );
502543
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+ ]);
505549
506550 expect (
507551 processRunner.recordedCalls,
508552 orderedEquals (< ProcessCall > [
553+ const ProcessCall (
554+ '/path/to/swift-format' , < String > ['--version' ], null ),
509555 ProcessCall (
510556 '/path/to/swift-format' ,
511557 < String > ['-i' , ...getPackagesDirRelativePaths (plugin, files)],
512558 packagesDir.path),
513559 ]));
514560 });
515561
516- test ('skips Swift if --swift-format flag is not provided' , () async {
562+ test ('skips Swift if --swift flag is not provided' , () async {
517563 const List <String > files = < String > [
518564 'macos/foo.swift' ,
519565 ];
@@ -528,6 +574,33 @@ void main() {
528574 expect (processRunner.recordedCalls, orderedEquals (< ProcessCall > []));
529575 });
530576
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+
531604 test ('fails if swift-format fails' , () async {
532605 const List <String > files = < String > [
533606 'macos/foo.swift' ,
@@ -536,12 +609,16 @@ void main() {
536609
537610 processRunner.mockProcessesForExecutable['swift-format' ] =
538611 < FakeProcessInfo > [
612+ FakeProcessInfo (MockProcess (),
613+ < String > ['--version' ]), // check for working swift-format
539614 FakeProcessInfo (MockProcess (exitCode: 1 ), < String > ['-i' ]),
540615 ];
541616 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) {
545622 commandError = e;
546623 });
547624
0 commit comments