[flutter_tools] fix -n workaround (#86142)

This commit is contained in:
Jonah Williams
2021-07-09 09:41:04 -07:00
committed by GitHub
parent 75f6d03b55
commit 9d70d9d589
2 changed files with 19 additions and 2 deletions

View File

@@ -47,8 +47,8 @@ class FormatCommand extends FlutterCommand {
} else {
command.addAll(<String>[
for (String arg in argResults.rest)
if (arg == '--dry-run')
'--output=show'
if (arg == '--dry-run' || arg == '-n')
'--output=none'
else
arg
]);

View File

@@ -59,6 +59,23 @@ void main() {
expect(shouldNotFormatted, nonFormatted);
});
testUsingContext('dry-run with -n', () async {
final String projectPath = await createProject(tempDir);
final File srcFile = globals.fs.file(
globals.fs.path.join(projectPath, 'lib', 'main.dart'));
final String nonFormatted = srcFile.readAsStringSync().replaceFirst(
'main()', 'main( )');
srcFile.writeAsStringSync(nonFormatted);
final FormatCommand command = FormatCommand(verboseHelp: false);
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['format', '-n', srcFile.path]);
final String shouldNotFormatted = srcFile.readAsStringSync();
expect(shouldNotFormatted, nonFormatted);
});
testUsingContext('dry-run with set-exit-if-changed', () async {
final String projectPath = await createProject(tempDir);