Unverified Commit 9f39039f authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Add presubmit test for trailing whitespace. (#19412)

Checks only changed source files (C++, Dart, Java, ObjC) for trailing whitespace.
parent 1cc03651
...@@ -17,6 +17,7 @@ task: ...@@ -17,6 +17,7 @@ task:
# run pub get in all the repo packages # run pub get in all the repo packages
./bin/flutter update-packages ./bin/flutter update-packages
git fetch origin master
matrix: matrix:
- name: docs - name: docs
env: env:
...@@ -25,11 +26,15 @@ task: ...@@ -25,11 +26,15 @@ task:
- name: analyze - name: analyze
env: env:
SHARD: analyze SHARD: analyze
test_script: dart ./dev/bots/test.dart test_script: |
export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD"
dart ./dev/bots/test.dart
- name: tests-linux - name: tests-linux
env: env:
SHARD: tests SHARD: tests
test_script: dart ./dev/bots/test.dart test_script: |
export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD"
dart ./dev/bots/test.dart
container: container:
cpu: 4 cpu: 4
memory: 8G memory: 8G
...@@ -48,8 +53,10 @@ task: ...@@ -48,8 +53,10 @@ task:
setup_script: setup_script:
- bin\flutter.bat config --no-analytics - bin\flutter.bat config --no-analytics
- bin\flutter.bat update-packages - bin\flutter.bat update-packages
test_all_script: - git fetch origin master
- bin\cache\dart-sdk\bin\dart.exe -c dev\bots\test.dart test_all_script: |
export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD"
bin\cache\dart-sdk\bin\dart.exe -c dev\bots\test.dart
task: task:
name: tests-macos name: tests-macos
...@@ -61,6 +68,7 @@ task: ...@@ -61,6 +68,7 @@ task:
setup_script: setup_script:
- bin/flutter config --no-analytics - bin/flutter config --no-analytics
- bin/flutter update-packages - bin/flutter update-packages
test_all_script: test_all_script: |
- ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976 ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976
- bin/cache/dart-sdk/bin/dart -c dev/bots/test.dart export TEST_COMMIT_RANGE="$(git merge-base --fork-point FETCH_HEAD HEAD)..HEAD"
bin/cache/dart-sdk/bin/dart -c dev/bots/test.dart
...@@ -95,6 +95,41 @@ Future<Null> _verifyInternationalizations() async { ...@@ -95,6 +95,41 @@ Future<Null> _verifyInternationalizations() async {
print('Contents of $localizationsFile matches output of gen_localizations.dart script.'); print('Contents of $localizationsFile matches output of gen_localizations.dart script.');
} }
Future<Null> _checkForTrailingSpaces() async {
if (!Platform.isWindows) {
final String commitRange = Platform.environment.containsKey('TEST_COMMIT_RANGE')
? Platform.environment['TEST_COMMIT_RANGE']
: 'master..HEAD';
print('Checking for trailing whitespace in source files.');
final List<String> fileTypes = <String>[
'*.dart', '*.cxx', '*.cpp', '*.cc', '*.c', '*.C', '*.h', '*.java', '*.mm', '*.m',
];
final EvalResult changedFilesResult = await _evalCommand(
'git', <String>['diff', '-U0', '--no-color', '--name-only', commitRange, '--'] + fileTypes,
workingDirectory: flutterRoot,
);
if (changedFilesResult.stdout == null) {
print('No Results for whitespace check.');
return;
}
final List<String> changedFiles = changedFilesResult.stdout.trim().split('\n')
.where((String item) => item.trim().isNotEmpty).toList();
if (changedFiles.isNotEmpty) {
await _runCommand('grep',
<String>[
'--line-number',
'--extended-regexp',
r'[[:space:]]+$',
] + changedFiles,
workingDirectory: flutterRoot,
printOutput: false,
expectFailure: true, // Just means a non-zero exit code is expected.
expectedExitCode: 1, // Indicates that zero lines were found.
);
}
}
}
Future<Null> _analyzeRepo() async { Future<Null> _analyzeRepo() async {
await _verifyGeneratedPluginRegistrants(flutterRoot); await _verifyGeneratedPluginRegistrants(flutterRoot);
await _verifyNoBadImportsInFlutter(flutterRoot); await _verifyNoBadImportsInFlutter(flutterRoot);
...@@ -123,6 +158,8 @@ Future<Null> _analyzeRepo() async { ...@@ -123,6 +158,8 @@ Future<Null> _analyzeRepo() async {
options: <String>['--flutter-repo', '--watch', '--benchmark'], options: <String>['--flutter-repo', '--watch', '--benchmark'],
); );
await _checkForTrailingSpaces();
// Try an analysis against a big version of the gallery. // Try an analysis against a big version of the gallery.
await _runCommand(dart, await _runCommand(dart,
<String>['--preview-dart-2', path.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')], <String>['--preview-dart-2', path.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')],
...@@ -331,6 +368,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, { ...@@ -331,6 +368,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
String workingDirectory, String workingDirectory,
Map<String, String> environment, Map<String, String> environment,
bool expectFailure = false, bool expectFailure = false,
int expectedExitCode,
bool printOutput = true, bool printOutput = true,
bool skip = false, bool skip = false,
Duration timeout = _kLongTimeout, Duration timeout = _kLongTimeout,
...@@ -363,7 +401,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, { ...@@ -363,7 +401,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
stderr.writeln('Process timed out after $timeout'); stderr.writeln('Process timed out after $timeout');
return expectFailure ? 0 : 1; return expectFailure ? 0 : 1;
}); });
if ((exitCode == 0) == expectFailure) { if ((exitCode == 0) == expectFailure || (expectedExitCode != null && exitCode != expectedExitCode)) {
if (!printOutput) { if (!printOutput) {
stdout.writeln(utf8.decode((await savedStdout).expand((List<int> ints) => ints).toList())); stdout.writeln(utf8.decode((await savedStdout).expand((List<int> ints) => ints).toList()));
stderr.writeln(utf8.decode((await savedStderr).expand((List<int> ints) => ints).toList())); stderr.writeln(utf8.decode((await savedStderr).expand((List<int> ints) => ints).toList()));
......
...@@ -59,5 +59,5 @@ elif [ "$SHARD" = "docs" ]; then ...@@ -59,5 +59,5 @@ elif [ "$SHARD" = "docs" ]; then
./dev/bots/docs.sh ./dev/bots/docs.sh
fi fi
else else
dart ./dev/bots/test.dart TEST_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}" dart ./dev/bots/test.dart
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment