Container Infrastructure Management Service for OpenStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cover.sh 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. ALLOWED_EXTRA_MISSING=0
  15. show_diff () {
  16. head -1 $1
  17. diff -U 0 $1 $2 | sed 1,2d
  18. }
  19. if ! git diff --exit-code || ! git diff --cached --exit-code
  20. then
  21. echo "There are uncommitted changes!"
  22. echo "Please clean git working directory and try again"
  23. exit 1
  24. fi
  25. # Checkout master and save coverage report
  26. git checkout HEAD^
  27. base_op_count=`grep "op\." -R magnum/db/sqlalchemy/alembic/versions/ | wc -l`
  28. baseline_report=$(mktemp -t magnum_coverageXXXXXXX)
  29. find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*"
  30. coverage report > $baseline_report
  31. mv cover cover-master
  32. cat $baseline_report
  33. baseline_missing=$(awk 'END { print $3 }' $baseline_report)
  34. # Checkout back and save coverage report
  35. git checkout -
  36. current_op_count=`grep "op\." -R magnum/db/sqlalchemy/alembic/versions/ | wc -l`
  37. current_report=$(mktemp -t magnum_coverageXXXXXXX)
  38. find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*"
  39. coverage report > $current_report
  40. current_missing=$(awk 'END { print $3 }' $current_report)
  41. # Show coverage details
  42. allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING+current_op_count-base_op_count))
  43. echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}"
  44. echo "Missing lines in master : ${baseline_missing}"
  45. echo "Missing lines in proposed change : ${current_missing}"
  46. if [ $allowed_missing -ge $current_missing ]; then
  47. if [ $baseline_missing -lt $current_missing ]; then
  48. show_diff $baseline_report $current_report
  49. echo "We believe you can test your code with 100% coverage!"
  50. else
  51. echo "Thank you! You are awesome! Keep writing unit tests! :)"
  52. fi
  53. exit_code=0
  54. else
  55. show_diff $baseline_report $current_report
  56. echo "Please write more unit tests, we must maintain our test coverage :( "
  57. exit_code=1
  58. fi
  59. rm $baseline_report $current_report
  60. exit $exit_code