_mvn_unit_report.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. REPORT_DIR=${REPORT_DIR:-$PWD}
  17. ## generate summary txt file
  18. find "." -name 'TEST*.xml' -print0 \
  19. | xargs -n1 -0 "grep" -l -E "<failure|<error" \
  20. | awk -F/ '{sub("'"TEST-"'",""); sub(".xml",""); print $NF}' \
  21. | tee "$REPORT_DIR/summary.txt"
  22. #Copy heap dump and dump leftovers
  23. find "." -name "*.hprof" \
  24. -or -name "*.dump" \
  25. -or -name "*.dumpstream" \
  26. -or -name "hs_err_*.log" \
  27. -exec cp {} "$REPORT_DIR/" \;
  28. ## Add the tests where the JVM is crashed
  29. grep -A1 'Crashed tests' "${REPORT_DIR}/output.log" \
  30. | grep -v -e 'Crashed tests' -e '--' \
  31. | cut -f2- -d' ' \
  32. | sort -u >> "${REPORT_DIR}/summary.txt"
  33. #Collect of all of the report failes of FAILED tests
  34. while IFS= read -r -d '' dir; do
  35. while IFS=$'\n' read -r file; do
  36. DIR_OF_TESTFILE=$(dirname "$file")
  37. NAME_OF_TESTFILE=$(basename "$file")
  38. NAME_OF_TEST="${NAME_OF_TESTFILE%.*}"
  39. DESTDIRNAME=$(realpath --relative-to="$PWD" "$DIR_OF_TESTFILE/../..")
  40. mkdir -p "$REPORT_DIR/$DESTDIRNAME"
  41. #shellcheck disable=SC2086
  42. cp -r "$DIR_OF_TESTFILE"/*$NAME_OF_TEST* "$REPORT_DIR/$DESTDIRNAME/"
  43. done < <(grep -l -r FAILURE --include="*.txt" "$dir" | grep -v output.txt)
  44. done < <(find "." -name surefire-reports -print0)
  45. ## generate summary markdown file
  46. export SUMMARY_FILE="$REPORT_DIR/summary.md"
  47. for TEST_RESULT_FILE in $(find "$REPORT_DIR" -name "*.txt" | grep -v output); do
  48. FAILURES=$(grep FAILURE "$TEST_RESULT_FILE" | grep "Tests run" | awk '{print $18}' | sort | uniq)
  49. for FAILURE in $FAILURES; do
  50. TEST_RESULT_LOCATION="$(realpath --relative-to="$REPORT_DIR" "$TEST_RESULT_FILE")"
  51. TEST_OUTPUT_LOCATION="${TEST_RESULT_LOCATION//.txt/-output.txt/}"
  52. printf " * [%s](%s) ([output](%s))\n" "$FAILURE" "$TEST_RESULT_LOCATION" "$TEST_OUTPUT_LOCATION" >> "$SUMMARY_FILE"
  53. done
  54. done
  55. if [ -s "$SUMMARY_FILE" ]; then
  56. printf "# Failing tests: \n\n" | cat - "$SUMMARY_FILE" > temp && mv temp "$SUMMARY_FILE"
  57. fi
  58. ## generate counter
  59. wc -l "$REPORT_DIR/summary.txt" | awk '{print $1}'> "$REPORT_DIR/failures"