@@ -7,6 +7,7 @@ import 'package:dart_dev/src/dart_dev_tool.dart';
77import 'package:glob/glob.dart' ;
88import 'package:io/io.dart' ;
99import 'package:logging/logging.dart' ;
10+ import 'package:path/path.dart' as p;
1011import 'package:test/test.dart' ;
1112
1213import 'package:dart_dev/src/tools/format_tool.dart' ;
@@ -15,7 +16,7 @@ import '../log_matchers.dart';
1516import 'shared_tool_tests.dart' ;
1617
1718void main () {
18- group ('FormatCommand ' , () {
19+ group ('FormatTool ' , () {
1920 sharedDevToolTests (() => FormatTool ());
2021
2122 test ('toCommand overrides the argParser' , () {
@@ -37,6 +38,73 @@ void main() {
3738
3839 expect (argParser.options['formatter-args' ].type, OptionType .single);
3940 });
41+
42+ group ('getInputs' , () {
43+ final root = 'test/tools/fixtures/format/globs' ;
44+
45+ test ('no excludes' , () {
46+ final formatterInputs = FormatTool .getInputs (root: root);
47+ expect (formatterInputs.includedFiles, unorderedEquals ({'.' }));
48+ expect (formatterInputs.excludedFiles, null );
49+ expect (formatterInputs.hiddenDirectories, null );
50+ expect (formatterInputs.skippedLinks, null );
51+ });
52+
53+ test ('custom excludes' , () {
54+ FormatterInputs formatterInputs =
55+ FormatTool .getInputs (exclude: [Glob ('*_exclude.dart' )], root: root);
56+
57+ expect (
58+ formatterInputs.includedFiles,
59+ unorderedEquals ({
60+ 'file.dart' ,
61+ 'lib/sub/file.dart' ,
62+ 'linked.dart' ,
63+ 'other/file.dart' ,
64+ }));
65+
66+ expect (formatterInputs.excludedFiles,
67+ unorderedEquals ({'should_exclude.dart' }));
68+ expect (formatterInputs.hiddenDirectories,
69+ unorderedEquals ({'.dart_tool_test' }));
70+ expect (formatterInputs.skippedLinks,
71+ unorderedEquals ({'links/lib-link' , 'links/link.dart' }));
72+ });
73+
74+ test ('empty inputs due to excludes config' , () async {
75+ expect (
76+ FormatTool .getInputs (exclude: [Glob ('**' )], root: root)
77+ .includedFiles,
78+ isEmpty);
79+ });
80+
81+ test ('expandCwd forces . to be expanded to all files' , () async {
82+ final formatterInputs =
83+ FormatTool .getInputs (expandCwd: true , root: root);
84+ expect (
85+ formatterInputs.includedFiles,
86+ unorderedEquals ({
87+ 'file.dart' ,
88+ 'lib/sub/file.dart' ,
89+ 'linked.dart' ,
90+ 'other/file.dart' ,
91+ 'should_exclude.dart' ,
92+ }));
93+ expect (formatterInputs.excludedFiles, isEmpty);
94+ });
95+
96+ test ('followLinks follows linked files and directories' , () async {
97+ final formatterInputs = FormatTool .getInputs (
98+ expandCwd: true , followLinks: true , root: p.join (root, 'links' ));
99+ expect (
100+ formatterInputs.includedFiles,
101+ unorderedEquals ({
102+ 'lib-link/sub/file.dart' ,
103+ 'link.dart' ,
104+ }));
105+ expect (formatterInputs.skippedLinks, isEmpty);
106+ });
107+ });
40108 });
41109
42110 group ('buildArgs' , () {
@@ -217,57 +285,6 @@ void main() {
217285 });
218286 });
219287
220- group ('getFormatterInputs' , () {
221- final root = 'test/tools/fixtures/format/globs' ;
222-
223- test ('no excludes' , () {
224- final formatterInputs = FormatTool .getInputs (root: root);
225- expect (formatterInputs.includedFiles, unorderedEquals ({'.' }));
226- expect (formatterInputs.excludedFiles, null );
227- expect (formatterInputs.hiddenDirectories, null );
228- expect (formatterInputs.skippedLinks, null );
229- });
230-
231- test ('custom excludes' , () {
232- FormatterInputs formatterInputs =
233- FormatTool .getInputs (exclude: [Glob ('*_exclude.dart' )], root: root);
234-
235- expect (
236- formatterInputs.includedFiles,
237- unorderedEquals ({
238- 'file.dart' ,
239- 'lib/sub/file.dart' ,
240- 'other/file.dart' ,
241- }));
242-
243- expect (formatterInputs.excludedFiles,
244- unorderedEquals ({'should_exclude.dart' }));
245- expect (formatterInputs.hiddenDirectories,
246- unorderedEquals ({'.dart_tool_test' }));
247- expect (formatterInputs.skippedLinks,
248- unorderedEquals ({'lib-link' , 'link.dart' }));
249- });
250-
251- test ('empty inputs due to excludes config' , () async {
252- expect (
253- FormatTool .getInputs (exclude: [Glob ('**' )], root: root).includedFiles,
254- isEmpty);
255- });
256-
257- test ('expandCwd forces . to be expanded to all files' , () async {
258- final formatterInputs = FormatTool .getInputs (expandCwd: true , root: root);
259- expect (
260- formatterInputs.includedFiles,
261- unorderedEquals ({
262- 'file.dart' ,
263- 'lib/sub/file.dart' ,
264- 'other/file.dart' ,
265- 'should_exclude.dart' ,
266- }));
267- expect (formatterInputs.excludedFiles, isEmpty);
268- });
269- });
270-
271288 group ('buildProcess' , () {
272289 test ('dartfmt' , () {
273290 final process = buildProcess (Formatter .dartfmt);
0 commit comments