Newer
Older
dub_jkp / test / run-unittest.sh
@Sönke Ludwig Sönke Ludwig on 27 Feb 2016 1 KB Echo test commands.
  1. #!/bin/bash
  2.  
  3. set -v
  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"$@"\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 'Error: 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. CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
  32.  
  33. for script in $(ls $CURR_DIR/*.sh); do
  34. if [ "$script" = "$(readlink -f ${BASH_SOURCE[0]})" ]; then continue; fi
  35. if [ -e $script.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $script.min_frontend) ]; then continue; fi
  36. log "Running $script..."
  37. DUB=$DUB DC=$DC CURR_DIR="$CURR_DIR" $script || logError "Script failure."
  38. done
  39.  
  40. for pack in $(ls -d $CURR_DIR/*/); do
  41. if [ -e $pack/.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $pack/.min_frontend) ]; then continue; fi
  42. # First we build the packages
  43. if [ ! -e $pack/.no_build ]; then # For sourceLibrary
  44. if [ -e $pack/.fail_build ]; then
  45. log "Building $pack, expected failure..."
  46. $DUB build --force --root=$pack --compiler=$DC 2>/dev/null && logError "Error: Failure expected, but build passed."
  47. else
  48. log "Building $pack..."
  49. $DUB build --force --root=$pack --compiler=$DC || logError "Build failure."
  50. fi
  51. fi
  52.  
  53. # We run the ones that are supposed to be runned
  54. if [ ! -e $pack/.no_build ] && [ ! -e $pack/.no_run ]; then
  55. log "Running $pack..."
  56. $DUB run --force --root=$pack --compiler=$DC || logError "Run failure."
  57. fi
  58.  
  59. # Finally, the unittest part
  60. if [ ! -e $pack/.no_build ] && [ ! -e $pack/.no_test ]; then
  61. log "Testing $pack..."
  62. $DUB test --force --root=$pack --compiler=$DC || logError "Test failure."
  63. fi
  64. done
  65.  
  66. exit $any_errors