Skip to content

Commit

Permalink
dart_test_runner: output expected dart format args (flutter#3889)
Browse files Browse the repository at this point in the history
Currently on a failed run due to unformatted dart code, the output looks like:

    ######### dart format #########
    Formatted lib/src/file_codesign_visitor.dart
    Formatted 10 files (1 changed) in 0.65 seconds.

In the face of this output, my natural inclination would be to run

    dart format path/to/file

but that would be incorrect. What would be correct would be to locate our CI test script, read the code, and discover that we format to a width of 120 characters, then format with those args. 

Instead, we now inform the user of the args directly in the test output to save them some digging.

Also checks to see the user actually supplied an argument to the script and if not, emits an error message and usage info then fails, rather than silently running  `pushd ""`, resulting in no change to PWD, then failing when it realises that the top level of the repo is not a pub package.
  • Loading branch information
cbracken authored Sep 5, 2024
1 parent 7eed365 commit 8f96724
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test_utilities/bin/dart_test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@
# Runner for dart tests. It expects a single parameter with the full
# path to the start folder where tests will be run.

set -e
set -euo pipefail

# Build and analyze
echo "###### dart_test_runner #######"
echo "Directory: $1"

if [ -z "$1" ]; then
echo "ERROR: no package directory supplied."
echo "usage: $0 PACKAGE_DIR_TO_TEST"
exit 1
fi

# Setup.
pushd "$1" > /dev/null
flutter clean
dart pub get

# TODO(drewroengoogle): Validate proto code has been generated. https://github.com/flutter/flutter/issues/115473

echo "######### dart format #########"
dart format --set-exit-if-changed --line-length=120 .
FORMAT_ARGS=--line-length=120
echo "######### dart format $FORMAT_ARGS #########"
dart format --set-exit-if-changed $FORMAT_ARGS .

echo "########### analyze ###########"
dart analyze --fatal-infos
Expand Down

0 comments on commit 8f96724

Please sign in to comment.