From d6a29ea707903c9d9c91d4fc18dca24fd770899e Mon Sep 17 00:00:00 2001 From: Jeremy Goldman Date: Tue, 8 Dec 2020 16:52:37 +0800 Subject: [PATCH] Precommit hook added to Settings, preventing the creation of new Robolectric tests. Test: repo upload . Change-Id: If31d79a7bf6a18f4c52692ffab4981056c14eaba --- PREUPLOAD.cfg | 2 ++ tests/robotests/new_tests_hook.sh | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100755 tests/robotests/new_tests_hook.sh diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg index 883e968e4dc..5100c03e509 100644 --- a/PREUPLOAD.cfg +++ b/PREUPLOAD.cfg @@ -4,3 +4,5 @@ checkcolor_hook = ${REPO_ROOT}/prebuilts/checkcolor/checkcolor.py -p . strings_lint_hook = ${REPO_ROOT}/frameworks/base/tools/stringslint/stringslint_sha.sh ${PREUPLOAD_COMMIT} checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT} + +robolectric_hook = ${REPO_ROOT}/packages/apps/Settings/tests/robotests/new_tests_hook.sh ${REPO_PROJECT} diff --git a/tests/robotests/new_tests_hook.sh b/tests/robotests/new_tests_hook.sh new file mode 100755 index 00000000000..92d66707a9b --- /dev/null +++ b/tests/robotests/new_tests_hook.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# This script detects the presence of new robolectric java tests within +# commits to be uploaded. If a new file is detected the script will print an +# error message and return an error code. Intended to be used as a repo hook. + +new_robolectric_tests=$( + git diff --name-status $REPO_LREV | grep "^A.*tests/robotests.*\.java") +if [ $new_robolectric_tests != "" ] +then + echo "New Robolectric unit tests detected. Please submit junit tests" \ + "instead, in the tests/junit directory." \ + "See go/android-platform-robolectric-cleanup." + echo $new_robolectric_tests + exit 1 +fi