test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. #
  3. # Run all tests.
  4. #
  5. set -euC
  6. vimgodir=$(cd -P "$(dirname "$0")/.." > /dev/null && pwd)
  7. cd "$vimgodir"
  8. _usage() {
  9. echo "Usage: ${0##*/} [-hvc] [-r file] vim_version"
  10. echo
  11. echo "Options:"
  12. echo " -h Show this help"
  13. echo " -v Enable verbose output"
  14. echo " -r Run only the tests from this file"
  15. echo " -c Generate and submit code coverage reports"
  16. echo
  17. }
  18. verbose=0
  19. run=""
  20. coverage=""
  21. while getopts "hvcr:" option; do
  22. case "$option" in
  23. h) _usage; exit 0 ;;
  24. v) verbose=1; ;;
  25. r) run=$OPTARG ;;
  26. c) coverage="-c" ;;
  27. *)
  28. echo "error: unknown option '$option'"
  29. _usage
  30. exit 1
  31. ;;
  32. esac
  33. done
  34. shift $((OPTIND - 1))
  35. ### Setup Vim and other dependencies.
  36. #####################################
  37. if [ -z "${1:-}" ]; then
  38. echo "unknown version: '${1:-}'"
  39. echo "First argument must be 'vim-7.4', 'vim-8.0', or 'nvim'."
  40. exit 1
  41. fi
  42. vim=$1
  43. vimdir="/tmp/vim-go-test/$vim-install"
  44. export GOPATH=$vimdir
  45. export PATH=${GOPATH}/bin:$PATH
  46. if [ ! -f "$vimdir/bin/vim" ]; then
  47. echo "$vimdir/bin/vim doesn't exist; did you install it with the install-vim script?"
  48. exit 1
  49. fi
  50. ### Run tests.
  51. ##############
  52. # Clean stale log file.
  53. [ -f '/tmp/vim-go-test/test.log' ] && rm '/tmp/vim-go-test/test.log'
  54. [ -f '/tmp/vim-go-test/FAILED' ] && rm '/tmp/vim-go-test/FAILED'
  55. [ -f '/tmp/vim-go-test/cov-profile.txt' ] && rm '/tmp/vim-go-test/cov-profile.txt'
  56. [ -f '/tmp/vim-go-test/cov-report.txt' ] && rm '/tmp/vim-go-test/cov-report.txt'
  57. # Run the actual tests.
  58. find "$vimgodir" -name '*_test.vim' | while read test_file; do
  59. [ -n "$run" -a "$(basename "$test_file")" != "$run" ] && continue
  60. "$vimgodir/scripts/run-vim" $coverage $vim -e \
  61. +"silent e $test_file" \
  62. +"let g:test_verbose=$verbose" \
  63. -S ./scripts/runtest.vim < /dev/null || (
  64. # If Vim exits with non-0 it's almost certainly a bug in the test runner;
  65. # should very rarely happen in normal usage.
  66. echo 'test runner failure'
  67. cat '/tmp/vim-go-test/test.tmp'
  68. rm '/tmp/vim-go-test/test.tmp'
  69. exit 5
  70. )
  71. # Append logs
  72. cat '/tmp/vim-go-test/test.tmp' | tee '/tmp/vim-go-test/test.log'
  73. rm '/tmp/vim-go-test/test.tmp'
  74. done
  75. echo
  76. if [ -f "/tmp/vim-go-test/FAILED" ]; then
  77. echo 2>&1 "Some ($vim) tests FAILED"
  78. exit 1
  79. fi
  80. echo 2>&1 "All ($vim) tests PASSED"
  81. # Submit coverage reports
  82. if [ -n "$coverage" ]; then
  83. coverage xml --omit '*_test.vim'
  84. codecov -X search gcov pycov -f coverage.xml --required \
  85. --flags "$(echo "$vim" | sed -s 's/[-.]//g')"
  86. rm coverage.xml
  87. fi
  88. # vim:ts=2:sts=2:sw=2:et