Newer
Older
dub_jkp / test / issue1531-toolchain-requirements.sh
  1. #!/usr/bin/env bash
  2. set -e
  3.  
  4. . $(dirname "${BASH_SOURCE[0]}")/common.sh
  5.  
  6. cat << EOF | $DUB - || die $LINENO "Did not pass without toolchainRequirements"
  7. /+ dub.sdl:
  8. +/
  9. void main() {}
  10. EOF
  11.  
  12. # pass test dub requirement given as $1
  13. function test_dub_req_pass {
  14. cat << EOF | $DUB - || die $LINENO "Did not pass requirement dub=\"$1\""
  15. /+ dub.sdl:
  16. toolchainRequirements dub="$1"
  17. +/
  18. void main() {}
  19. EOF
  20. }
  21.  
  22. # fail test dub requirement given as $1
  23. function test_dub_req_fail {
  24. ! cat << EOF | $DUB - || die $LINENO "Did not pass requirement dub=\"$1\""
  25. /+ dub.sdl:
  26. toolchainRequirements dub="$1"
  27. +/
  28. void main() {}
  29. EOF
  30. }
  31.  
  32. test_dub_req_pass ">=1.7.0"
  33. test_dub_req_fail "~>0.9"
  34. test_dub_req_fail "~>999.0"
  35.  
  36. # extract compiler version
  37. if [[ $DC == *ldc* ]] || [[ $DC == *ldmd* ]]; then
  38. VER_REG='\((([[:digit:]]+)(\.[[:digit:]]+\.[[:digit:]]+[A-Za-z0-9.+-]*))\)'
  39. DC_NAME=ldc
  40. elif [[ $DC == *dmd* ]]; then
  41. VER_REG='v(([[:digit:]]+)(\.[[:digit:]]+\.[[:digit:]]+[A-Za-z0-9.+-]*))'
  42. DC_NAME=dmd
  43. elif [[ $DC == *gdc* ]]; then
  44. VER_REG='\) (([[:digit:]]+)(\.[[:digit:]]+\.[[:digit:]]+[A-Za-z0-9.+-]*))'
  45. DC_NAME=gdc
  46. else
  47. die $LINENO "Did not recognize compiler"
  48. fi
  49. if [[ $($DC --version) =~ $VER_REG ]]; then
  50. DC_VER=${BASH_REMATCH[1]}
  51. DC_VER_MAJ=${BASH_REMATCH[2]}
  52. DC_VER_REM=${BASH_REMATCH[3]}
  53. $DC --version
  54. echo $DC version is $DC_VER
  55. else
  56. $DC --version
  57. die $LINENO "Could not extract compiler version"
  58. fi
  59.  
  60. # create test app directory
  61. TMPDIR=$(mktemp -d /tmp/dubtest1531_XXXXXX)
  62. mkdir -p $TMPDIR/source
  63. cat << EOF > $TMPDIR/source/app.d
  64. module dubtest1531;
  65. void main() {}
  66. EOF
  67.  
  68. # write dub.sdl with compiler requirement given as $1
  69. function write_cl_req {
  70. cat << EOF > $TMPDIR/dub.sdl
  71. name "dubtest1531"
  72. toolchainRequirements ${DC_NAME}="$1"
  73. EOF
  74. }
  75.  
  76. # pass test compiler requirement given as $1
  77. function test_cl_req_pass {
  78. echo "Expecting success on '$DC $1'" 2>&1
  79. write_cl_req $1
  80. $DUB build -q --compiler=$DC --root=$TMPDIR || die $LINENO "Did not pass with $DC_NAME=\"$1\""
  81. }
  82.  
  83. # fail test compiler requirement given as $1
  84. function test_cl_req_fail {
  85. echo "Expecting failure on '$DC $1'" 2>&1
  86. write_cl_req $1
  87. ! $DUB --compiler=$DC --root=$TMPDIR || die $LINENO "Did not fail with $DC_NAME=\"$1\""
  88. }
  89.  
  90.  
  91. test_cl_req_pass "==$DC_VER"
  92. test_cl_req_pass ">=$DC_VER"
  93. test_cl_req_fail ">$DC_VER"
  94. test_cl_req_pass "<=$DC_VER"
  95. test_cl_req_fail "<$DC_VER"
  96. test_cl_req_pass ">=$DC_VER <$(($DC_VER_MAJ + 1))$DC_VER_REM"
  97. test_cl_req_pass "~>$DC_VER"
  98. test_cl_req_fail "~>$(($DC_VER_MAJ + 1))$DC_VER_REM"
  99. test_cl_req_fail no
  100.  
  101. rm -rf $TMPDIR