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

TF_RUN 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. #shellcheck disable=SC1090
  3. . "$TF_DIR/include/subtest.sh"
  4. . "$TF_DIR/include/tools.sh"
  5. . "$(sfpath)" || tf_exit_error "failed to init shellfu"
  6. export PRETTY=plain
  7. shellfu import isa || tf_exit_error "failed to import isa"
  8. tf_enum_subtests() {
  9. local sut
  10. local ttype
  11. #
  12. # isa_
  13. #
  14. for sut in isa__bool isa__false isa__int isa__name isa__posint isa__true; do
  15. for ttype in ok empty none pfx sfx nota; do
  16. echo "${sut},$ttype"
  17. done
  18. done
  19. }
  20. mkfact() {
  21. #
  22. # Make artifact or oracle $what for $TestName
  23. #
  24. local what=$1
  25. case $TestName:$what in
  26. isa__bool,ok:arg) echo true ;;
  27. isa__bool,pfx:arg) echo xtrue ;;
  28. isa__bool,sfx:arg) echo truex ;;
  29. isa__bool,nota:arg) echo hello ;;
  30. isa__bool,tricky:arg) echo True ;;
  31. isa__bool,ok:o_es) echo 0 ;;
  32. isa__bool,*:o_es) echo 1 ;;
  33. isa__false,ok:arg) echo false ;;
  34. isa__false,pfx:arg) echo xfalse ;;
  35. isa__false,sfx:arg) echo falsex ;;
  36. isa__false,nota:arg) echo true ;;
  37. isa__false,tricky:arg) echo False ;;
  38. isa__false,ok:o_es) echo 0 ;;
  39. isa__false,*:o_es) echo 1 ;;
  40. isa__true,ok:arg) echo true ;;
  41. isa__true,pfx:arg) echo xtrue ;;
  42. isa__true,sfx:arg) echo truex ;;
  43. isa__true,nota:arg) echo True ;;
  44. isa__true,tricky:arg) echo 0 ;;
  45. isa__true,ok:o_es) echo 0 ;;
  46. isa__true,*:o_es) echo 1 ;;
  47. isa__int,ok:arg) echo 42 ;;
  48. isa__int,pfx:arg) echo x42 ;;
  49. isa__int,sfx:arg) echo 42x ;;
  50. isa__int,nota:arg) echo 22.2 ;;
  51. isa__int,tricky:arg) echo \ 42 ;;
  52. isa__int,ok:o_es) echo 0 ;;
  53. isa__int,*:o_es) echo 1 ;;
  54. isa__posint,ok:arg) echo 42 ;;
  55. isa__posint,pfx:arg) echo x42 ;;
  56. isa__posint,sfx:arg) echo 42x ;;
  57. isa__posint,nota:arg) echo -42 ;;
  58. isa__posint,tricky:arg) echo 42 + 55 ;;
  59. isa__posint,ok:o_es) echo 0 ;;
  60. isa__posint,*:o_es) echo 1 ;;
  61. isa__name,ok:arg) echo foo5az ;;
  62. isa__name,pfx:arg) echo .foo5az ;;
  63. isa__name,sfx:arg) echo foo5az/ ;;
  64. isa__name,nota:arg) echo 55zoos ;;
  65. isa__name,tricky:arg) echo foo bar ;;
  66. isa__name,ok:o_es) echo 0 ;;
  67. isa__name,*:o_es) echo 1 ;;
  68. esac
  69. }
  70. mkresult() {
  71. local sut
  72. local ttype
  73. local args=()
  74. ttype=${TestName##*,}
  75. sut=${TestName%,$ttype}
  76. type -t "$sut" >/dev/null || {
  77. tf_exit_error "no such function: $sut"
  78. }
  79. #shellcheck disable=SC2046
  80. case $ttype in
  81. none) : ;;
  82. empty) args=("") ;;
  83. more) args=(foo bar) ;;
  84. *) readarray -t args <<<"$(mkfact arg)" ;;
  85. esac
  86. "$sut" "${args[@]}"
  87. }
  88. tf_do_subtest() {
  89. local TestName=$1
  90. local o_es
  91. o_es=$(mkfact o_es)
  92. tf_testflt -n "$TestName" -S "$o_es" "mkresult"
  93. }
  94. tf_do_subtests