Working Saturnin-based meta-command

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