run.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. # basedir is the root of the test directory in the package
  3. basedir="$(dirname "$0")"
  4. [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
  5. # rootdir is the root of the package
  6. rootdir="$basedir/.."
  7. die()
  8. {
  9. [ -n "$*" ] && echo "$*" >&2
  10. exit 1
  11. }
  12. # $1=interpreter
  13. # $2=test_dir
  14. run_pyunit()
  15. {
  16. local interpreter="$1"
  17. local test_dir="$2"
  18. (
  19. echo
  20. echo "==="
  21. echo "= Running $interpreter, PWMAN_CRYPTOLIB=\"$PWMAN_CRYPTOLIB\""
  22. echo "==="
  23. export PYTHONPATH="$rootdir/tests:$PYTHONPATH"
  24. cd "$rootdir" || die "Failed to cd to rootdir."
  25. "$interpreter" -m unittest --failfast --buffer --catch --verbose "$test_dir" ||\
  26. die "Test failed"
  27. ) || die
  28. }
  29. # $1=test_dir
  30. run_testdir()
  31. {
  32. local test_dir="$1"
  33. unset PYTHONPATH
  34. unset PYTHONSTARTUP
  35. unset PYTHONY2K
  36. unset PYTHONOPTIMIZE
  37. unset PYTHONDEBUG
  38. export PYTHONDONTWRITEBYTECODE=1
  39. unset PYTHONINSPECT
  40. unset PYTHONIOENCODING
  41. unset PYTHONNOUSERSITE
  42. unset PYTHONUNBUFFERED
  43. unset PYTHONVERBOSE
  44. export PYTHONWARNINGS=once
  45. export PYTHONHASHSEED=random
  46. unset PWMAN_DATABASE
  47. unset PWMAN_RAWGETPASS
  48. unset PWMAN_CRYPTOLIB
  49. run_pyunit python3 "$test_dir"
  50. export PWMAN_CRYPTOLIB=cryptodome
  51. run_pyunit python3 "$test_dir"
  52. export PWMAN_CRYPTOLIB=pyaes
  53. run_pyunit python3 "$test_dir"
  54. }
  55. run_tests()
  56. {
  57. run_testdir tests
  58. }
  59. run_tests