Newer
Older
dub_jkp / test / run-unittest.sh
  1. #!/usr/bin/env bash
  2.  
  3. . $(dirname "${BASH_SOURCE[0]}")/common.sh
  4.  
  5. function log() {
  6. echo -e "\033[0;33m[INFO] "$@"\033[0m"
  7. }
  8.  
  9. function logError() {
  10. echo -e 1>&2 "\033[0;31m[ERROR] "$@"\033[0m"
  11. any_errors=1
  12. }
  13.  
  14. function die() {
  15. logError "$@"
  16. exit 1
  17. }
  18.  
  19. export -f log
  20. export -f die
  21.  
  22. if [ -z ${DUB:-} ]; then
  23. die 'Variable $DUB must be defined to run the tests.'
  24. fi
  25.  
  26. if [ -z ${DC:-} ]; then
  27. log '$DC not defined, assuming dmd...'
  28. DC=dmd
  29. fi
  30.  
  31. DC_BIN=$(basename "$DC")
  32. CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
  33.  
  34. for script in $(ls $CURR_DIR/*.sh); do
  35. if [ "$script" = "$(readlink -f ${BASH_SOURCE[0]})" ] || [ "$(basename $script)" = "common.sh" ]; then continue; fi
  36. if [ -e $script.min_frontend ] && [ ! -z ${FRONTEND:-} -a ${FRONTEND:-} \< $(cat $script.min_frontend) ]; then continue; fi
  37. log "Running $script..."
  38. DUB=$DUB DC=$DC CURR_DIR="$CURR_DIR" $script || logError "Script failure."
  39. done
  40.  
  41. for pack in $(ls -d $CURR_DIR/*/); do
  42. if [ -e $pack/.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $pack/.min_frontend) ]; then continue; fi
  43.  
  44. # First we build the packages
  45. if [ ! -e $pack/.no_build ] && [ ! -e $pack/.no_build_$DC_BIN ]; then # For sourceLibrary
  46. build=1
  47. if [ -e $pack/.fail_build ]; then
  48. log "Building $pack, expected failure..."
  49. $DUB build --force --root=$pack --compiler=$DC 2>/dev/null && logError "Error: Failure expected, but build passed."
  50. else
  51. log "Building $pack..."
  52. $DUB build --force --root=$pack --compiler=$DC || logError "Build failure."
  53. fi
  54. else
  55. build=0
  56. fi
  57.  
  58. # We run the ones that are supposed to be run
  59. if [ $build -eq 1 ] && [ ! -e $pack/.no_run ] && [ ! -e $pack/.no_run_$DC_BIN ]; then
  60. log "Running $pack..."
  61. $DUB run --force --root=$pack --compiler=$DC || logError "Run failure."
  62. fi
  63.  
  64. # Finally, the unittest part
  65. if [ $build -eq 1 ] && [ ! -e $pack/.no_test ] && [ ! -e $pack/.no_test_$DC_BIN ]; then
  66. log "Testing $pack..."
  67. $DUB test --force --root=$pack --compiler=$DC || logError "Test failure."
  68. fi
  69. done
  70.  
  71. exit ${any_errors:-0}