fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.3 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. compose_core=$(which compose-core) || {
  4. echo "Requires compose-core executable to be in \$PATH." >&2
  5. exit 1
  6. }
  7. fetch-def() {
  8. local path="$1" fname="$2"
  9. ( . "$path" 1>&2 || {
  10. echo "Failed to load '$path'." >&2
  11. exit 1
  12. }
  13. declare -f "$fname"
  14. )
  15. }
  16. prefix_cmd="
  17. . /etc/shlib
  18. include common
  19. include parse
  20. . ../lib/common
  21. $(fetch-def "$compose_core" yaml_get_values)
  22. $(fetch-def "$compose_core" yaml_get_interpret)
  23. $(fetch-def "$compose_core" read-0-err)
  24. $(fetch-def "$compose_core" p-err)
  25. " || {
  26. echo "Couldn't build prefix cmd" >&2
  27. exit 1
  28. }
  29. # mock
  30. cfg-get-value() {
  31. local key="$1"
  32. shyaml get-value "$key" 2>/dev/null
  33. }
  34. export -f cfg-get-value
  35. yaml_get_interpret() {
  36. shyaml get-value
  37. }
  38. export -f yaml_get_interpret
  39. export CACHEDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
  40. export state_tmpdir=$(mktemp -d -t tmp.XXXXXXXXXX)
  41. trap "rm -rf \"$state_tmpdir\"" EXIT
  42. trap "rm -rf \"$CACHEDIR\"" EXIT
  43. ##
  44. ## Tests
  45. ##
  46. try "
  47. cron:lock_opts ''"
  48. noerror
  49. is out '' TRIM
  50. try "
  51. cron:lock_opts '--XXX'
  52. "
  53. is errlvl 1
  54. is err reg 'Error: .*argument.*--XXX.*'
  55. is out ''
  56. try "
  57. cron:lock_opts -p X
  58. "
  59. is errlvl 1
  60. is err reg 'Error: .*priority.*X.*integer.*'
  61. is out ''
  62. try "
  63. cron:lock_opts -p 10 -k -D
  64. "
  65. noerror
  66. is out "\
  67. -p
  68. 10
  69. -k
  70. -D" TRIM