1 ##############################################################################
2 # Copyright 2015: Mirantis Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
16 # yardstick comment: this is a modified copy of
17 # rally/tests/ci/cover.sh
18 ##############################################################################
22 diff -U 0 $1 $2 | sed 1,2d
28 ALLOWED_EXTRA_MISSING=10
31 # Stash uncommitted changes, checkout master and save coverage report
32 uncommited=$(git status --porcelain | grep -v "^??")
33 [[ -n $uncommited ]] && git stash > /dev/null
36 baseline_report=$(mktemp -t yardstick_coverageXXXXXXX)
37 # workaround 'db type could not be determined' bug
38 # https://bugs.launchpad.net/testrepository/+bug/1229445
39 rm -rf .testrepository
40 find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --slowest --testr-args="$*"
41 coverage report > $baseline_report
42 baseline_missing=$(awk 'END { print $3 }' $baseline_report)
44 # Checkout back and unstash uncommitted changes (if any)
46 [[ -n $uncommited ]] && git stash pop > /dev/null
48 # Generate and save coverage report
49 current_report=$(mktemp -t yardstick_coverageXXXXXXX)
50 # workaround 'db type could not be determined' bug
51 # https://bugs.launchpad.net/testrepository/+bug/1229445
52 rm -rf .testrepository
53 find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --slowest --testr-args="$*"
54 coverage report > $current_report
55 current_missing=$(awk 'END { print $3 }' $current_report)
57 # Show coverage details
58 allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING))
60 echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}"
61 echo "Missing lines in master : ${baseline_missing}"
62 echo "Missing lines in proposed change : ${current_missing}"
64 if [ $allowed_missing -gt $current_missing ];
66 if [ $baseline_missing -lt $current_missing ];
68 show_diff $baseline_report $current_report
69 echo "I believe you can cover all your code with 100% coverage!"
71 echo "Thank you! You are awesome! Keep writing unit tests! :)"
74 show_diff $baseline_report $current_report
75 echo "Please write more unit tests, we should keep our test coverage :( "
76 rm $baseline_report $current_report
80 rm $baseline_report $current_report