common.sh 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #
  2. # Variables to hold exit status semantic
  3. #
  4. TF_ES_OK=0
  5. TF_ES_FAIL=1
  6. TF_ES_BAILOUT=2
  7. TF_ES_ERROR=3
  8. TF_ES_PANIC=4
  9. #
  10. # Option to turn on/off verbosity
  11. #
  12. TF_VERBOSE=${TF_VERBOSE:-true}
  13. #
  14. # Option to turn on/off debug mode
  15. #
  16. TF_DEBUG=${TF_DEBUG:-false}
  17. #
  18. # Regex to filter test names to run
  19. #
  20. TF_FILTER_TEST="${TF_FILTER_TEST:-.*}"
  21. #
  22. # Regex to filter subtest names to run
  23. #
  24. TF_FILTER_SUBTEST="${TF_FILTER_SUBTEST:-.*}"
  25. #
  26. # Enable color?
  27. #
  28. TF_COLOR=${TF_COLOR:-true}
  29. #
  30. # Color definition variables
  31. #
  32. TF_COLOR_BLACK="\033[0;30m"
  33. TF_COLOR_RED="\033[0;31m"
  34. TF_COLOR_GREEN="\033[0;32m"
  35. TF_COLOR_YELLOW="\033[0;33m"
  36. TF_COLOR_BLUE="\033[0;34m"
  37. TF_COLOR_MAGENTA="\033[0;35m"
  38. TF_COLOR_CYAN="\033[0;36m"
  39. TF_COLOR_WHITE="\033[0;37m"
  40. TF_COLOR_LBLACK="\033[1;30m"
  41. TF_COLOR_LRED="\033[1;31m"
  42. TF_COLOR_LGREEN="\033[1;32m"
  43. TF_COLOR_LYELLOW="\033[1;33m"
  44. TF_COLOR_LBLUE="\033[1;34m"
  45. TF_COLOR_LMAGENTA="\033[1;35m"
  46. TF_COLOR_LCYAN="\033[1;36m"
  47. TF_COLOR_LWHITE="\033[1;37m"
  48. TF_COLOR_NONE="\033[1;0m"
  49. tf_exit_ok() {
  50. #
  51. # Exit with OK status
  52. #
  53. exit $TF_ES_OK
  54. }
  55. tf_exit_fail() {
  56. #
  57. # Warn $1 and exit with status FAIL
  58. #
  59. tf_warn "$@"
  60. exit $TF_ES_FAIL
  61. }
  62. tf_exit_bailout() {
  63. #
  64. # Warn $1 and exit with status FAIL
  65. #
  66. tf_warn "$@"
  67. exit $TF_ES_BAILOUT
  68. }
  69. tf_exit_error() {
  70. #
  71. # Warn $1 and exit with status FAIL
  72. #
  73. tf_warn "$@"
  74. exit $TF_ES_ERROR
  75. }
  76. tf_exit_panic() {
  77. #
  78. # Warn $1 and exit with status FAIL
  79. #
  80. tf_warn "$@"
  81. exit $TF_ES_PANIC
  82. }
  83. tf_debug() {
  84. #
  85. # Emit debug message
  86. #
  87. $TF_DEBUG || return 0
  88. local msg
  89. for msg in "$@";
  90. do
  91. $TF_COLOR && echo -ne "$TF_COLOR_CYAN" >&2
  92. echo "||| $msg" >&2;
  93. $TF_COLOR && echo -ne "$TF_COLOR_NONE" >&2
  94. done
  95. }
  96. tf_think() {
  97. #
  98. # Emit status/progress message
  99. #
  100. $TF_VERBOSE || return 0
  101. local msg
  102. for msg in "$@";
  103. do
  104. $TF_COLOR && echo -ne "$TF_COLOR_LBLACK" >&2
  105. echo "$pfx$msg$sfx" >&2;
  106. $TF_COLOR && echo -ne "$TF_COLOR_NONE" >&2
  107. done
  108. }
  109. tf_warn() {
  110. #
  111. # Emit warning
  112. #
  113. local msg
  114. for msg in "$@";
  115. do
  116. $TF_COLOR && echo -ne "$TF_COLOR_LRED" >&2
  117. echo "$msg" >&2;
  118. $TF_COLOR && echo -ne "$TF_COLOR_NONE" >&2
  119. done
  120. }