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