44
55import 'package:args/command_runner.dart' ;
66import 'package:flutter_tools/src/base/file_system.dart' ;
7- import 'package:flutter_tools/src/base/io .dart' ;
7+ import 'package:flutter_tools/src/base/logger .dart' ;
88import 'package:flutter_tools/src/cache.dart' ;
99import 'package:flutter_tools/src/commands/format.dart' ;
1010import 'package:flutter_tools/src/globals.dart' as globals;
1111
1212import '../../src/common.dart' ;
1313import '../../src/context.dart' ;
14- import '../../src/fakes.dart' ;
1514import '../../src/test_flutter_command_runner.dart' ;
1615
1716void main () {
1817 group ('format' , () {
1918 late Directory tempDir;
20- late FakeStdio mockStdio ;
19+ late BufferLogger logger ;
2120
2221 setUp (() {
2322 Cache .disableLocking ();
2423 tempDir = globals.fs.systemTempDirectory.createTempSync ('flutter_tools_format_test.' );
25- mockStdio = FakeStdio ();
24+ logger = BufferLogger . test ();
2625 });
2726
2827 tearDown (() {
2928 tryToDelete (tempDir);
3029 });
3130
31+ testUsingContext ('shows deprecation warning' , () async {
32+ final String projectPath = await createProject (tempDir);
33+
34+ final File srcFile = globals.fs.file (globals.fs.path.join (projectPath, 'lib' , 'main.dart' ));
35+ final String original = srcFile.readAsStringSync ();
36+ srcFile.writeAsStringSync (original);
37+
38+ final FormatCommand command = FormatCommand (verboseHelp: false );
39+ final CommandRunner <void > runner = createTestCommandRunner (command);
40+ await runner.run (< String > ['format' , srcFile.path]);
41+ expect (
42+ logger.warningText,
43+ contains ('The "format" command is deprecated and will be removed in a future version of Flutter' ),
44+ );
45+ }, overrides: < Type , Generator > {
46+ Logger : () => logger,
47+ });
48+
3249 testUsingContext ('a file' , () async {
3350 final String projectPath = await createProject (tempDir);
3451
@@ -43,7 +60,7 @@ void main() {
4360 final String formatted = srcFile.readAsStringSync ();
4461 expect (formatted, original);
4562 }, overrides: < Type , Generator > {
46- Stdio : () => mockStdio ,
63+ Logger : () => logger ,
4764 });
4865
4966 testUsingContext ('dry-run' , () async {
@@ -61,6 +78,8 @@ void main() {
6178
6279 final String shouldNotFormatted = srcFile.readAsStringSync ();
6380 expect (shouldNotFormatted, nonFormatted);
81+ }, overrides: < Type , Generator > {
82+ Logger : () => logger,
6483 });
6584
6685 testUsingContext ('dry-run with -n' , () async {
0 commit comments