mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Update packages. * Add many more global analyses. * Catch trailing spaces and trailing newlines in all text files. Before we were only checking newly added files, but that means we missed some. * Port the trailing spaces logic to work on Windows too. * Correct all the files with trailing spaces and newlines. * Refactor some of the dev/bots logic into a utils.dart library. Notably, the "exit" and "print" shims for testing are now usable from test.dart, analyze.dart, and run_command.dart. * Add an "exitWithError" function that prints the red lines and then exits. This is the preferred way to exit from test.dart, analyze.dart, and run_command.dart. * More consistency in the output of analyze.dart. * Refactor analyze.dart to use the _allFiles file enumerating logic more widely. * Add some double-checking logic to the _allFiles logic to catch cases where changes to that logic end up catching fewer files than expected (helps prevent future false positives). * Add a check to prevent new binary files from being added to the repository. Grandfather in the binaries that we've already added. * Update all the dependencies (needed because we now import crypto in dev/bots/analyze.dart).
138 lines
4.5 KiB
Dart
138 lines
4.5 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:file/memory.dart';
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
import 'package:flutter_tools/src/build_system/depfile.dart';
|
|
|
|
import '../../src/common.dart';
|
|
import '../../src/testbed.dart';
|
|
|
|
void main() {
|
|
Testbed testbed;
|
|
|
|
setUp(() {
|
|
testbed = Testbed();
|
|
});
|
|
test('Can parse depfile from file', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync('''
|
|
a.txt: b.txt
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs.single.path, 'b.txt');
|
|
expect(depfile.outputs.single.path, 'a.txt');
|
|
}));
|
|
|
|
test('Can parse depfile with multiple inputs', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync('''
|
|
a.txt: b.txt c.txt d.txt
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs.map((File file) => file.path), <String>[
|
|
'b.txt',
|
|
'c.txt',
|
|
'd.txt',
|
|
]);
|
|
expect(depfile.outputs.single.path, 'a.txt');
|
|
}));
|
|
|
|
test('Can parse depfile with multiple outputs', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync('''
|
|
a.txt c.txt d.txt: b.txt
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs.single.path, 'b.txt');
|
|
expect(depfile.outputs.map((File file) => file.path), <String>[
|
|
'a.txt',
|
|
'c.txt',
|
|
'd.txt',
|
|
]);
|
|
}));
|
|
|
|
test('Can parse depfile with windows file paths', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
|
C:\\a.txt: C:\\b.txt
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs.single.path, r'C:\b.txt');
|
|
expect(depfile.outputs.single.path, r'C:\a.txt');
|
|
}, overrides: <Type, Generator>{
|
|
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.windows),
|
|
}));
|
|
|
|
test('Resillient to weird whitespace', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
|
a.txt
|
|
: b.txt c.txt
|
|
|
|
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs, hasLength(2));
|
|
expect(depfile.outputs.single.path, 'a.txt');
|
|
}));
|
|
|
|
test('Resillient to duplicate files', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
|
a.txt: b.txt b.txt
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs.single.path, 'b.txt');
|
|
expect(depfile.outputs.single.path, 'a.txt');
|
|
}));
|
|
|
|
test('Resillient to malformed file, missing :', () => testbed.run(() {
|
|
final File depfileSource = fs.file('example.d')..writeAsStringSync(r'''
|
|
a.text b.txt
|
|
''');
|
|
final Depfile depfile = Depfile.parse(depfileSource);
|
|
|
|
expect(depfile.inputs, isEmpty);
|
|
expect(depfile.outputs, isEmpty);
|
|
}));
|
|
|
|
test('Can parse dart2js output format', () => testbed.run(() {
|
|
final File dart2jsDependencyFile = fs.file('main.dart.js.deps')..writeAsStringSync(r'''
|
|
file:///Users/foo/collection.dart
|
|
file:///Users/foo/algorithms.dart
|
|
file:///Users/foo/canonicalized_map.dart
|
|
''');
|
|
|
|
final Depfile depfile = Depfile.parseDart2js(dart2jsDependencyFile, fs.file('foo.dart.js'));
|
|
|
|
expect(depfile.inputs.map((File file) => file.path), <String>[
|
|
fs.path.absolute(fs.path.join('Users', 'foo', 'collection.dart')),
|
|
fs.path.absolute(fs.path.join('Users', 'foo', 'algorithms.dart')),
|
|
fs.path.absolute(fs.path.join('Users', 'foo', 'canonicalized_map.dart')),
|
|
]);
|
|
expect(depfile.outputs.single.path, 'foo.dart.js');
|
|
}, overrides: <Type, Generator>{
|
|
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix)
|
|
}));
|
|
|
|
test('Can parse handle invalid uri', () => testbed.run(() {
|
|
final File dart2jsDependencyFile = fs.file('main.dart.js.deps')..writeAsStringSync('''
|
|
file:///Users/foo/collection.dart
|
|
abcdevf
|
|
file:///Users/foo/canonicalized_map.dart
|
|
''');
|
|
|
|
final Depfile depfile = Depfile.parseDart2js(dart2jsDependencyFile, fs.file('foo.dart.js'));
|
|
|
|
expect(depfile.inputs.map((File file) => file.path), <String>[
|
|
fs.path.absolute(fs.path.join('Users', 'foo', 'collection.dart')),
|
|
fs.path.absolute(fs.path.join('Users', 'foo', 'canonicalized_map.dart')),
|
|
]);
|
|
expect(depfile.outputs.single.path, 'foo.dart.js');
|
|
}, overrides: <Type, Generator>{
|
|
FileSystem: () => MemoryFileSystem(style: FileSystemStyle.posix)
|
|
}));
|
|
}
|