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.
 
 
 
 

129 regels
3.7 KiB

  1. #!/bin/bash
  2. VERSION=$(grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' _kosmorro/__version__.py)
  3. PYTHON_BIN=$(command -v python)
  4. PIP_BIN=$(command -v pip)
  5. if python3 --version > /dev/null; then
  6. PYTHON_BIN=$(command -v python3)
  7. PIP_BIN=$(command -v pip3)
  8. fi
  9. failures=''
  10. function fail() {
  11. failures="$failures\n\n - $1\n\n$2"
  12. }
  13. function run() {
  14. eval "$1" &> /tmp/output.txt
  15. return $?
  16. }
  17. function canRun() {
  18. if [[ "$1" != "" && "$1" != "$ENVIRONMENT" ]]; then
  19. return 1
  20. fi
  21. return 0
  22. }
  23. # Asserts that command $1 has finished with sucess
  24. # $1: the command to run
  25. function assertSuccess() {
  26. if ! canRun "$2"; then
  27. echo -n 'I'
  28. return
  29. fi
  30. run "$1"
  31. returned=$?
  32. if [ $returned -ne 0 ]; then
  33. fail "Failed asserting that command '$1' finishes with success, returned status $returned." "$(cat /tmp/output.txt)"
  34. echo -n 'F'
  35. return
  36. fi
  37. echo -n '.'
  38. }
  39. # Asserts that command $1 has finished with sucess
  40. # $1: the command to run
  41. function assertFailure() {
  42. if ! canRun "$2"; then
  43. echo -n 'I'
  44. return
  45. fi
  46. run "$1"
  47. returned=$?
  48. if [ $returned -eq 0 ]; then
  49. fail "Failed asserting that command '$1' finishes with failure." "$(cat /tmp/output.txt)"
  50. echo -n 'F'
  51. return
  52. fi
  53. echo -n '.'
  54. }
  55. mkdir -p $HOME/kosmorro/export
  56. echo
  57. echo "==== RUNNING E2E TESTS ===="
  58. echo
  59. # Create the package and install it
  60. assertSuccess "make build"
  61. assertSuccess "$PIP_BIN install dist/kosmorro-$VERSION.tar.gz" "CI"
  62. KOSMORRO_COMMAND="kosmorro --debug"
  63. assertSuccess "$KOSMORRO_COMMAND"
  64. assertSuccess "$KOSMORRO_COMMAND -h"
  65. assertSuccess "$KOSMORRO_COMMAND -d 2020-01-27"
  66. assertFailure "$KOSMORRO_COMMAND -d yolo-yo-lo"
  67. assertFailure "$KOSMORRO_COMMAND -d 2020-13-32"
  68. assertFailure "$KOSMORRO_COMMAND --date=1789-05-05"
  69. assertFailure "$KOSMORRO_COMMAND --date=3000-01-01"
  70. assertSuccess "$KOSMORRO_COMMAND --date='+3y 5m3d'"
  71. assertSuccess "$KOSMORRO_COMMAND --date='-1y3d'"
  72. assertFailure "$KOSMORRO_COMMAND --date='+3d4m"
  73. assertFailure "$KOSMORRO_COMMAND -date='3y'"
  74. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624"
  75. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27"
  76. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=1"
  77. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=-1"
  78. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=json"
  79. assertFailure "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf"
  80. assertSuccess "$KOSMORRO_COMMAND -d 2020-01-27 --format=json"
  81. # Environment variables
  82. assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=1 kosmorro -d 2020-01-27"
  83. assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=-1 kosmorro -d 2020-01-27"
  84. # Missing dependencies, should fail
  85. assertFailure "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o $HOME/kosmorro/export/document.pdf"
  86. assertFailure "ls $HOME/kosmorro/export/document.pdf"
  87. assertSuccess "sudo apt-get install -y texlive texlive-latex-extra" "CI"
  88. # Dependencies installed, should not fail
  89. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o $HOME/kosmorro/export/document.pdf"
  90. assertSuccess "ls $HOME/kosmorro/export/document.pdf"
  91. assertSuccess "$KOSMORRO_COMMAND --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o $HOME/kosmorro/export/document-no-graph.pdf --no-graph"
  92. assertSuccess "ls $HOME/kosmorro/export/document-no-graph.pdf"
  93. # man page
  94. assertSuccess "man --pager=cat kosmorro"
  95. if [ "$failures" != "" ]; then
  96. echo -e "\n$failures"
  97. exit 2
  98. fi
  99. echo -e "\n\n==== TESTS RAN SUCCESSFULLY 👍 ===="