1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
13 diff -U 0 $1 $2 | sed 1,2d
19 ALLOWED_EXTRA_MISSING=10
22 # Stash uncommitted changes, checkout master and save coverage report
23 uncommited=$(git status --porcelain | grep -v "^??")
24 [[ -n $uncommited ]] && git stash > /dev/null
27 baseline_report=$(mktemp -t yardstick_coverageXXXXXXX)
28 find . -type f -name "*.pyc" -delete && python setup.py testr --coverage --testr-args="$*"
29 coverage report > $baseline_report
30 baseline_missing=$(awk 'END { print $3 }' $baseline_report)
32 # Checkout back and unstash uncommitted changes (if any)
34 [[ -n $uncommited ]] && git stash pop > /dev/null
36 # Generate and save coverage report
37 current_report=$(mktemp -t yardstick_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)
42 # Show coverage details
43 allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING))
45 echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}"
46 echo "Missing lines in master : ${baseline_missing}"
47 echo "Missing lines in proposed change : ${current_missing}"
49 if [ $allowed_missing -gt $current_missing ];
51 if [ $baseline_missing -lt $current_missing ];
53 show_diff $baseline_report $current_report
54 echo "I believe you can cover all your code with 100% coverage!"
56 echo "Thank you! You are awesome! Keep writing unit tests! :)"
59 show_diff $baseline_report $current_report
60 echo "Please write more unit tests, we should keep our test coverage :( "
61 rm $baseline_report $current_report
65 rm $baseline_report $current_report