Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
420 changes: 221 additions & 199 deletions ci/bin/format.dart

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions ci/test/format_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,32 @@ class FileContentPair {
}

final FileContentPair ccContentPair = FileContentPair(
'int main(){return 0;}\n', 'int main() {\n return 0;\n}\n');
final FileContentPair hContentPair =
FileContentPair('int\nmain\n()\n;\n', 'int main();\n');
'int main(){return 0;}\n',
'int main() {\n return 0;\n}\n',
);
final FileContentPair hContentPair = FileContentPair('int\nmain\n()\n;\n', 'int main();\n');
final FileContentPair dartContentPair = FileContentPair(
'enum \n\nfoo {\n entry1,\n entry2,\n}', 'enum foo { entry1, entry2 }\n');
'enum \n\nfoo {\n entry1,\n entry2,\n}',
'enum foo { entry1, entry2 }\n',
);
final FileContentPair gnContentPair = FileContentPair(
'test\n(){testvar=true}\n', 'test() {\n testvar = true\n}\n');
'test\n(){testvar=true}\n',
'test() {\n testvar = true\n}\n',
);
final FileContentPair javaContentPair = FileContentPair(
'class Test{public static void main(String args[]){System.out.println("Test");}}\n',
'class Test {\n public static void main(String args[]) {\n System.out.println("Test");\n }\n}\n');
'class Test{public static void main(String args[]){System.out.println("Test");}}\n',
'class Test {\n public static void main(String args[]) {\n System.out.println("Test");\n }\n}\n',
);
final FileContentPair pythonContentPair = FileContentPair(
"if __name__=='__main__':\n sys.exit(\nMain(sys.argv)\n)\n",
"if __name__ == '__main__':\n sys.exit(Main(sys.argv))\n");
"if __name__=='__main__':\n sys.exit(\nMain(sys.argv)\n)\n",
"if __name__ == '__main__':\n sys.exit(Main(sys.argv))\n",
);
final FileContentPair whitespaceContentPair = FileContentPair(
'int main() {\n return 0; \n}\n', 'int main() {\n return 0;\n}\n');
'int main() {\n return 0; \n}\n',
'int main() {\n return 0;\n}\n',
);
final FileContentPair headerContentPair = FileContentPair(
<String>[
'#ifndef FOO_H_',
'#define FOO_H_',
'',
'#endif // FOO_H_',
].join('\n'),
<String>['#ifndef FOO_H_', '#define FOO_H_', '', '#endif // FOO_H_'].join('\n'),
<String>[
'#ifndef FLUTTER_FORMAT_TEST_H_',
'#define FLUTTER_FORMAT_TEST_H_',
Expand Down Expand Up @@ -118,55 +122,37 @@ class TestFileFixture {
case target.FormatCheck.clang:
return FileContentPair(
content,
path.extension(file.path) == '.cc'
? ccContentPair.formatted
: hContentPair.formatted,
path.extension(file.path) == '.cc' ? ccContentPair.formatted : hContentPair.formatted,
);
case target.FormatCheck.dart:
return FileContentPair(
content,
dartContentPair.formatted,
);
return FileContentPair(content, dartContentPair.formatted);
case target.FormatCheck.gn:
return FileContentPair(
content,
gnContentPair.formatted,
);
return FileContentPair(content, gnContentPair.formatted);
case target.FormatCheck.java:
return FileContentPair(
content,
javaContentPair.formatted,
);
return FileContentPair(content, javaContentPair.formatted);
case target.FormatCheck.python:
return FileContentPair(
content,
pythonContentPair.formatted,
);
return FileContentPair(content, pythonContentPair.formatted);
case target.FormatCheck.whitespace:
return FileContentPair(
content,
whitespaceContentPair.formatted,
);
return FileContentPair(content, whitespaceContentPair.formatted);
case target.FormatCheck.header:
return FileContentPair(
content,
headerContentPair.formatted,
);
return FileContentPair(content, headerContentPair.formatted);
}
});
}
}

