Add --noformat option for unit test
The run-unit-test-docker.sh and unit-test.py will run format-code.sh to
check the code format, and break when the code is not formatted
correctly.
For local-ci, this is unecessary because the code not "git add" or not
committed is treated as not-formatted and will break.
Adding NO_FORMAT_CODE option to make the unit test skip formatting the
code, so that one could write code in local repo, run the local-ci
without having to git add ro commit the changes.
Tested: Run run-unit-test-docker.sh as before, verify the format-code.sh
is invoked;
Run 'NO_FORMAT_CODE=1 run-unit-test-docker.sh', verify the
format-code.sh is not invoked.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: Ib3b6cf34390c91d551bc14613e925b8e51a3065f
diff --git a/run-unit-test-docker.sh b/run-unit-test-docker.sh
index 18e7e6a..b178fa4 100755
--- a/run-unit-test-docker.sh
+++ b/run-unit-test-docker.sh
@@ -24,6 +24,7 @@
# -$BRANCH replacing -master if $BRANCH provided
# dbus_sys_config_file: Optional, with the default being
# `/usr/share/dbus-1/system.conf`
+# NO_FORMAT_CODE: Optional, do not run format-code.sh
# Trace bash processing. Set -e so when a step fails, we fail the build
set -uo pipefail
@@ -41,6 +42,7 @@
DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"}
MAKEFLAGS="${MAKEFLAGS:-""}"
DOCKER_WORKDIR="${DOCKER_WORKDIR:-$WORKSPACE}"
+NO_FORMAT_CODE="${NO_FORMAT_CODE:-}"
# Timestamp for job
echo "Unit test build started, $(date)"
@@ -90,7 +92,7 @@
# Unit test and parameters
UNIT_TEST="${DOCKER_WORKDIR}/${UNIT_TEST_PY},-w,${DOCKER_WORKDIR},\
--p,${UNIT_TEST_PKG},-b,$BRANCH,-v${TEST_ONLY:+,-t}"
+-p,${UNIT_TEST_PKG},-b,$BRANCH,-v${TEST_ONLY:+,-t}${NO_FORMAT_CODE:+,-n}"
# Run the docker unit test container with the unit test execution script
echo "Executing docker image"
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index ab35c4e..1f2bf2a 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -772,11 +772,15 @@
parser.add_argument("-b", "--branch", dest="BRANCH", required=False,
help="Branch to target for dependent repositories",
default="master")
+ parser.add_argument("-n", "--noformat", dest="FORMAT",
+ action="store_false", required=False,
+ help="Whether or not to run format code")
args = parser.parse_args(sys.argv[1:])
WORKSPACE = args.WORKSPACE
UNIT_TEST_PKG = args.PACKAGE
TEST_ONLY = args.TEST_ONLY
BRANCH = args.BRANCH
+ FORMAT_CODE = args.FORMAT
if args.verbose:
def printline(*line):
for arg in line:
@@ -785,10 +789,12 @@
else:
printline = lambda *l: None
+ CODE_SCAN_DIR = WORKSPACE + "/" + UNIT_TEST_PKG
+
# First validate code formatting if repo has style formatting files.
# The format-code.sh checks for these files.
- CODE_SCAN_DIR = WORKSPACE + "/" + UNIT_TEST_PKG
- check_call_cmd("./format-code.sh", CODE_SCAN_DIR)
+ if FORMAT_CODE:
+ check_call_cmd("./format-code.sh", CODE_SCAN_DIR)
# Automake and meson
if (os.path.isfile(CODE_SCAN_DIR + "/configure.ac") or