test_startup.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. run() {
  3. pwd
  4. output=$({ timeout 10 ./$1 $2; } 2>&1)
  5. exitcode=$?
  6. test $exitcode -eq 124 && exitcode=0 # exitcode 124 is comming from "timeout command above"
  7. echo $output | grep -e "NiceGUI ready to go" -e "Uvicorn running on http://127.0.0.1:8000" > /dev/null || exitcode=1
  8. echo $output | grep "Traceback" > /dev/null && exitcode=1
  9. echo $output | grep "Error" > /dev/null && exitcode=1
  10. if test $exitcode -ne 0; then
  11. echo "wrong exit code $exitcode. Output was:"
  12. echo $output
  13. return 1
  14. fi
  15. }
  16. check() {
  17. echo checking $1 ----------
  18. pushd $(dirname "$1") >/dev/null
  19. if run $(basename "$1") $2; then
  20. echo "ok --------"
  21. popd > /dev/null
  22. else
  23. echo "failed -------"
  24. popd > /dev/null
  25. return 1
  26. fi
  27. }
  28. error=0
  29. check main.py || error=1
  30. for path in examples/*
  31. do
  32. if [[ $path == *"chat_with_ai"* ]] && [[ $(python3 --version) == *"3.7"* ]]; then
  33. # NOTE: chat_with_ai example is not working with python 3.7
  34. continue
  35. fi
  36. if [[ $path == *"ai_interface"* ]] && [[ $(python3 --version) == *"3.7"* ]]; then
  37. # NOTE: ai_interface example is not working with python 3.7
  38. continue
  39. fi
  40. if test -f $path/start.sh; then
  41. check $path/start.sh dev || error=1
  42. elif test -f $path/main.py; then
  43. check $path/main.py || error=1
  44. fi
  45. done
  46. test $error -eq 0