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

TF_RUN 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. . "$TF_DIR/include/subtest.sh"
  3. . "$TF_DIR/include/tools.sh"
  4. tf_enum_subtests() {
  5. echo "no_module"
  6. echo "empty_file"
  7. echo "no_declaration"
  8. echo "deep1"
  9. echo "deep2"
  10. echo "deep3"
  11. echo "deep4"
  12. echo "version_empty"
  13. echo "version_spaces"
  14. }
  15. mkwrapper() {
  16. #
  17. # Prepare script body
  18. #
  19. local modname=$1
  20. echo '#!/bin/bash'
  21. echo 'SHELLFU_PATH=test/shellfu'
  22. echo '. "$(sfpath)" || exit 3'
  23. echo "shellfu version $modname"
  24. }
  25. mkmodule() {
  26. #
  27. # Prepare module body
  28. #
  29. test "$name" == no_module && return 0
  30. {
  31. test "$name" == empty_file || {
  32. echo 'foo() {'
  33. echo ' echo hello'
  34. echo '}'
  35. }
  36. case $name in
  37. no_declaration)
  38. :
  39. ;;
  40. deep?)
  41. n=${name#deep}
  42. echo '#shellfu module-version: 0.1.2'
  43. while test "$n" -gt 1; do
  44. ((n--))
  45. echo
  46. done
  47. ;;
  48. version_empty)
  49. echo '#shellfu module-version:'
  50. ;;
  51. version_spaces)
  52. echo '#shellfu module-version: 0.1.2 '
  53. ;;
  54. esac
  55. } > "test/shellfu/$name.sh"
  56. }
  57. mkoracle() {
  58. case $name in
  59. deep1) echo 0.1.2 ;;
  60. deep2) echo 0.1.2 ;;
  61. deep3) echo 0.1.2 ;;
  62. version_spaces) echo 0.1.2 ;;
  63. esac > "oracle/$name.stdout"
  64. case $name in
  65. no_module) echo "shellfu: cannot find module: $name" ;;
  66. empty_file) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
  67. no_declaration) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
  68. deep4) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
  69. version_empty) echo "shellfu: missing version declaration: test/shellfu/$name.sh" ;;
  70. esac > "oracle/$name.stderr"
  71. }
  72. mkes() {
  73. case $name in
  74. deep1|deep2|deep3|version_spaces) echo 0 ;;
  75. no_module) echo 3 ;;
  76. *) echo 2 ;;
  77. esac
  78. }
  79. run_wrapper() {
  80. #
  81. # Run shellfu in wrapper
  82. #
  83. mkwrapper "$name" | bash
  84. }
  85. tf_do_subtest() {
  86. #
  87. # Prepare, run and check results of test $1
  88. #
  89. local name="$1"
  90. local o_es
  91. mkdir -p test/shellfu result oracle
  92. mkmodule
  93. mkoracle
  94. o_es=$(mkes)
  95. tf_testflt -n "$name" -O "oracle/$name.stdout" -E "oracle/$name.stderr" -S "$o_es" run_wrapper
  96. }
  97. tf_do_subtests