Newer
Older
dub_jkp / test / issue1856-build-unittest.sh
  1. #!/usr/bin/env bash
  2.  
  3. set -euo pipefail
  4.  
  5. TMPDIR=$(mktemp -d "$(basename "$0").XXXXXX")
  6.  
  7. function cleanup {
  8. rm -rf "$TMPDIR"
  9. }
  10. trap cleanup EXIT
  11.  
  12. # no unittest config
  13. cat > "$TMPDIR/no_ut.d" <<EOF
  14. /+ dub.sdl:
  15. name "no_ut"
  16. targetType "library"
  17. +/
  18. void foo() {}
  19. EOF
  20. $DUB describe --single "$TMPDIR/no_ut.d" --config=unittest | grep '"targetName": "no_ut-test-library"'
  21. $DUB build --single "$TMPDIR/no_ut.d" --config=unittest --build=unittest
  22. "$TMPDIR/no_ut-test-library"
  23.  
  24. # partial unittest config - targetPath only
  25. cat > "$TMPDIR/partial_ut.d" <<EOF
  26. /+ dub.sdl:
  27. name "partial_ut"
  28. targetType "library"
  29. configuration "unittest" {
  30. targetPath "bin"
  31. }
  32. +/
  33. void foo() {}
  34. EOF
  35. $DUB describe --single "$TMPDIR/partial_ut.d" --config=unittest | grep '"targetName": "partial_ut-test-unittest"'
  36. $DUB build --single "$TMPDIR/partial_ut.d" --config=unittest --build=unittest
  37. "$TMPDIR/bin/partial_ut-test-unittest"
  38.  
  39. # partial unittest config - targetPath & targetName
  40. cat > "$TMPDIR/partial_ut2.d" <<EOF
  41. /+ dub.sdl:
  42. name "partial_ut2"
  43. targetType "library"
  44. configuration "unittest" {
  45. targetPath "bin"
  46. targetName "ut"
  47. }
  48. +/
  49. void foo() {}
  50. EOF
  51. $DUB describe --single "$TMPDIR/partial_ut2.d" --config=unittest | grep '"targetName": "ut"'
  52. $DUB build --single "$TMPDIR/partial_ut2.d" --config=unittest --build=unittest
  53. "$TMPDIR/bin/ut"
  54.  
  55. # full unittest config (i.e., `executable` target type)
  56. cat > "$TMPDIR/full_ut.d" <<EOF
  57. /+ dub.sdl:
  58. name "full_ut"
  59. targetType "library"
  60. configuration "unittest" {
  61. targetType "executable"
  62. targetPath "bin"
  63. }
  64. +/
  65. void main() {}
  66. EOF
  67. $DUB describe --single "$TMPDIR/full_ut.d" --config=unittest | grep '"targetName": "full_ut"'
  68. $DUB build --single "$TMPDIR/full_ut.d" --config=unittest --build=unittest
  69. "$TMPDIR/bin/full_ut"