No Description
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.

runtest.sh 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. #
  3. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  4. #
  5. # Copyright (C) 2015-2017 Cléo UMS-3287
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License, version 3,
  9. # as published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...]
  20. #########
  21. #
  22. # Running all discoverables tests :
  23. # ./runtest
  24. #
  25. ################
  26. # -f, --failfast
  27. #
  28. # Stop the test run on the first error or failure.
  29. # -v --verbose
  30. #
  31. # higher verbosity
  32. #
  33. # -d 0 : results are not displayed but stored in logfiles in /tmp/logXXXXXXX repository, with XXXXXXX a timestamp (default)
  34. # -d 1 : results are displayed when tests finish and kept in logfiles in /tmp/logXXXXXXX repository, with XXXXXXX a timestamp
  35. # -d 2 : results are displayed when tests finish, they are not stored
  36. #
  37. # Furthermore
  38. ################
  39. # Most of the tests need an install of lodel for dependencies reasons
  40. # For those which not need, prefix the python file by 'nc_' (example nc_test_query.py)
  41. # they will be executed outside a lodel install
  42. # More details :
  43. ################
  44. #
  45. # https://docs.python.org/3.4/library/unittest.html
  46. #
  47. if test ! -f lodel/buildconf.py
  48. then
  49. echo "You have to build the project before running the tests"
  50. echo "See README"
  51. exit 1
  52. fi
  53. logdisplay=2;
  54. while getopts ":d:" opt; do
  55. case $opt in
  56. d)
  57. logdisplay=$OPTARG
  58. ;;
  59. :)
  60. echo "Option -$OPTARG requires an argument, as it does not have we assume 0"
  61. ;;
  62. esac
  63. done
  64. if [[ $logdisplay -eq 2 ]]
  65. then
  66. echo $logdisplay
  67. logdir=$(mktemp -td "lodel2_log_unittest_XXXXXXX")
  68. else
  69. if [ ! -d ./tmp ]
  70. then
  71. mkdir ./tmp
  72. fi
  73. timestamp=$(date +%s)
  74. logdir="$(dirname $(realpath $0))/tmp/log$timestamp"
  75. mkdir $logdir
  76. fi
  77. PYTHON='env python3'
  78. ret_status=0
  79. $PYTHON ./nocontext_tests.py $logdir $@ || ret_status=1
  80. ./runtest_context.sh $logdir $@ || ret_status=1
  81. if [[ $logdisplay -eq 1 || $logdisplay -eq 2 ]]
  82. then
  83. logfiles=$(ls $logdir)
  84. for logfile in $logfiles
  85. do
  86. cat $logdir/$logfile
  87. done
  88. if [[ $logdisplay -eq 2 ]]
  89. then
  90. rm -rf $logdir
  91. fi
  92. fi
  93. exit $ret_status