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:
# run pub get in all the repo packages
./bin/flutter update-packages
git fetch origin master
matrix:
- name: docs
env:
......@@ -25,11 +26,15 @@ task:
- name: analyze
env:
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
env:
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:
cpu: 4
memory: 8G
......@@ -48,8 +53,10 @@ task:
setup_script:
- bin\flutter.bat config --no-analytics
- bin\flutter.bat update-packages
test_all_script:
- bin\cache\dart-sdk\bin\dart.exe -c dev\bots\test.dart
- git fetch origin master
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:
name: tests-macos
......@@ -61,6 +68,7 @@ task:
setup_script:
- bin/flutter config --no-analytics
- bin/flutter update-packages
test_all_script:
- ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976
- bin/cache/dart-sdk/bin/dart -c dev/bots/test.dart
test_all_script: |
ulimit -S -n 2048 # https://github.com/flutter/flutter/issues/2976
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 {
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 {
await _verifyGeneratedPluginRegistrants(flutterRoot);
await _verifyNoBadImportsInFlutter(flutterRoot);
......@@ -123,6 +158,8 @@ Future<Null> _analyzeRepo() async {
options: <String>['--flutter-repo', '--watch', '--benchmark'],
);
await _checkForTrailingSpaces();
// Try an analysis against a big version of the gallery.
await _runCommand(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, {
String workingDirectory,
Map<String, String> environment,
bool expectFailure = false,
int expectedExitCode,
bool printOutput = true,
bool skip = false,
Duration timeout = _kLongTimeout,
......@@ -363,7 +401,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
stderr.writeln('Process timed out after $timeout');
return expectFailure ? 0 : 1;
});
if ((exitCode == 0) == expectFailure) {
if ((exitCode == 0) == expectFailure || (expectedExitCode != null && exitCode != expectedExitCode)) {
if (!printOutput) {
stdout.writeln(utf8.decode((await savedStdout).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
./dev/bots/docs.sh
fi
else
dart ./dev/bots/test.dart
TEST_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE}" dart ./dev/bots/test.dart
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