void main() {
final String formatterPath =
'${repoDir.path}/ci/format.${io.Platform.isWindows ? 'bat' : 'sh'}';
final String formatterPath = '${repoDir.path}/ci/format.${io.Platform.isWindows ? 'bat' : 'sh'}';

test('Can fix C++ formatting errors', () {
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.clang);
try {
fixture.gitAdd();
io.Process.runSync(formatterPath, <String>['--check', 'clang', '--fix'],
workingDirectory: repoDir.path);
io.Process.runSync(formatterPath, <String>[
'--check',
'clang',
'--fix',
], workingDirectory: repoDir.path);

final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
Expand All @@ -181,8 +167,11 @@ void main() {
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.dart);
try {
fixture.gitAdd();
io.Process.runSync(formatterPath, <String>['--check', 'dart', '--fix'],
workingDirectory: repoDir.path);
io.Process.runSync(formatterPath, <String>[
'--check',
'dart',
'--fix',
], workingDirectory: repoDir.path);

final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
Expand All @@ -201,10 +190,11 @@ void main() {

try {
fixture.gitAdd();
final io.ProcessResult result = io.Process.runSync(
formatterPath, <String>['--check', 'dart', '--fix'],
workingDirectory: repoDir.path,
);
final io.ProcessResult result = io.Process.runSync(formatterPath, <String>[
'--check',
'dart',
'--fix',
], workingDirectory: repoDir.path);
expect(result.stdout, contains('format_test2.dart produced the following error'));
expect(result.exitCode, isNot(0));
} finally {
Expand All @@ -216,8 +206,11 @@ void main() {
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.gn);
try {
fixture.gitAdd();
io.Process.runSync(formatterPath, <String>['--check', 'gn', '--fix'],
workingDirectory: repoDir.path);
io.Process.runSync(formatterPath, <String>[
'--check',
'gn',
'--fix',
], workingDirectory: repoDir.path);

final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
Expand All @@ -232,8 +225,11 @@ void main() {
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.java);
try {
fixture.gitAdd();
io.Process.runSync(formatterPath, <String>['--check', 'java', '--fix'],
workingDirectory: repoDir.path);
io.Process.runSync(formatterPath, <String>[
'--check',
'java',
'--fix',
], workingDirectory: repoDir.path);

final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
Expand All @@ -248,8 +244,11 @@ void main() {
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.python);
try {
fixture.gitAdd();
io.Process.runSync(formatterPath, <String>['--check', 'python', '--fix'],
workingDirectory: repoDir.path);
io.Process.runSync(formatterPath, <String>[
'--check',
'python',
'--fix',
], workingDirectory: repoDir.path);

final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
Expand All @@ -261,13 +260,14 @@ void main() {
});

test('Can fix whitespace formatting errors', () {
final TestFileFixture fixture =
TestFileFixture(target.FormatCheck.whitespace);
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.whitespace);
try {
fixture.gitAdd();
io.Process.runSync(
formatterPath, <String>['--check', 'whitespace', '--fix'],
workingDirectory: repoDir.path);
io.Process.runSync(formatterPath, <String>[
'--check',
'whitespace',
'--fix',
], workingDirectory: repoDir.path);

final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
Expand All @@ -282,11 +282,11 @@ void main() {
final TestFileFixture fixture = TestFileFixture(target.FormatCheck.header);
try {
fixture.gitAdd();
io.Process.runSync(
formatterPath,
<String>['--check', 'header', '--fix'],
workingDirectory: repoDir.path,
);
io.Process.runSync(formatterPath, <String>[
'--check',
'header',
'--fix',
], workingDirectory: repoDir.path);
final Iterable<FileContentPair> files = fixture.getFileContents();
for (final FileContentPair pair in files) {
expect(pair.original, equals(pair.formatted));
Expand Down
17 changes: 6 additions & 11 deletions examples/glfw/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter_gpu/gpu.dart' as gpu;
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;

void main() {
// Ensure Flutter GPU symbols are available by forcing the GPU context to instantiate.
Expand All @@ -14,8 +13,9 @@ void main() {
gpu.gpuContext; // Force the context to instantiate.
} catch (e) {
// If impeller is not enabled, make sure the exception isn't about symbols missing.
assert(e.toString().contains(
'Flutter GPU requires the Impeller rendering backend to be enabled.'));
assert(
e.toString().contains('Flutter GPU requires the Impeller rendering backend to be enabled.'),
);
}

// This is a hack to make Flutter think you are running on Google Fuchsia,
Expand Down Expand Up @@ -113,13 +113,8 @@ class _MyHomePageState extends State<MyHomePage> {
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
Text('You have pushed the button this many times:'),
Text('$_counter', style: Theme.of(context).textTheme.headlineMedium),
],
),
),
Expand Down
8 changes: 2 additions & 6 deletions examples/glfw_drm/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;
import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride;
import 'package:flutter_spinkit/flutter_spinkit.dart';


void main() {
// This is a hack to make Flutter think you are running on Google Fuchsia,
// otherwise you will get an error about running from an unsupported platform.
Expand Down Expand Up @@ -71,9 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: RepaintBoundary(
child: SpinKitRotatingCircle(color: Colors.blue, size: 50.0),
),
child: RepaintBoundary(child: SpinKitRotatingCircle(color: Colors.blue, size: 50.0)),
),
);
}
Expand Down
69 changes: 32 additions & 37 deletions flutter_frontend_server/test/to_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ void main() {
if (buildDir == null) {
fail('No build directory found. Set FLUTTER_BUILD_DIRECTORY');
}
final frontendServer = path.join(
buildDir,
'gen',
'frontend_server_aot.dart.snapshot',
);
final sdkRoot = path.join(
buildDir,
'flutter_patched_sdk',
);
final frontendServer = path.join(buildDir, 'gen', 'frontend_server_aot.dart.snapshot');
final sdkRoot = path.join(buildDir, 'flutter_patched_sdk');

final String dart = io.Platform.resolvedExecutable;
final String dartaotruntime = path.join(
Expand All @@ -35,11 +28,7 @@ void main() {
final basePath = path.join(engineDir, 'flutter_frontend_server');
final fixtures = path.join(basePath, 'test', 'fixtures');
final mainDart = path.join(fixtures, 'lib', 'main.dart');
final packageConfig = path.join(
fixtures,
'.dart_tool',
'package_config.json',
);
final packageConfig = path.join(fixtures, '.dart_tool', 'package_config.json');
final regularDill = path.join(fixtures, 'toString.dill');
final transformedDill = path.join(fixtures, 'toStringTransformed.dill');

Expand All @@ -50,23 +39,26 @@ void main() {
}

test('Without flag', () {
checkProcessResult(io.Process.runSync(dartaotruntime, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
'--packages=$packageConfig',
'--output-dill=$regularDill',
mainDart,
]));
checkProcessResult(
io.Process.runSync(dartaotruntime, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
'--packages=$packageConfig',
'--output-dill=$regularDill',
mainDart,
]),
);
final runResult = io.Process.runSync(dart, <String>[regularDill]);
checkProcessResult(runResult);
var paintString =
'"Paint.toString":"Paint(Color(alpha: 1.0000, red: 1.0000, green: 1.0000, blue: 1.0000, colorSpace: ColorSpace.sRGB))"';
'"Paint.toString":"Paint(Color(alpha: 1.0000, red: 1.0000, green: 1.0000, blue: 1.0000, colorSpace: ColorSpace.sRGB))"';
if (buildDir.contains('release')) {
paintString = '"Paint.toString":"Instance of \'Paint\'"';
}

final String expectedStdout = '{$paintString,'
final String expectedStdout =
'{$paintString,'
'"Brightness.toString":"Brightness.dark",'
'"Foo.toString":"I am a Foo",'
'"Keep.toString":"I am a Keep"}';
Expand All @@ -75,22 +67,25 @@ void main() {
});

test('With flag', () {
checkProcessResult(io.Process.runSync(dartaotruntime, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
'--packages=$packageConfig',
'--output-dill=$transformedDill',
'--delete-tostring-package-uri',
'dart:ui',
'--delete-tostring-package-uri',
'package:flutter_frontend_fixtures',
mainDart,
]));
checkProcessResult(
io.Process.runSync(dartaotruntime, <String>[
frontendServer,
'--sdk-root=$sdkRoot',
'--target=flutter',
'--packages=$packageConfig',
'--output-dill=$transformedDill',
'--delete-tostring-package-uri',
'dart:ui',
'--delete-tostring-package-uri',
'package:flutter_frontend_fixtures',
mainDart,
]),
);
final runResult = io.Process.runSync(dart, <String>[transformedDill]);
checkProcessResult(runResult);

const expectedStdout = '{"Paint.toString":"Instance of \'Paint\'",'
const expectedStdout =
'{"Paint.toString":"Instance of \'Paint\'",'
'"Brightness.toString":"Brightness.dark",'
'"Foo.toString":"Instance of \'Foo\'",'
'"Keep.toString":"I am a Keep"}';
Expand Down
Loading
Loading