run_test.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright 2019 The FATE Authors. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # 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. #
  17. cd $(dirname "$0")
  18. cur_dir=$(pwd)
  19. first_test=1
  20. failed_count=0
  21. run_test() {
  22. file=$1
  23. echo "start to run test "$file
  24. if [ $first_test == 1 ]; then
  25. coverage run $file 2>test.log
  26. else
  27. coverage run -a $file 2>test.log
  28. fi
  29. failed_single_test=$(cat test.log | grep FAILED | wc -l)
  30. failed_count=$(($failed_count+$failed_single_test))
  31. echo $failed_count
  32. cat test.log
  33. first_test=0
  34. }
  35. traverse_folder() {
  36. for file in $(ls ${1});
  37. do
  38. file_fullname=$1/$file
  39. if [ -d $file_fullname ]; then
  40. traverse_folder $file_fullname
  41. elif [[ $file =~ _test.py$ ]] && [[ $1 =~ /test$ || $1 =~ tests$ ]]; then
  42. if [[ $file_fullname =~ "ftl" ]]; then
  43. continue
  44. else
  45. run_test $file_fullname
  46. fi
  47. fi
  48. done
  49. }
  50. traverse_folder $cur_dir/..
  51. # traverse_folder $cur_dir/../../fate_flow/tests/api_tests
  52. echo "there are "$failed_count" failed test"
  53. if [ $failed_count -gt 0 ]; then
  54. exit 1
  55. fi