Skip to content

Commit

Permalink
Add presubmit test for trailing whitespace. (flutter#19412)
Browse files Browse the repository at this point in the history
Checks only changed source files (C++, Dart, Java, ObjC) for trailing whitespace.
  • Loading branch information
gspencergoog authored Jul 20, 2018
1 parent 1cc0365 commit 9f39039
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
22 changes: 15 additions & 7 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
40 changes: 39 additions & 1 deletion dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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')],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion dev/bots/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9f39039

Please sign in to comment.