This fork extends the command line interface (CLI) and is distributed as a convenient one-file-executable (Windows, Linux, Mac). It is also available via Docker Hub, PyPI and Binder.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

124 lines
3.8 KiB

  1. #!/bin/bash
  2. # Script for running functional tests against the CLI
  3. # Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>
  14. # ================================== CONFIG ================================== #
  15. cd "${BASH_SOURCE%/*}/" || exit 1
  16. port=3334
  17. if [[ ${1} ]]; then
  18. version="${1}"
  19. else
  20. version="3.2"
  21. fi
  22. refine="openrefine-${version}/refine"
  23. if [[ ${2} ]]; then
  24. client="$(readlink -e "${2}")"
  25. else
  26. client="python2 $(readlink -e refine.py)"
  27. fi
  28. cmd="${client} -H localhost -P ${port}"
  29. if [[ ${3} ]]; then
  30. filename="${3%%.*}"
  31. else
  32. filename=""
  33. fi
  34. cmd="${client} -H localhost -P ${port}"
  35. # =============================== REQUIREMENTS =============================== #
  36. # check existence of java and cURL
  37. if [[ -z "$(command -v java 2> /dev/null)" ]] ; then
  38. echo 1>&2 "ERROR: OpenRefine requires JAVA runtime environment (jre)" \
  39. "https://openjdk.java.net/install/"
  40. exit 1
  41. fi
  42. if [[ -z "$(command -v curl 2> /dev/null)" ]] ; then
  43. echo 1>&2 "ERROR: This shell script requires cURL" \
  44. "https://curl.haxx.se/download.html"
  45. exit 1
  46. fi
  47. # download OpenRefine
  48. if [[ -z "$(readlink -e "${refine}")" ]]; then
  49. echo "Download OpenRefine ${version}..."
  50. mkdir -p "$(dirname "${refine}")"
  51. curl -L --output openrefine.tar.gz \
  52. "https://github.com/OpenRefine/OpenRefine/releases/download/${version}/openrefine-linux-${version}.tar.gz"
  53. echo "Install OpenRefine ${version} in subdirectory $(dirname "${refine}")..."
  54. tar -xzf openrefine.tar.gz -C "$(dirname "${refine}")" --strip 1 --totals
  55. rm -f openrefine.tar.gz
  56. # do not try to open OpenRefine in browser
  57. sed -i '$ a JAVA_OPTIONS=-Drefine.headless=true' \
  58. "$(dirname "${refine}")"/refine.ini
  59. # set autosave period from 5 minutes to 25 hours
  60. sed -i 's/#REFINE_AUTOSAVE_PERIOD=60/REFINE_AUTOSAVE_PERIOD=1500/' \
  61. "$(dirname "${refine}")"/refine.ini
  62. echo
  63. fi
  64. # ================================== SETUP =================================== #
  65. dir="$(readlink -f "tests/tmp")"
  66. mkdir -p "${dir}"
  67. rm -f tests-cli.log
  68. echo "start OpenRefine ${version}..."
  69. ${refine} -v warn -p ${port} -d "${dir}" &>> tests-cli.log &
  70. pid_server=${!}
  71. timeout 30s bash -c "until curl -s 'http://localhost:3334' \
  72. | cat | grep -q -o 'OpenRefine' ; do sleep 1; done" \
  73. || error "starting OpenRefine server failed!"
  74. echo
  75. # ================================== TESTS =================================== #
  76. echo "running tests, please wait..."
  77. tests=()
  78. results=()
  79. for t in tests/*${filename}*.sh; do
  80. tests+=("${t}")
  81. echo "======================= ${t} =======================" &>> tests-cli.log
  82. bash "${t}" "${cmd}" "${version}" &>> tests-cli.log
  83. results+=(${?})
  84. done
  85. echo
  86. # ================================= TEARDOWN ================================= #
  87. echo "cleanup..."
  88. { kill -9 "${pid_server}" && wait "${pid_server}"; } 2>/dev/null
  89. rm -rf "${dir}"
  90. echo
  91. # ================================= SUMMARY ================================== #
  92. printf "%s\t%s\n" "code" "test"
  93. printf "%s\t%s\n" "----" "----------------"
  94. for i in "${!tests[@]}"; do
  95. printf "%s\t%s\n" "${results[$i]}" "${tests[$i]}"
  96. done
  97. echo
  98. if [[ " ${results[*]} " =~ [1-9] ]]; then
  99. echo "failed tests! check tests-cli.log for debugging"; echo
  100. else
  101. echo "all tests passed!"; echo
  102. fi