mirror of
https://github.com/flutter/packages.git
synced 2025-05-28 19:26:50 +08:00
Add a way to opt a file out of Dart formatting (#4292)
This commit is contained in:
@ -8,6 +8,7 @@ import 'package:args/command_runner.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_plugin_tools/src/common/core.dart';
|
||||
import 'package:flutter_plugin_tools/src/common/file_utils.dart';
|
||||
import 'package:flutter_plugin_tools/src/format_command.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:test/test.dart';
|
||||
@ -106,6 +107,42 @@ void main() {
|
||||
]));
|
||||
});
|
||||
|
||||
test('does not format .dart files with pragma', () async {
|
||||
const List<String> formattedFiles = <String>[
|
||||
'lib/a.dart',
|
||||
'lib/src/b.dart',
|
||||
'lib/src/c.dart',
|
||||
];
|
||||
const String unformattedFile = 'lib/src/d.dart';
|
||||
final Directory pluginDir = createFakePlugin(
|
||||
'a_plugin',
|
||||
packagesDir,
|
||||
extraFiles: <String>[
|
||||
...formattedFiles,
|
||||
unformattedFile,
|
||||
],
|
||||
);
|
||||
|
||||
final p.Context posixContext = p.posix;
|
||||
childFileWithSubcomponents(pluginDir, posixContext.split(unformattedFile))
|
||||
.writeAsStringSync(
|
||||
'// copyright bla bla\n// This file is hand-formatted.\ncode...');
|
||||
|
||||
await runCapturingPrint(runner, <String>['format']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall(
|
||||
getFlutterCommand(mockPlatform),
|
||||
<String>[
|
||||
'format',
|
||||
..._getPackagesDirRelativePaths(pluginDir, formattedFiles)
|
||||
],
|
||||
packagesDir.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('fails if flutter format fails', () async {
|
||||
const List<String> files = <String>[
|
||||
'lib/a.dart',
|
||||
|
Reference in New Issue
Block a user