test.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. declare -r plugins_dir="./.tests/site/pack/deps/start"
  4. declare -r module="nui"
  5. declare test_scope="${module}"
  6. while [[ $# -gt 0 ]]; do
  7. case "${1}" in
  8. --clean)
  9. shift
  10. echo "[test] cleaning up environment"
  11. rm -rf "${plugins_dir}"
  12. echo "[test] envionment cleaned"
  13. ;;
  14. *)
  15. if [[ "${test_scope}" == "${module}" ]] && [[ "${1}" == "${module}/"* ]]; then
  16. test_scope="${1}"
  17. fi
  18. shift
  19. ;;
  20. esac
  21. done
  22. function setup_environment() {
  23. echo
  24. echo "[test] setting up environment"
  25. echo
  26. if [[ ! -d "${plugins_dir}" ]]; then
  27. mkdir -p "${plugins_dir}"
  28. fi
  29. if [[ ! -d "${plugins_dir}/plenary.nvim" ]]; then
  30. echo "[plugins] plenary.nvim: installing..."
  31. git clone https://github.com/nvim-lua/plenary.nvim "${plugins_dir}/plenary.nvim"
  32. # commit 9069d14a120cadb4f6825f76821533f2babcab92 broke luacov
  33. # issue: https://github.com/nvim-lua/plenary.nvim/issues/353
  34. local -r plenary_353_patch="$(pwd)/scripts/plenary-353.patch"
  35. git -C "${plugins_dir}/plenary.nvim" apply "${plenary_353_patch}"
  36. echo "[plugins] plenary.nvim: installed"
  37. echo
  38. fi
  39. echo "[test] environment ready"
  40. echo
  41. }
  42. function luacov_start() {
  43. luacov_dir="$(dirname "$(luarocks which luacov 2>/dev/null | head -1)")"
  44. if [[ "${luacov_dir}" == "." ]]; then
  45. luacov_dir=""
  46. fi
  47. if test -n "${luacov_dir}"; then
  48. rm -f luacov.*.out
  49. export LUA_PATH=";;${luacov_dir}/?.lua"
  50. fi
  51. }
  52. function luacov_end() {
  53. if test -n "${luacov_dir}"; then
  54. if test -f "luacov.stats.out"; then
  55. luacov
  56. echo
  57. tail -n +$(($(grep -n "^Summary$" luacov.report.out | cut -d":" -f1) - 1)) luacov.report.out
  58. fi
  59. fi
  60. }
  61. setup_environment
  62. luacov_start
  63. declare test_logs=""
  64. if [[ -d "./tests/${test_scope}/" ]]; then
  65. test_logs=$(nvim --headless --noplugin -u tests/init.lua -c "lua require('plenary.test_harness').test_directory('./tests/${test_scope}/', { minimal_init = 'tests/init.lua', sequential = true })" || true)
  66. elif [[ -f "./tests/${test_scope}_spec.lua" ]]; then
  67. test_logs=$(nvim --headless --noplugin -u tests/init.lua -c "lua require('plenary.busted').run('./tests/${test_scope}_spec.lua')" || true)
  68. fi
  69. echo "${test_logs}"
  70. luacov_end
  71. if echo "${test_logs}" | grep --quiet "stack traceback"; then
  72. {
  73. echo ""
  74. echo "FOUND STACK TRACEBACK IN TEST LOGS"
  75. echo ""
  76. } >&2
  77. exit 1
  78. fi