JAT - Just A Testing library https://pagure.io/shellfu-bash-jat

TF_RUN 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. #shellcheck disable=SC2016,SC1090
  3. . "$TF_DIR/include/subtest.sh"
  4. . "$TF_DIR/include/tools.sh"
  5. . "$(sfpath)" || tf_exit_error "failed to init shellfu"
  6. shellfu import jat || tf_exit_error "failed to import jat"
  7. tf_enum_subtests() {
  8. echo ylog_pass
  9. echo ylog_fail
  10. echo ylog_both
  11. }
  12. rndtoken() {
  13. head -c 100 /dev/urandom | md5sum | head -c 7
  14. }
  15. mkhacks() {
  16. echo '__JAT__SELF_VERSION=0.0.0+TESTED_VERSION'
  17. echo '__JAT__DETERMINISTIC=true'
  18. echo ''
  19. }
  20. mkhead() {
  21. echo '#!/bin/bash'
  22. echo ''
  23. echo '. "$(sfpath)" || exit 3'
  24. echo 'shellfu import jat'
  25. echo ''
  26. mkhacks
  27. echo ''
  28. echo "JAT__DIR=$PWD/result/$name/dir"
  29. echo "JAT__YLOG=$PWD/result/$name/ylog"
  30. echo ''
  31. echo 'jat__sinit'
  32. echo ''
  33. }
  34. mkbody() {
  35. #shellcheck disable=SC1003
  36. case $name in
  37. ylog_pass)
  38. echo ' jat__pstartt'
  39. echo ' jat__cmd -h "true is true" \'
  40. echo ' true'
  41. echo ' jat__cmd -h "false is false" -S 1 \'
  42. echo ' false'
  43. echo ' jat__pend'
  44. ;;
  45. ylog_fail)
  46. echo ' jat__pstartt'
  47. echo ' jat__cmd -h "true is false" -S 1 \'
  48. echo ' true'
  49. echo ' jat__cmd -h "false is true" -S 0 \'
  50. echo ' false'
  51. echo ' jat__pend'
  52. ;;
  53. ylog_both)
  54. echo ' jat__pstartt'
  55. echo ' jat__cmd -h "true is true" -S 0 \'
  56. echo ' true'
  57. echo ' jat__cmd -h "false is true" -S 0 \'
  58. echo ' false'
  59. echo ' jat__pend'
  60. ;;
  61. esac
  62. }
  63. mktail() {
  64. echo ''
  65. echo 'jat__sfinish'
  66. }
  67. unveil() {
  68. #
  69. # Remove arbitrary values
  70. #
  71. sed "
  72. s/^jat_version: .*$/jat_version: JAT_VERSION/
  73. "
  74. }
  75. runtest() {
  76. mkdir -p "test" "result/$name"
  77. {
  78. mkhead
  79. mkbody
  80. mktail
  81. } > "test/$name.sh"
  82. bash "test/$name.sh" 2>/dev/null
  83. < "result/$name/ylog" unveil
  84. }
  85. tf_do_subtest() {
  86. local name=$1
  87. local o_out=oracle/$name.stdout
  88. local o_err=oracle/$name.stderr
  89. tf_testflt -n "$name" -E "$o_err" -O "$o_out" runtest
  90. }
  91. tf_do_subtests