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