Poor man's XPath library https://pagure.io/shellfu-bash-pxpath

subtest.sh 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. . "$TF_DIR/include/common.sh"
  3. tf_enum_subtests() {
  4. #
  5. # Stub: enumerate subtests
  6. #
  7. tf_warn "implement tf_enum_subtests()!"
  8. return "$TF_ES_ERROR"
  9. }
  10. tf_do_subtest() {
  11. #
  12. # Stub: perform test named $1
  13. #
  14. tf_warn "implement tf_do_subtest()!"
  15. return "$TF_ES_ERROR"
  16. }
  17. _tf_do_subtest() {
  18. #
  19. # Run single subtest inc. setup/cleanup if present
  20. #
  21. local subtname="$1" # this subtest name
  22. local ses=0 # subtest exit status
  23. local setup=true # setup command
  24. local cleanup=true # cleanup command
  25. if test -f TF_SETUP;
  26. then
  27. setup=". TF_SETUP"
  28. bash -n TF_SETUP || {
  29. tf_warn "synax errors in TF_SETUP, skipping"
  30. return "$TF_ES_ERROR"
  31. }
  32. fi
  33. if test -f TF_CLEANUP;
  34. then
  35. setup=". TF_CLEANUP"
  36. bash -n TF_CLEANUP || {
  37. tf_warn "synax errors in TF_CLEANUP, skipping"
  38. return "$TF_ES_ERROR"
  39. }
  40. fi
  41. if $setup;
  42. then
  43. tf_do_subtest "$subtname"; ses=$?
  44. else
  45. tf_warn "setup phase failed, skipping: $subtname"
  46. ses=$TF_ES_ERROR
  47. fi
  48. if ! $cleanup;
  49. then
  50. tf_warn "cleanup phase failed: $subtname"
  51. ses=$TF_ES_PANIC
  52. fi
  53. return "$ses"
  54. }
  55. tf_do_subtests() {
  56. #
  57. # Run all subtests and return highest status
  58. #
  59. local es=0 # final exit status ("worst" of subtests)
  60. local subtname="" # one subtest name
  61. local tes="" # one subtest exit status
  62. local enumd=TF_ENUMERATED_SUBTESTS
  63. local fltrd=TF_FILTERED_SUBTESTS
  64. tf_enum_subtests >$enumd || { tf_warn "error enumerating subtests"; return "$TF_ES_BAILOUT"; }
  65. test -s $enumd || { tf_warn "no subtests enumerated"; return "$TF_ES_BAILOUT"; }
  66. grep -e "$TF_FILTER_SUBTEST" $enumd > $fltrd
  67. test -s $fltrd || tf_debug "TF_FILTER_SUBTEST ate everything: $TF_FILTER_SUBTEST"
  68. for subtname in $(<$fltrd);
  69. do
  70. tf_think "::: $TF_TEST::$subtname"
  71. TF_SUBTEST=$subtname _tf_do_subtest "$subtname";
  72. tes=$?
  73. test $tes -gt $es && es=$tes
  74. test $tes -gt "$TF_ES_OK" && tf_warn "!!! $TF_TEST::$subtname ($tes)"
  75. test $tes -gt "$TF_ES_BAILOUT" && break
  76. done
  77. return $es
  78. }