From 8f96724a7d9ff17d1b1d9a1cbbee865263c5d5e0 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 5 Sep 2024 10:34:17 -0700 Subject: [PATCH] dart_test_runner: output expected dart format args (#3889) 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. --- test_utilities/bin/dart_test_runner.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test_utilities/bin/dart_test_runner.sh b/test_utilities/bin/dart_test_runner.sh index eae625130..78875f23e 100755 --- a/test_utilities/bin/dart_test_runner.sh +++ b/test_utilities/bin/dart_test_runner.sh @@ -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