1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # tfkit - Shellfu's movable test framework
  3. # See LICENSE file for copyright and license details.
  4. TF_VERSION="0.0.16"
  5. die() {
  6. echo "$@" && exit 9
  7. }
  8. usage() {
  9. echo "usage: $(basename "$0") [-c|-C] [-t tests_re] [-s subtest_re] [-p binpath] [-v] [-d]" >&2
  10. exit 2
  11. }
  12. version() {
  13. echo "TFKit (A trivial test kit) $TF_VERSION"
  14. exit 0
  15. }
  16. #
  17. # Relic directory path
  18. #
  19. TF_RELICS="${TF_RELICS:-relics}"
  20. #
  21. # Relic collection mode
  22. #
  23. # 'always' to always collect, 'never` to never collect and 'auto'
  24. # to collect only on failed tests.
  25. #
  26. TF_COLLECT="${TF_COLLECT:-auto}"
  27. #
  28. # Enable color?
  29. #
  30. TF_COLOR=${TF_COLOR:-true}
  31. #
  32. # Turn on debug mode?
  33. #
  34. TF_DEBUG="${TF_DEBUG:-false}"
  35. #
  36. # Location of own directory
  37. #
  38. TF_DIR=${TF_DIR:-$(dirname "$0")}
  39. #
  40. # Regex (BRE) to filter subtests based on name
  41. #
  42. TF_FILTER_SUBTEST=${TF_FILTER_SUBTEST:-}
  43. #
  44. # Regex (BRE) to filter tests based on name
  45. #
  46. TF_FILTER_TEST=${TF_FILTER_TEST:-}
  47. #
  48. # Location of test suite
  49. #
  50. TF_SUITE="${TF_SUITE:-tests}"
  51. #
  52. # Turn on verbosity?
  53. #
  54. TF_VERBOSE=${TF_VERBOSE:-true}
  55. . "$TF_DIR/include/harness.sh" \
  56. || die "cannot import harness; is TF_DIR set properly?: $TF_DIR"
  57. main() {
  58. while true; do case "$1" in
  59. -c|--collect) TF_COLLECT=always; shift ;;
  60. -C|--no-collect) TF_COLLECT=never; shift ;;
  61. -d|--debug) TF_DEBUG=true; shift ;;
  62. -p|--prefix) export PATH="$(readlink -f "$2")/bin:$PATH"
  63. shift 2 || usage ;;
  64. -s|--filter-subtest) TF_FILTER_SUBTEST="$2"; shift 2 || usage ;;
  65. -t|--filter-test) TF_FILTER_TEST="$2"; shift 2 || usage ;;
  66. -v|--verbose) TF_VERBOSE=true; shift ;;
  67. --version-semver) echo "$TF_VERSION"; exit 0 ;;
  68. --version) version ;;
  69. "") break ;;
  70. *) usage ;;
  71. esac done
  72. export LC_ALL=C
  73. time tf_run_tests
  74. }
  75. main "$@"