/tests/aggregate-results.sh

https://code.google.com/ · Shell · 81 lines · 75 code · 5 blank · 1 comment · 13 complexity · f60d93134ce10b67d8a96a502980b29f MD5 · raw file

  1. #!/bin/sh
  2. fixed=0
  3. success=0
  4. failed=0
  5. broken=0
  6. total=0
  7. for file
  8. do
  9. while read type value
  10. do
  11. case $type in
  12. '')
  13. continue ;;
  14. fixed)
  15. fixed=$(($fixed + $value)) ;;
  16. success)
  17. success=$(($success + $value)) ;;
  18. failed)
  19. failed=$(($failed + $value)) ;;
  20. broken)
  21. broken=$(($broken + $value)) ;;
  22. total)
  23. total=$(($total + $value)) ;;
  24. esac
  25. done <"$file"
  26. done
  27. pluralize () {
  28. case $2 in
  29. 1)
  30. case $1 in
  31. test)
  32. echo test ;;
  33. failure)
  34. echo failure ;;
  35. esac
  36. ;;
  37. *)
  38. case $1 in
  39. test)
  40. echo tests ;;
  41. failure)
  42. echo failures ;;
  43. esac
  44. ;;
  45. esac
  46. }
  47. echo "pdsh test suite complete."
  48. if [ "$fixed" = "0" ] && [ "$failed" = "0" ]; then
  49. tests=$(pluralize "test" $total)
  50. printf "All $total $tests "
  51. if [ "$broken" = "0" ]; then
  52. echo "passed."
  53. else
  54. failures=$(pluralize "failure" $broken)
  55. echo "behaved as expected ($broken expected $failures)."
  56. fi;
  57. else
  58. echo "$success/$total tests passed."
  59. if [ "$broken" != "0" ]; then
  60. tests=$(pluralize "test" $broken)
  61. echo "$broken broken $tests failed as expected."
  62. fi
  63. if [ "$fixed" != "0" ]; then
  64. tests=$(pluralize "test" $fixed)
  65. echo "$fixed broken $tests now fixed."
  66. fi
  67. if [ "$failed" != "0" ]; then
  68. tests=$(pluralize "test" $failed)
  69. echo "$failed $tests failed."
  70. fi
  71. fi
  72. skipped=$(($total - $fixed - $success - $failed - $broken))
  73. if [ "$skipped" != "0" ]; then
  74. tests=$(pluralize "test" $skipped)
  75. echo "$skipped $tests skipped."
  76. fi