| #!/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. |
| |
| add_test_format junit |
| |
| JUNIT_TEST_TIMEOUTS="" |
| JUNIT_FAILED_TESTS="" |
| |
| JUNIT_TEST_OUTPUT_DIR="." |
| JUNIT_TEST_PREFIX="org.apache." |
| |
| function junit_usage |
| { |
| yetus_add_option "--junit-test-output=<path>" "Directory to search for the test output TEST-*.xml files, relative to the module directory (default:'${JUNIT_TEST_OUTPUT_DIR}')" |
| yetus_add_option "--junit-test-prefix=<prefix to trim>" "Prefix of test names to be be removed. Used to shorten test names by removing common package name. (default:'${JUNIT_TEST_PREFIX}')" |
| } |
| |
| function junit_parse_args |
| { |
| declare i |
| |
| for i in "$@"; do |
| case ${i} in |
| --junit-test-output=*) |
| JUNIT_TEST_OUTPUT_DIR=${i#*=} |
| ;; |
| --junit-test-prefix=*) |
| JUNIT_TEST_PREFIX=${i#*=} |
| ;; |
| esac |
| done |
| } |
| |
| function junit_process_tests |
| { |
| # shellcheck disable=SC2034 |
| declare module=$1 |
| declare buildlogfile=$2 |
| declare result=0 |
| declare module_test_timeouts |
| declare module_failed_tests |
| |
| # shellcheck disable=SC2016 |
| module_test_timeouts=$(${AWK} '/^Running / { array[$NF] = 1 } /^Tests run: .* in / { delete array[$NF] } END { for (x in array) { print x } }' "${buildlogfile}") |
| if [[ -n "${module_test_timeouts}" ]] ; then |
| JUNIT_TEST_TIMEOUTS="${JUNIT_TEST_TIMEOUTS} ${module_test_timeouts}" |
| ((result=result+1)) |
| fi |
| |
| #shellcheck disable=SC2026,SC2038,SC2016 |
| module_failed_tests=$(find "${JUNIT_TEST_OUTPUT_DIR}" -name 'TEST*.xml'\ |
| | xargs "${GREP}" -l -E "<failure|<error"\ |
| | ${AWK} -F/ '{sub("'"TEST-${JUNIT_TEST_PREFIX}"'",""); sub(".xml",""); print $NF}') |
| if [[ -n "${module_failed_tests}" ]] ; then |
| JUNIT_FAILED_TESTS="${JUNIT_FAILED_TESTS} ${module_failed_tests}" |
| ((result=result+1)) |
| fi |
| |
| if [[ ${result} -gt 0 ]]; then |
| return 1 |
| fi |
| return 0 |
| } |
| |
| function junit_finalize_results |
| { |
| declare jdk=$1 |
| |
| if [[ -n "${JUNIT_FAILED_TESTS}" ]] ; then |
| # shellcheck disable=SC2086 |
| populate_test_table "${jdk}Failed junit tests" ${JUNIT_FAILED_TESTS} |
| JUNIT_FAILED_TESTS="" |
| fi |
| if [[ -n "${JUNIT_TEST_TIMEOUTS}" ]] ; then |
| # shellcheck disable=SC2086 |
| populate_test_table "${jdk}Timed out junit tests" ${JUNIT_TEST_TIMEOUTS} |
| JUNIT_TEST_TIMEOUTS="" |
| fi |
| } |