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.
 
 
 
 

119 lines
3.2 KiB

  1. #!/bin/bash
  2. VERSION=$(grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' kosmorrolib/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. echo
  56. echo "==== RUNNING E2E TESTS ===="
  57. echo
  58. # Create the package and install it
  59. assertSuccess "make build"
  60. assertSuccess "$PIP_BIN install dist/kosmorro-$VERSION.tar.gz" "CI"
  61. assertSuccess kosmorro
  62. assertSuccess "kosmorro -h"
  63. assertSuccess "kosmorro -d 2020-01-27"
  64. assertFailure "kosmorro -d yolo-yo-lo"
  65. assertFailure "kosmorro -d 2020-13-32"
  66. assertFailure "kosmorro --date=1789-05-05"
  67. assertFailure "kosmorro --date=3000-01-01"
  68. assertSuccess "kosmorro --date='+3y 5m3d'"
  69. assertSuccess "kosmorro --date='-1y3d'"
  70. assertFailure "kosmorro --date='+3d4m"
  71. assertFailure "kosmorro -date='3y'"
  72. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624"
  73. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27"
  74. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=1"
  75. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --timezone=-1"
  76. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=json"
  77. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf"
  78. # Environment variables
  79. assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=1 kosmorro -d 2020-01-27"
  80. assertSuccess "LATITUDE=50.5876 LONGITUDE=3.0624 TIMEZONE=-1 kosmorro -d 2020-01-27"
  81. # Missing dependencies, should fail
  82. assertFailure "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf"
  83. assertSuccess "sudo apt-get install -y texlive texlive-latex-extra" "CI"
  84. # Dependencies installed, should not fail
  85. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf"
  86. assertSuccess "kosmorro --latitude=50.5876 --longitude=3.0624 -d 2020-01-27 --format=pdf -o /tmp/document.pdf --no-graph"
  87. # man page
  88. assertSuccess "man --pager=cat kosmorro"
  89. if [ "$failures" != "" ]; then
  90. echo -e "\n$failures"
  91. exit 2
  92. fi
  93. echo -e "\n\n==== TESTS RAN SUCCESSFULLY 👍 ===="