This is an automated email from the ASF dual-hosted git repository.
aw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/master by this push:
new fd125e6 YETUS-688. convert key globals from strings to arrays
fd125e6 is described below
commit fd125e61e6c158a86269f49b2d528cc82021d2f2
Author: Allen Wittenauer <[email protected]>
AuthorDate: Sun Feb 3 20:12:24 2019 -0800
YETUS-688. convert key globals from strings to arrays
Signed-off-by: Allen Wittenauer <[email protected]>
---
precommit/pom.xml | 23 +++++
precommit/src/main/shell/core.d/00-yetuslib.sh | 52 +++++++++-
precommit/src/main/shell/core.d/01-common.sh | 50 +++++-----
precommit/src/main/shell/core.d/docker.sh | 2 +-
precommit/src/main/shell/core.d/patchfiles.sh | 2 +-
precommit/src/main/shell/core.d/reaper.sh | 2 +-
precommit/src/main/shell/docker-cleanup.sh | 11 ++-
precommit/src/main/shell/robots.d/circleci.sh | 2 +-
precommit/src/main/shell/robots.d/gitlabci.sh | 8 +-
precommit/src/main/shell/robots.d/jenkins.sh | 2 +-
precommit/src/main/shell/robots.d/travisci.sh | 2 +-
precommit/src/main/shell/smart-apply-patch.sh | 21 ++--
precommit/src/main/shell/test-patch.d/java.sh | 20 ++--
precommit/src/main/shell/test-patch.d/maven.sh | 6 +-
precommit/src/main/shell/test-patch.sh | 106 ++++++++++-----------
.../src/test/shell/functions_test_helper.bash | 50 ++++++++++
precommit/src/test/shell/run-bats.sh | 43 +++++++++
.../src/test/shell/yetus_add_array_element.bats | 36 +++++++
precommit/src/test/shell/yetus_array_contains.bats | 47 +++++++++
.../src/test/shell/yetus_del_array_element.bats | 59 ++++++++++++
20 files changed, 429 insertions(+), 115 deletions(-)
diff --git a/precommit/pom.xml b/precommit/pom.xml
index cea68a2..1b41946 100644
--- a/precommit/pom.xml
+++ b/precommit/pom.xml
@@ -37,10 +37,33 @@
<build>
<plugins>
+
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+
+ </executions>
+ </plugin>
+
+
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
+ <id>test-bats-driver</id>
+ <phase>test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <exec dir="src/test/shell" executable="bash"
failonerror="true">
+ <arg value="./run-bats.sh" />
+ </exec>
+ </target>
+ </configuration>
+ </execution>
+ <execution>
<id>mkdir-bin</id>
<phase>initialize</phase>
<goals>
diff --git a/precommit/src/main/shell/core.d/00-yetuslib.sh
b/precommit/src/main/shell/core.d/00-yetuslib.sh
index 7f21bb3..3d86974 100755
--- a/precommit/src/main/shell/core.d/00-yetuslib.sh
+++ b/precommit/src/main/shell/core.d/00-yetuslib.sh
@@ -305,7 +305,7 @@ function yetus_file_to_array
}
## @description Check if an array has a given value
-## @audience public
+## @audience private
## @stability stable
## @replaceable yes
## @param element
@@ -330,6 +330,26 @@ function yetus_array_contains
return 1
}
+## @description Check if an arrayname has a given value
+## @audience public
+## @stability stable
+## @replaceable yes
+## @param arrayname
+## @param element
+## @returns 0 = yes
+## @returns 1 = no
+function yetus_ver_array_element
+{
+ declare arrname=$1
+ declare element=$2
+
+ declare arrref="${arrname}[@]"
+ declare array=("${!arrref}")
+
+ # shellcheck disable=SC2046
+ return $(yetus_array_contains "${element}" "${array[@]}")
+}
+
## @description Add the element if it is not
## @description present in the given array
## @audience public
@@ -354,6 +374,36 @@ function yetus_add_array_element
fi
}
+## @description Check if an array has a given value
+## @audience public
+## @stability stable
+## @replaceable yes
+## @param arrayname
+## @param element
+function yetus_del_array_element
+{
+ if [[ "$#" -eq 0 ]]; then
+ return 1
+ fi
+
+ declare arrname=$1
+ declare element=$2
+ shift
+ declare val
+
+ declare arrref="${arrname}[@]"
+ declare array=("${!arrref}")
+ declare -a newarr
+
+ for val in "${array[@]}"; do
+ if [[ "${val}" != "${element}" ]]; then
+ newarr+=("${val}")
+ fi
+ done
+ # shellcheck disable=SC1083,SC2086
+ eval "${arrname}"=\(\"\${newarr[@]}\"\)
+}
+
## @description Sort an array by its elements
## @audience public
## @stability stable
diff --git a/precommit/src/main/shell/core.d/01-common.sh
b/precommit/src/main/shell/core.d/01-common.sh
index 0692a9c..91d1cdc 100755
--- a/precommit/src/main/shell/core.d/01-common.sh
+++ b/precommit/src/main/shell/core.d/01-common.sh
@@ -24,11 +24,11 @@ function common_defaults
{
#shellcheck disable=SC2034
BASEDIR=$(pwd)
- BUGSYSTEMS=""
+ BUGSYSTEMS=()
BUILDTOOL=""
- BUILDTOOLS=""
+ BUILDTOOLS=()
#shellcheck disable=SC2034
- EXEC_MODES=""
+ EXEC_MODES=()
ROBOTTYPE=""
LOAD_SYSTEM_PLUGINS=true
#shellcheck disable=SC2034
@@ -59,8 +59,8 @@ function common_defaults
#shellcheck disable=SC2034
SENTINEL=false
#shellcheck disable=SC2034
- TESTTYPES=""
- TESTFORMATS=""
+ TESTTYPES=()
+ TESTFORMATS=()
USER_PLUGIN_DIR=""
#shellcheck disable=SC2034
@@ -249,6 +249,8 @@ function list_plugins
{
declare plugintype
declare name
+ declare plugref
+ declare plugarray
ENABLED_PLUGINS="all"
importplugins
@@ -256,8 +258,10 @@ function list_plugins
printf "Reminder: every plug-in may be enabled via 'all'.\\n\\n"
for plugintype in BUILDTOOLS TESTTYPES BUGSYSTEMS TESTFORMATS; do
printf '%s:\n\t' ${plugintype}
- for name in ${!plugintype}; do
- printf "%s " ${name}
+ plugref="${plugintype}[@]"
+ plugarray=("${!plugref}")
+ for name in "${plugarray[@]}"; do
+ printf "%s " "${name}"
done
echo ""
done
@@ -271,8 +275,8 @@ function parse_args_plugins
{
declare plugin
- for plugin in ${TESTTYPES} ${BUGSYSTEMS} ${TESTFORMATS} ${BUILDTOOLS}; do
- if declare -f ${plugin}_parse_args >/dev/null 2>&1; then
+ for plugin in "${TESTTYPES[@]}" "${BUGSYSTEMS[@]}" "${TESTFORMATS[@]}"
"${BUILDTOOLS[@]}"; do
+ if declare -f "${plugin}_parse_args" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_parse_args"
"${plugin}_parse_args" "$@"
(( RESULT = RESULT + $? ))
@@ -288,8 +292,8 @@ function plugins_initialize
{
declare plugin
- for plugin in ${TESTTYPES} ${BUGSYSTEMS} ${TESTFORMATS} ${BUILDTOOL}; do
- if declare -f ${plugin}_initialize >/dev/null 2>&1; then
+ for plugin in "${TESTTYPES[@]}" "${BUGSYSTEMS[@]}" "${TESTFORMATS[@]}"; do
+ if declare -f "${plugin}_initialize" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_initialize"
"${plugin}_initialize"
(( RESULT = RESULT + $? ))
@@ -364,7 +368,7 @@ function personality_plugins
function add_test
{
if verify_plugin_enabled "${1}"; then
- yetus_add_entry NEEDED_TESTS "${1}"
+ yetus_add_array_element NEEDED_TESTS "${1}"
fi
}
@@ -375,7 +379,7 @@ function add_test
## @param test
function delete_test
{
- yetus_delete_entry NEEDED_TESTS "${1}"
+ yetus_del_array_element NEEDED_TESTS "${1}"
}
## @description Verify if a given test was requested
@@ -387,7 +391,7 @@ function delete_test
## @return 1 = no
function verify_needed_test
{
- yetus_verify_entry NEEDED_TESTS "${1}"
+ yetus_ver_array_element NEEDED_TESTS "${1}"
}
## @description Add the given test type
@@ -398,7 +402,7 @@ function verify_needed_test
function add_test_type
{
if verify_plugin_enabled "${1}"; then
- yetus_add_entry TESTTYPES "${1}"
+ yetus_add_array_element TESTTYPES "${1}"
fi
}
@@ -409,7 +413,7 @@ function add_test_type
## @param plugin
function delete_test_type
{
- yetus_delete_entry TESTTYPES "${1}"
+ yetus_del_array_element TESTTYPES "${1}"
}
## @description Add the given bugsystem type
@@ -420,7 +424,7 @@ function delete_test_type
function add_bugsystem
{
if verify_plugin_enabled "${1}"; then
- yetus_add_entry BUGSYSTEMS "${1}"
+ yetus_add_array_element BUGSYSTEMS "${1}"
fi
}
@@ -431,7 +435,7 @@ function add_bugsystem
## @param bugsystem
function delete_bugsystem
{
- yetus_delete_entry BUGSYSTEMS "${1}"
+ yetus_del_array_element BUGSYSTEMS "${1}"
}
## @description Add the given test format type
@@ -442,7 +446,7 @@ function delete_bugsystem
function add_test_format
{
if verify_plugin_enabled "${1}"; then
- yetus_add_entry TESTFORMATS "${1}"
+ yetus_add_array_element TESTFORMATS "${1}"
fi
}
@@ -453,7 +457,7 @@ function add_test_format
## @param test format
function delete_test_format
{
- yetus_delete_entry TESTFORMATS "${1}"
+ yetus_del_array_element TESTFORMATS "${1}"
}
## @description Add the given build tool type
@@ -464,7 +468,7 @@ function delete_test_format
function add_build_tool
{
if verify_plugin_enabled "${1}"; then
- yetus_add_entry BUILDTOOLS "${1}"
+ yetus_add_array_element BUILDTOOLS "${1}"
fi
}
@@ -475,7 +479,7 @@ function add_build_tool
## @param build tool
function delete_build_tool
{
- yetus_delete_entry BUILDTOOLS "${1}"
+ yetus_del_array_element BUILDTOOLS "${1}"
}
## @description Import content from test-patch.d and optionally
@@ -697,7 +701,7 @@ function guess_build_tool
declare plugin
declare filename
- for plugin in ${BUILDTOOLS}; do
+ for plugin in "${BUILDTOOLS[@]}"; do
if [[ "${plugin}" != "nobuild" ]] && declare -f "${plugin}_buildfile"
>/dev/null 2>&1; then
filename=$("${plugin}_buildfile")
if [[ -n "${filename}" ]] &&
diff --git a/precommit/src/main/shell/core.d/docker.sh
b/precommit/src/main/shell/core.d/docker.sh
index ec931e2..d66acdb 100755
--- a/precommit/src/main/shell/core.d/docker.sh
+++ b/precommit/src/main/shell/core.d/docker.sh
@@ -848,7 +848,7 @@ function docker_handler
# need to call this explicitly
console_docker_support
- for plugin in ${PROJECT_NAME} ${BUILDTOOL} ${BUGSYSTEMS} ${TESTTYPES}
${TESTFORMATS}; do
+ for plugin in ${PROJECT_NAME} ${BUILDTOOL} "${BUGSYSTEMS[@]}"
"${TESTTYPES[@]}" "${TESTFORMATS[@]}"; do
if declare -f "${plugin}_docker_support" >/dev/null; then
"${plugin}_docker_support"
fi
diff --git a/precommit/src/main/shell/core.d/patchfiles.sh
b/precommit/src/main/shell/core.d/patchfiles.sh
index e0db5fc..e038381 100755
--- a/precommit/src/main/shell/core.d/patchfiles.sh
+++ b/precommit/src/main/shell/core.d/patchfiles.sh
@@ -133,7 +133,7 @@ function locate_patch
fi
else
# run through the bug systems. maybe they know?
- for bugsys in ${BUGSYSTEMS}; do
+ for bugsys in "${BUGSYSTEMS[@]}"; do
if declare -f "${bugsys}_locate_patch" >/dev/null 2>&1; then
if "${bugsys}_locate_patch" "${PATCH_OR_ISSUE}" "${PATCH_DIR}/patch";
then
gotit=true
diff --git a/precommit/src/main/shell/core.d/reaper.sh
b/precommit/src/main/shell/core.d/reaper.sh
index 8859274..5ba03e7 100755
--- a/precommit/src/main/shell/core.d/reaper.sh
+++ b/precommit/src/main/shell/core.d/reaper.sh
@@ -78,7 +78,7 @@ function reaper_parse_args
# as necessary
if [[ "${REAPER_MODE}" = "report" || "${REAPER_MODE}" = "kill" ]]; then
add_test_format reaper
- yetus_add_entry EXEC_MODES Reaper
+ yetus_add_array_element EXEC_MODES Reaper
else
REAPER_MODE="off"
fi
diff --git a/precommit/src/main/shell/docker-cleanup.sh
b/precommit/src/main/shell/docker-cleanup.sh
index e6515e5..3173993 100755
--- a/precommit/src/main/shell/docker-cleanup.sh
+++ b/precommit/src/main/shell/docker-cleanup.sh
@@ -75,9 +75,12 @@ function import_and_clean
{
importplugins
yetus_debug "Removing BUILDTOOLS, TESTTYPES, and TESTFORMATS from installed
plug-in list"
- unset BUILDTOOLS
- unset TESTTYPES
- unset TESTFORMATS
+ #shellcheck disable=SC2034
+ BUILDTOOLS=()
+ #shellcheck disable=SC2034
+ TESTTYPES=()
+ #shellcheck disable=SC2034
+ TESTFORMATS=()
#shellcheck disable=SC2034
DOCKER_CLEANUP_CMD=true
@@ -139,7 +142,7 @@ function parse_args
ROBOT=true
# shellcheck disable=SC2034
SENTINEL=true
- yetus_add_entry EXEC_MODES Sentinel
+ yetus_add_array_element EXEC_MODES Sentinel
;;
esac
done
diff --git a/precommit/src/main/shell/robots.d/circleci.sh
b/precommit/src/main/shell/robots.d/circleci.sh
index bc05dd6..4095866 100755
--- a/precommit/src/main/shell/robots.d/circleci.sh
+++ b/precommit/src/main/shell/robots.d/circleci.sh
@@ -57,7 +57,7 @@ if [[ "${CIRCLECI}" = true ]] &&
CIRCLE_PROJECT_REPONAME \
CIRCLE_REPOSITORY_URL
- yetus_add_entry EXEC_MODES Circle_CI
+ yetus_add_array_element EXEC_MODES Circle_CI
fi
fi
diff --git a/precommit/src/main/shell/robots.d/gitlabci.sh
b/precommit/src/main/shell/robots.d/gitlabci.sh
index 9e99b84..17f96d1 100755
--- a/precommit/src/main/shell/robots.d/gitlabci.sh
+++ b/precommit/src/main/shell/robots.d/gitlabci.sh
@@ -40,10 +40,10 @@ if [[ "${GITLAB_CI}" = true ]] &&
CI_PROJECT_PATH \
GITLAB_CI
- yetus_add_entry EXEC_MODES Gitlab_CI
- yetus_add_entry EXEC_MODES ResetRepo
- yetus_add_entry EXEC_MODES Robot
- yetus_add_entry EXEC_MODES UnitTests
+ yetus_add_array_element EXEC_MODES Gitlab_CI
+ yetus_add_array_element EXEC_MODES ResetRepo
+ yetus_add_array_element EXEC_MODES Robot
+ yetus_add_array_element EXEC_MODES UnitTests
fi
function gitlabci_set_plugin_defaults
diff --git a/precommit/src/main/shell/robots.d/jenkins.sh
b/precommit/src/main/shell/robots.d/jenkins.sh
index 52f8ab1..6850317 100755
--- a/precommit/src/main/shell/robots.d/jenkins.sh
+++ b/precommit/src/main/shell/robots.d/jenkins.sh
@@ -102,7 +102,7 @@ if [[ -n "${JENKINS_URL}" && -n "${EXECUTOR_NUMBER}" ]] &&
GIT_URL \
JENKINS_URL
- yetus_add_entry EXEC_MODES Jenkins
+ yetus_add_array_element EXEC_MODES Jenkins
fi
function jenkins_set_plugin_defaults
diff --git a/precommit/src/main/shell/robots.d/travisci.sh
b/precommit/src/main/shell/robots.d/travisci.sh
index 7c066e3..937b6ec 100755
--- a/precommit/src/main/shell/robots.d/travisci.sh
+++ b/precommit/src/main/shell/robots.d/travisci.sh
@@ -66,7 +66,7 @@ if [[ "${TRAVIS}" == true ]] &&
pushd "${BASEDIR}" >/dev/null || exit 1
fi
- yetus_add_entry EXEC_MODES TravisCI
+ yetus_add_array_element EXEC_MODES TravisCI
fi
function travisci_set_plugin_defaults
diff --git a/precommit/src/main/shell/smart-apply-patch.sh
b/precommit/src/main/shell/smart-apply-patch.sh
index 0a5a742..8997ae4 100755
--- a/precommit/src/main/shell/smart-apply-patch.sh
+++ b/precommit/src/main/shell/smart-apply-patch.sh
@@ -158,11 +158,14 @@ function yetus_usage
echo ""
importplugins
- unset TESTFORMATS
- unset TESTTYPES
- unset BUILDTOOLS
-
- for plugin in ${BUGSYSTEMS}; do
+ #shellcheck disable=SC2034
+ BUILDTOOLS=()
+ #shellcheck disable=SC2034
+ TESTTYPES=()
+ #shellcheck disable=SC2034
+ TESTFORMATS=()
+
+ for plugin in "${BUGSYSTEMS[@]}"; do
if declare -f "${plugin}_usage" >/dev/null 2>&1; then
echo ""
echo "${plugin} plugin usage options:"
@@ -386,9 +389,11 @@ setup_defaults
parse_args "$@"
importplugins
-yetus_debug "Removing BUILDTOOLS, TESTTYPES, and TESTFORMATS from installed
plug-in list"
-unset TESTTYPES
-unset TESTFORMATS
+yetus_debug "Removing TESTTYPES and TESTFORMATS from installed plug-in list"
+#shellcheck disable=SC2034
+TESTTYPES=()
+#shellcheck disable=SC2034
+TESTFORMATS=()
parse_args_plugins "$@"
diff --git a/precommit/src/main/shell/test-patch.d/java.sh
b/precommit/src/main/shell/test-patch.d/java.sh
index 2482189..0738009 100755
--- a/precommit/src/main/shell/test-patch.d/java.sh
+++ b/precommit/src/main/shell/test-patch.d/java.sh
@@ -19,7 +19,7 @@
add_test_type javac
add_test_type javadoc
-yetus_add_entry JDK_TEST_LIST javadoc
+yetus_add_array_element JDK_TEST_LIST javadoc
JAVA_INITIALIZED=false
@@ -69,19 +69,18 @@ function initialize_java
JAVA_HOME=$(yetus_abs "${JAVA_HOME}")
- for i in ${JDK_DIR_LIST}; do
+ for i in "${JDK_DIR_LIST[@]}"; do
if [[ -d "${i}" ]]; then
jdkdir=$(yetus_abs "${i}")
if [[ ${jdkdir} != "${JAVA_HOME}" ]]; then
- tmplist="${tmplist} ${jdkdir}"
+ tmplist+=("${jdkdir}")
fi
else
yetus_error "WARNING: Cannot locate JDK directory ${i}: ignoring"
fi
done
- JDK_DIR_LIST="${tmplist} ${JAVA_HOME}"
- JDK_DIR_LIST=${JDK_DIR_LIST/ }
+ JDK_DIR_LIST+=("${JAVA_HOME}")
}
function javac_initialize
@@ -103,7 +102,7 @@ function javadoc_initialize
function javac_precheck
{
declare javaversion
- declare listofjdks
+ declare -a listofjdks
declare i
start_clock
@@ -117,13 +116,12 @@ function javac_precheck
javaversion=$(report_jvm_version "${JAVA_HOME}")
add_footer_table "Default Java" "${javaversion}"
- if [[ -n ${JDK_DIR_LIST}
- && ${JDK_DIR_LIST} != "${JAVA_HOME}" ]]; then
- for i in ${JDK_DIR_LIST}; do
+ if [[ "${#JDK_DIR_LIST[@]}" -gt 1 ]]; then
+ for i in "${JDK_DIR_LIST[@]}"; do
javaversion=$(report_jvm_version "${i}")
- listofjdks="${listofjdks} ${i}:${javaversion}"
+ listofjdks+=("${i}:${javaversion}")
done
- add_footer_table "Multi-JDK versions" "${listofjdks}"
+ add_footer_table "Multi-JDK versions" "${listofjdks[*]}"
fi
return 0
}
diff --git a/precommit/src/main/shell/test-patch.d/maven.sh
b/precommit/src/main/shell/test-patch.d/maven.sh
index 59f6a66..09c7064 100755
--- a/precommit/src/main/shell/test-patch.d/maven.sh
+++ b/precommit/src/main/shell/test-patch.d/maven.sh
@@ -36,7 +36,7 @@ add_build_tool maven
## @param test
function maven_add_install
{
- yetus_add_entry MAVEN_NEED_INSTALL "${1}"
+ yetus_add_array_element MAVEN_NEED_INSTALL "${1}"
}
## @description Remove the given test type as requiring a mvn install
@@ -46,7 +46,7 @@ function maven_add_install
## @param test
function maven_delete_install
{
- yetus_delete_entry MAVEN_NEED_INSTALL "${1}"
+ yetus_del_array_element MAVEN_NEED_INSTALL "${1}"
}
## @description replace the custom repo with either home or workspace if
jenkins.
@@ -609,7 +609,7 @@ function maven_precompile
# not everything needs a maven install
# but quite a few do ...
# shellcheck disable=SC2086
- for index in ${MAVEN_NEED_INSTALL}; do
+ for index in "${MAVEN_NEED_INSTALL[@]}"; do
if verify_needed_test "${index}"; then
need=true
fi
diff --git a/precommit/src/main/shell/test-patch.sh
b/precommit/src/main/shell/test-patch.sh
index b84fb57..1847edc 100755
--- a/precommit/src/main/shell/test-patch.sh
+++ b/precommit/src/main/shell/test-patch.sh
@@ -99,8 +99,8 @@ function setup_defaults
ISSUE=${ISSUE:-""}
TIMER=$("${AWK}" 'BEGIN {srand(); print srand()}')
JVM_REQUIRED=true
- yetus_add_entry JDK_TEST_LIST compile
- yetus_add_entry JDK_TEST_LIST unit
+ yetus_add_array_element JDK_TEST_LIST compile
+ yetus_add_array_element JDK_TEST_LIST unit
}
@@ -280,13 +280,13 @@ function verify_multijdk_test
{
local i=$1
- if [[ "${JDK_DIR_LIST}" == "${JAVA_HOME}" ]]; then
+ if [[ "${#JDK_DIR_LIST[@]}" -lt 2 ]] ; then
yetus_debug "MultiJDK not configured."
return 1
fi
- if [[ ${JDK_TEST_LIST} =~ $i ]]; then
- yetus_debug "${i} is in ${JDK_TEST_LIST} and MultiJDK configured."
+ if yetus_ver_array_element JDK_TEST_LIST "${i}"; then
+ yetus_debug "${i} is in JDK_TEST_LIST and MultiJDK configured."
return 0
fi
return 1
@@ -667,12 +667,10 @@ function yetus_usage
importplugins
- # shellcheck disable=SC2116,SC2086
- bugsys=$(echo ${BUGSYSTEMS})
+ bugsys="${BUGSYSTEMS[*]}"
bugsys=${bugsys// /,}
- # shellcheck disable=SC2116,SC2086
- jdktlist=$(echo ${JDK_TEST_LIST})
+ jdktlist="${JDK_TEST_LIST[*]}"
jdktlist=${jdktlist// /,}
if [[ "${BUILDMODE}" = patch ]]; then
@@ -692,8 +690,8 @@ function yetus_usage
yetus_add_option "--branch-default=<ref>" "If the branch isn't forced and we
don't detect one in the patch name, use this branch (default 'master')"
yetus_add_option "--build-native=<bool>" "If true, then build native
components (default 'true')"
# shellcheck disable=SC2153
- yetus_add_option "--build-tool=<tool>" "Pick which build tool to focus
around (one of ${BUILDTOOLS})"
- yetus_add_option "--bugcomments=<bug>" "Only write comments to the screen
and this comma delimited list (default: ${bugsys})"
+ yetus_add_option "--build-tool=<tool>" "Pick which build tool to focus
around (one of ${BUILDTOOLS[*]})"
+ yetus_add_option "--bugcomments=<bug>" "Only write comments to the screen
and this comma delimited list (default: '${bugsys}')"
yetus_add_option "--contrib-guide=<url>" "URL to point new users towards
project conventions. (default: ${PATCH_NAMING_RULE} )"
yetus_add_option "--debug" "If set, then output some extra stuff to stderr"
yetus_add_option "--dirty-workspace" "Allow the local git workspace to have
uncommitted changes"
@@ -769,7 +767,7 @@ function yetus_usage
yetus_generic_columnprinter "${YETUS_OPTION_USAGE[@]}"
yetus_reset_usage
- for plugin in ${BUILDTOOLS} ${TESTTYPES} ${BUGSYSTEMS} ${TESTFORMATS}; do
+ for plugin in "${BUILDTOOLS[@]}" "${TESTTYPES[@]}" "${BUGSYSTEMS[@]}"
"${TESTFORMATS[@]}"; do
if declare -f "${plugin}_usage" >/dev/null 2>&1; then
echo ""
echo "'${plugin}' plugin usage options:"
@@ -854,15 +852,13 @@ function parse_args
yetus_debug "Manually forcing modules ${USER_MODULE_LIST[*]}"
;;
--multijdkdirs=*)
- JDK_DIR_LIST=${i#*=}
- JDK_DIR_LIST=${JDK_DIR_LIST//,/ }
- yetus_debug "Multi-JDK mode activated with ${JDK_DIR_LIST}"
- yetus_add_entry EXEC_MODES MultiJDK
+ yetus_comma_to_array JDK_DIR_LIST "${i#*=}"
+ yetus_debug "Multi-JDK mode activated with ${JDK_DIR_LIST[*]}"
+ yetus_add_array_element EXEC_MODES MultiJDK
;;
--multijdktests=*)
- JDK_TEST_LIST=${i#*=}
- JDK_TEST_LIST=${JDK_TEST_LIST//,/ }
- yetus_debug "Multi-JDK test list: ${JDK_TEST_LIST}"
+ yetus_comma_to_array JDK_TEST_LIST "${i#*=}"
+ yetus_debug "MultiJDK test list=${JDK_TEST_LIST[*]}"
;;
--mv-patch-dir)
RELOCATE_PATCH_DIR=true;
@@ -888,7 +884,7 @@ function parse_args
--sentinel)
# shellcheck disable=SC2034
SENTINEL=true
- yetus_add_entry EXEC_MODES Sentinel
+ yetus_add_array_element EXEC_MODES Sentinel
;;
--skip-dirs=*)
MODULE_SKIPDIRS=${i#*=}
@@ -953,7 +949,7 @@ function parse_args
RESETREPO=true
RUN_TESTS=true
ISSUE=${PATCH_OR_ISSUE}
- yetus_add_entry EXEC_MODES Robot
+ yetus_add_array_element EXEC_MODES Robot
fi
if [[ -n $UNIT_TEST_FILTER_FILE ]]; then
@@ -973,14 +969,14 @@ function parse_args
if [[ "${DOCKERMODE}" = true || "${DOCKERSUPPORT}" = true ]]; then
if [[ "${DOCKER_DESTRCUTIVE}" = true ]]; then
- yetus_add_entry EXEC_MODES DestructiveDocker
+ yetus_add_array_element EXEC_MODES DestructiveDocker
else
- yetus_add_entry EXEC_MODES Docker
+ yetus_add_array_element EXEC_MODES Docker
fi
add_vote_table 0 reexec "Docker mode activated."
start_clock
elif [[ "${REEXECED}" = true ]]; then
- yetus_add_entry EXEC_MODES Re-exec
+ yetus_add_array_element EXEC_MODES Re-exec
add_vote_table 0 reexec "Precommit patch detected."
start_clock
fi
@@ -1018,11 +1014,11 @@ function parse_args
fi
if [[ ${RESETREPO} == "true" ]] ; then
- yetus_add_entry EXEC_MODES ResetRepo
+ yetus_add_array_element EXEC_MODES ResetRepo
fi
if [[ ${RUN_TESTS} == "true" ]] ; then
- yetus_add_entry EXEC_MODES UnitTests
+ yetus_add_array_element EXEC_MODES UnitTests
fi
if [[ -n "${USER_PLUGIN_DIR}" ]]; then
@@ -1294,7 +1290,7 @@ function determine_branch
return
fi
- for bugs in ${BUGSYSTEMS}; do
+ for bugs in "${BUGSYSTEMS[@]}"; do
if declare -f "${bugs}_determine_branch" >/dev/null;then
"${bugs}_determine_branch"
retval=$?
@@ -1322,7 +1318,7 @@ function determine_issue
yetus_debug "Determine issue"
- for bugsys in ${BUGSYSTEMS}; do
+ for bugsys in "${BUGSYSTEMS[@]}"; do
if declare -f "${bugsys}_determine_issue" >/dev/null; then
if "${bugsys}_determine_issue" "${PATCH_OR_ISSUE}"; then
yetus_debug "${bugsys} says ${ISSUE}"
@@ -1350,14 +1346,14 @@ function determine_needed_tests
yetus_debug "Determining needed tests for ${i}"
personality_file_tests "${i}"
- for plugin in ${TESTTYPES} ${BUILDTOOL}; do
+ for plugin in "${TESTTYPES[@]}" ${BUILDTOOL}; do
if declare -f "${plugin}_filefilter" >/dev/null 2>&1; then
"${plugin}_filefilter" "${i}"
fi
done
done
- add_footer_table "Optional Tests" "${NEEDED_TESTS}"
+ add_footer_table "Optional Tests" "${NEEDED_TESTS[*]}"
}
## @description Given ${PATCH_DIR}/patch, apply the patch
@@ -1982,7 +1978,7 @@ function check_unittests
declare multijdkmode
declare jdk=""
declare jdkindex=0
- declare jdklist
+ declare -a jdklist
declare statusjdk
declare formatresult=0
declare needlog
@@ -1995,13 +1991,13 @@ function check_unittests
if verify_multijdk_test unit; then
multijdkmode=true
- jdklist=${JDK_DIR_LIST}
+ jdklist=("${JDK_DIR_LIST[@]}")
else
multijdkmode=false
- jdklist=${JAVA_HOME}
+ jdklist=("${JAVA_HOME}")
fi
- for jdkindex in ${jdklist}; do
+ for jdkindex in "${jdklist[@]}"; do
if [[ ${multijdkmode} == true ]]; then
JAVA_HOME=${jdkindex}
jdk=$(report_jvm_version "${JAVA_HOME}")
@@ -2025,7 +2021,7 @@ function check_unittests
buildtool_cwd "${i}"
needlog=0
- for testsys in ${TESTFORMATS}; do
+ for testsys in "${TESTFORMATS[@]}"; do
if declare -f "${testsys}_process_tests" >/dev/null; then
yetus_debug "Calling ${testsys}_process_tests"
"${testsys}_process_tests" "${module}" "${test_logfile}" "${fn}"
@@ -2046,7 +2042,7 @@ function check_unittests
((i=i+1))
done
- for testsys in ${TESTFORMATS}; do
+ for testsys in "${TESTFORMATS[@]}"; do
if declare -f "${testsys}_finalize_results" >/dev/null; then
yetus_debug "Calling ${testsys}_finalize_results"
"${testsys}_finalize_results" "${statusjdk}"
@@ -2281,7 +2277,7 @@ function runtests
check_unittests
fi
- for plugin in ${TESTTYPES}; do
+ for plugin in "${TESTTYPES[@]}"; do
verify_patchdir_still_exists
if declare -f "${plugin}_tests" >/dev/null 2>&1; then
modules_reset
@@ -2488,7 +2484,7 @@ function generic_pre_handler
declare -r savejavahome=${JAVA_HOME}
declare multijdkmode
declare jdkindex=0
- declare jdklist
+ declare -a jdklist
if ! verify_needed_test "${testtype}"; then
return 0
@@ -2498,13 +2494,13 @@ function generic_pre_handler
if verify_multijdk_test "${testtype}"; then
multijdkmode=true
- jdklist=${JDK_DIR_LIST}
+ jdklist=("${JDK_DIR_LIST[@]}")
else
multijdkmode=false
- jdklist=${JAVA_HOME}
+ jdklist=("${JAVA_HOME}")
fi
- for jdkindex in ${jdklist}; do
+ for jdkindex in "${jdklist[@]}"; do
if [[ ${multijdkmode} == true ]]; then
JAVA_HOME=${jdkindex}
fi
@@ -2654,7 +2650,7 @@ function generic_post_handler
big_console_header "${testtype} verification: ${BUILDMODE}"
- for jdkindex in ${JDK_DIR_LIST}; do
+ for jdkindex in "${JDK_DIR_LIST[@]}"; do
if [[ ${multijdkmode} == true ]]; then
JAVA_HOME=${jdkindex}
yetus_debug "Using ${JAVA_HOME} to run this set of tests"
@@ -2695,17 +2691,17 @@ function compile_jvm
declare -r savejavahome=${JAVA_HOME}
declare multijdkmode
declare jdkindex=0
- declare jdklist
+ declare -a jdklist
if verify_multijdk_test compile; then
multijdkmode=true
- jdklist=${JDK_DIR_LIST}
+ jdklist=("${JDK_DIR_LIST[@]}")
else
multijdkmode=false
- jdklist=${JAVA_HOME}
+ jdklist=("${JAVA_HOME}")
fi
- for jdkindex in ${jdklist}; do
+ for jdkindex in "${jdklist[@]}"; do
if [[ ${multijdkmode} == true ]]; then
JAVA_HOME=${jdkindex}
fi
@@ -2743,7 +2739,7 @@ function compile_nonjvm
modules_backup
- for plugin in ${TESTTYPES}; do
+ for plugin in "${TESTTYPES[@]}"; do
modules_restore
verify_patchdir_still_exists
if declare -f "${plugin}_compile" >/dev/null 2>&1; then
@@ -2806,7 +2802,7 @@ function compile_cycle
find_changed_modules "${codebase}"
- for plugin in ${PROJECT_NAME} ${BUILDTOOL} ${TESTTYPES} ${TESTFORMATS}; do
+ for plugin in ${PROJECT_NAME} ${BUILDTOOL} "${TESTTYPES[@]}"
"${TESTFORMATS[@]}"; do
if declare -f "${plugin}_precompile" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_precompile"
if ! "${plugin}_precompile" "${codebase}"; then
@@ -2818,7 +2814,7 @@ function compile_cycle
compile "${codebase}"
- for plugin in ${PROJECT_NAME} ${BUILDTOOL} ${TESTTYPES} ${TESTFORMATS}; do
+ for plugin in ${PROJECT_NAME} ${BUILDTOOL} "${TESTTYPES[@]}"
"${TESTFORMATS[@]}"; do
if declare -f "${plugin}_postcompile" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_postcompile"
if ! "${plugin}_postcompile" "${codebase}"; then
@@ -2828,7 +2824,7 @@ function compile_cycle
fi
done
- for plugin in ${PROJECT_NAME} ${BUILDTOOL} ${TESTTYPES} ${TESTFORMATS}; do
+ for plugin in ${PROJECT_NAME} ${BUILDTOOL} "${TESTTYPES[@]}"
"${TESTFORMATS[@]}"; do
if declare -f "${plugin}_rebuild" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_rebuild"
if ! "${plugin}_rebuild" "${codebase}"; then
@@ -2857,7 +2853,7 @@ function patchfiletests
declare plugin
declare result=0
- for plugin in ${BUILDTOOL} ${TESTTYPES} ${TESTFORMATS}; do
+ for plugin in ${BUILDTOOL} "${TESTTYPES[@]}" "${TESTFORMATS[@]}"; do
if declare -f "${plugin}_patchfile" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_patchfile"
if ! "${plugin}_patchfile" "${PATCH_DIR}/patch"; then
@@ -2887,7 +2883,7 @@ function distclean
big_console_header "Cleaning the source tree"
- for plugin in ${TESTTYPES} ${TESTFORMATS}; do
+ for plugin in "${TESTTYPES[@]}" "${TESTFORMATS[@]}"; do
if declare -f "${plugin}_clean" >/dev/null 2>&1; then
yetus_debug "Running ${plugin}_distclean"
if ! "${plugin}_clean"; then
@@ -2982,7 +2978,7 @@ function initialize
personality_parse_args "$@"
fi
- BUGCOMMENTS=${BUGCOMMENTS:-${BUGSYSTEMS}}
+ BUGCOMMENTS=${BUGCOMMENTS:-"${BUGSYSTEMS[@]}"}
if [[ ! ${BUGCOMMENTS} =~ console ]]; then
BUGCOMMENTS="${BUGCOMMENTS} console"
fi
@@ -3012,7 +3008,7 @@ function initialize
cleanup_and_exit 1
fi
- echo "Modes: ${EXEC_MODES}"
+ echo "Modes: ${EXEC_MODES[*]}"
if [[ "${BUILDMODE}" = patch ]]; then
locate_patch
@@ -3068,7 +3064,7 @@ function prechecks
declare plugin
declare result=0
- for plugin in ${BUILDTOOL} ${NEEDED_TESTS} ${TESTFORMATS}; do
+ for plugin in ${BUILDTOOL} "${NEEDED_TESTS[@]}" "${TESTFORMATS[@]}"; do
verify_patchdir_still_exists
if declare -f "${plugin}_precheck" >/dev/null 2>&1; then
diff --git a/precommit/src/test/shell/functions_test_helper.bash
b/precommit/src/test/shell/functions_test_helper.bash
new file mode 100755
index 0000000..2d92edf
--- /dev/null
+++ b/precommit/src/test/shell/functions_test_helper.bash
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+setup() {
+ RELTMP="${BATS_TEST_DIRNAME}/../../../target/test-dir/bats.$$.${RANDOM}"
+ mkdir -p "${RELTMP}"
+ TMP=$(cd -P -- "${RELTMP}" >/dev/null && pwd -P)
+ export TMP
+ TESTBINDIR=$(cd -P -- "$(pwd)" >/dev/null && pwd -P)
+
+ echo "bindir: ${TESTBINDIR}" 2>&1
+
+ mkdir -p "${TMP}"
+
+ # shellcheck disable=SC2034
+ QATESTMODE=true
+
+ # shellcheck disable=SC1090
+ . "${BATS_TEST_DIRNAME}/../../main/shell/core.d/00-yetuslib.sh"
+ # shellcheck disable=SC1090
+ . "${BATS_TEST_DIRNAME}/../../main/shell/core.d/01-common.sh"
+ pushd "${TMP}" >/dev/null || return 1
+}
+
+teardown() {
+ popd >/dev/null || return 1
+ rm -rf "${TMP}"
+}
+
+
+strstr() {
+ if [ "${1#*$2}" != "${1}" ]; then
+ echo true
+ else
+ echo false
+ fi
+}
diff --git a/precommit/src/test/shell/run-bats.sh
b/precommit/src/test/shell/run-bats.sh
new file mode 100755
index 0000000..566f47a
--- /dev/null
+++ b/precommit/src/test/shell/run-bats.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+targetdir=../../../target
+mkdir -p ${targetdir}/surefire-reports ${targetdir}/tap
+
+batsexe=$(which bats) 2>/dev/null
+
+if [[ -z ${batsexe} ]]; then
+ echo "not ok - no bats executable found" > "${targetdir}/tap/shelltest.tap"
+ echo ""
+ echo ""
+ echo "ERROR: bats not installed. Skipping bash tests."
+ echo "ERROR: Please install bats as soon as possible."
+ echo ""
+ echo ""
+ exit 0
+fi
+
+for j in *.bats; do
+ echo Running bats -t "${j}"
+ bats -t "${j}" 2>&1 | tee "${targetdir}/tap/${j}.tap"
+ result=${PIPESTATUS[0]}
+ ((exitcode=exitcode+result))
+done
+
+if [[ ${exitcode} -gt 0 ]]; then
+ exit 1
+fi
+exit 0
diff --git a/precommit/src/test/shell/yetus_add_array_element.bats
b/precommit/src/test/shell/yetus_add_array_element.bats
new file mode 100755
index 0000000..462f34c
--- /dev/null
+++ b/precommit/src/test/shell/yetus_add_array_element.bats
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load functions_test_helper
+
+@test "yetus_add_array_element (empty)" {
+ yetus_add_array_element ARRAY value
+ [ "${ARRAY[0]}" = value ]
+}
+
+@test "yetus_add_array_element (exist)" {
+ ARRAY=("val2")
+ yetus_add_array_element ARRAY val1
+ [ "${ARRAY[0]}" = val2 ]
+ [ "${ARRAY[1]}" = val1 ]
+}
+
+@test "yetus_add_array_element (double exist)" {
+ ARRAY=("val2" "val1")
+ yetus_add_array_element ARRAY val3
+ [ "${ARRAY[0]}" = val2 ]
+ [ "${ARRAY[1]}" = val1 ]
+ [ "${ARRAY[2]}" = val3 ]
+}
diff --git a/precommit/src/test/shell/yetus_array_contains.bats
b/precommit/src/test/shell/yetus_array_contains.bats
new file mode 100755
index 0000000..4151ffe
--- /dev/null
+++ b/precommit/src/test/shell/yetus_array_contains.bats
@@ -0,0 +1,47 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load functions_test_helper
+
+@test "yetus_array_contains (empty)" {
+ run yetus_array_contains value "${ARRAY[@]}"
+ [ "${status}" = 1 ]
+}
+
+@test "yetus_array_contains (exist)" {
+ ARRAY=("value")
+ run yetus_array_contains value "${ARRAY[@]}"
+ [ "${status}" = 0 ]
+}
+
+@test "yetus_array_contains (notexist)" {
+ ARRAY=("different")
+ run yetus_array_contains value "${ARRAY[@]}"
+ [ "${status}" = 1 ]
+}
+
+@test "yetus_array_contains (exist, multi)" {
+ ARRAY=("val1" "val2" "val3")
+ for j in val1 val2 val3; do
+ run yetus_array_contains "${j}" "${ARRAY[@]}"
+ [ "${status}" = 0 ]
+ done
+}
+
+@test "yetus_array_contains (multi, not exist)" {
+ ARRAY=("val1" "val2" "val3")
+ run yetus_array_contains value "${ARRAY[@]}"
+ [ "${status}" = 1 ]
+}
diff --git a/precommit/src/test/shell/yetus_del_array_element.bats
b/precommit/src/test/shell/yetus_del_array_element.bats
new file mode 100755
index 0000000..a79b584
--- /dev/null
+++ b/precommit/src/test/shell/yetus_del_array_element.bats
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load functions_test_helper
+
+@test "yetus_del_array_element (empty array)" {
+ yetus_del_array_element ARRAY value
+ [ "${#ARRAY[@]}" = 0 ]
+}
+
+@test "yetus_del_array_element (not exist)" {
+ ARRAY=("val2")
+ yetus_del_array_element ARRAY val1
+ [ "${ARRAY[0]}" = val2 ]
+ [ "${#ARRAY[@]}" -eq 1 ]
+}
+
+@test "yetus_add_array_element (single exist)" {
+ ARRAY=("val1")
+ yetus_del_array_element ARRAY val1
+ echo ">${ARRAY[@]}<"
+ [ "${#ARRAY[@]}" -eq 0 ]
+}
+
+@test "yetus_del_array_element (size 2, exist)" {
+ ARRAY=("val2" "val1")
+ yetus_del_array_element ARRAY val1
+ [ "${ARRAY[0]}" = val2 ]
+ [ "${ARRAY[1]}" = '' ]
+ [ "${#ARRAY[@]}" -eq 1 ]
+}
+
+@test "yetus_del_array_element (size 2, exist, squash)" {
+ ARRAY=("val2" "val1")
+ yetus_del_array_element ARRAY val2
+ [ "${ARRAY[0]}" = val1 ]
+ [ "${ARRAY[1]}" = '' ]
+ [ "${#ARRAY[@]}" -eq 1 ]
+}
+
+@test "yetus_del_array_element (size 3, exist, squash)" {
+ ARRAY=("val3" "val2" "val1")
+ yetus_del_array_element ARRAY val2
+ [ "${ARRAY[0]}" = val3 ]
+ [ "${ARRAY[1]}" = val1 ]
+ [ "${#ARRAY[@]}" -eq 2 ]
+}
\ No newline at end of file