shell dot on steroids https://pagure.io/shellfu

TF_RUN 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/bash
  2. #shellcheck disable=SC1090
  3. . "$TF_DIR/include/subtest.sh"
  4. . "$TF_DIR/include/tools.sh"
  5. tf_enum_subtests() {
  6. echo "no_module"
  7. echo "empty_file"
  8. echo "no_directive"
  9. echo "deep1"
  10. echo "deep2"
  11. echo "deep3"
  12. echo "deep4"
  13. echo "1directive"
  14. echo "2directives"
  15. echo "3directives"
  16. echo "twins"
  17. echo "twins"
  18. echo "updown"
  19. echo "directive_empty"
  20. echo "directive_spaces"
  21. }
  22. mkresult() {
  23. #
  24. # Prepare script body
  25. #
  26. #shellcheck disable=SC2016
  27. {
  28. echo '#!/bin/bash'
  29. echo 'SHELLFU_PATH=test/shellfu'
  30. echo '. "$(sfpath)" || exit 3'
  31. echo "shellfu _read_directive dname test/shellfu/$TF_SUBTEST.sh"
  32. } | bash
  33. }
  34. mkmodule() {
  35. #
  36. # Prepare module body
  37. #
  38. test "$TF_SUBTEST" == no_module && return 0
  39. {
  40. case $TF_SUBTEST in
  41. updown) echo '#shellfu dname=dvalue'
  42. esac
  43. test "$TF_SUBTEST" == empty_file || {
  44. echo 'foo() {'
  45. echo ' echo hello'
  46. echo '}'
  47. }
  48. case $TF_SUBTEST in
  49. no_directive)
  50. :
  51. ;;
  52. deep?)
  53. n=${TF_SUBTEST#deep}
  54. echo '#shellfu dname=dvalue'
  55. while test "$n" -gt 1; do
  56. ((n--))
  57. echo
  58. done
  59. ;;
  60. updown)
  61. echo '#shellfu dname=dvalue2'
  62. ;;
  63. directive_empty)
  64. echo '#shellfu dname='
  65. ;;
  66. twins)
  67. echo '#shellfu dname=dvalue dname=dvalue2'
  68. ;;
  69. 1directive)
  70. echo '#shellfu dname=dvalue'
  71. ;;
  72. 2directives)
  73. echo '#shellfu name=value dname=dvalue'
  74. ;;
  75. 3directives)
  76. echo '#shellfu name=value dname=dvalue name=value'
  77. ;;
  78. directive_spaces)
  79. echo '#shellfu dname=dvalue '
  80. ;;
  81. esac
  82. } > "test/shellfu/$TF_SUBTEST.sh"
  83. }
  84. mkoracle() {
  85. case $TF_SUBTEST in
  86. deep1) echo -n dvalue ;;
  87. deep2) echo -n dvalue ;;
  88. deep3) echo -n dvalue ;;
  89. twins) echo -n dvalue ;;
  90. updown) echo -n dvalue ;;
  91. 1directive) echo -n dvalue ;;
  92. 2directives) echo -n dvalue ;;
  93. 3directives) echo -n dvalue ;;
  94. directive_spaces) echo -n dvalue ;;
  95. esac > "oracle/$TF_SUBTEST.stdout"
  96. local f="shellfu:fatal:"
  97. local w="shellfu:"
  98. local m="test/shellfu/$TF_SUBTEST.sh"
  99. case $TF_SUBTEST in
  100. no_module) echo "$f no such file: $m" ;;
  101. empty_file) echo "$w directive not found: 'dname' in '$m'" ;;
  102. no_directive) echo "$w directive not found: 'dname' in '$m'" ;;
  103. deep4) echo "$w directive not found: 'dname' in '$m'" ;;
  104. esac > "oracle/$TF_SUBTEST.stderr"
  105. }
  106. mkes() {
  107. case $TF_SUBTEST in
  108. empty_file) return 2 ;;
  109. no_directive) return 2 ;;
  110. deep4) return 2 ;;
  111. directive_empty) return 1 ;;
  112. no_module) return 3 ;;
  113. esac
  114. return 0
  115. }
  116. tf_do_subtest() {
  117. #
  118. # Prepare, run and check results of test $1
  119. #
  120. local o_es
  121. mkdir -p test/shellfu result oracle
  122. mkmodule
  123. mkoracle
  124. mkes; o_es=$?
  125. tf_testflt \
  126. -n "$TF_SUBTEST" \
  127. -O "oracle/$TF_SUBTEST.stdout" \
  128. -E "oracle/$TF_SUBTEST.stderr" \
  129. -S "$o_es" mkresult
  130. }
  131. tf_do_subtests