logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

touch.sh (2215B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD=$(dirname "$0")
  5. plans=33
  6. target="${WD}/../cmd/touch"
  7. . "${WD}/tap.sh"
  8. tempfile="$(mktemp)"
  9. tempdir="$(mktemp -d)"
  10. t noargs
  11. t file "$tempfile"
  12. t ref_file:setup "-d 2007-11-12T10:15:30Z $tempfile"
  13. t ref_file "-r $target $tempfile"
  14. t_cmd ref_file:atime "$("${WD}/stat_atime" "$target")
  15. " "${WD}/stat_atime" "$tempfile"
  16. t_cmd ref_file:mtime "$("${WD}/stat_mtime" "$target")
  17. " "${WD}/stat_mtime" "$tempfile"
  18. t mtime:setup "-d 2007-11-12T10:15:30Z $tempfile"
  19. atime=$("${WD}/stat_atime" "$tempfile")
  20. t mtime "-m $tempfile"
  21. t_cmd mtime:atime "$atime
  22. " "${WD}/stat_atime" "$tempfile"
  23. t ref_mtime:setup "-d 2007-11-12T10:15:30Z $tempfile"
  24. atime=$("${WD}/stat_atime" "$tempfile")
  25. t ref_mtime "-m -r $target $tempfile"
  26. t_cmd ref_mtime:atime "$atime
  27. " "${WD}/stat_atime" "$tempfile"
  28. t_cmd ref_mtime:mtime "$("${WD}/stat_mtime" "$target")
  29. " "${WD}/stat_mtime" "$tempfile"
  30. t atime:setup "-d 2007-11-12T10:15:30Z $tempfile"
  31. mtime=$("${WD}/stat_mtime" "$tempfile")
  32. t atime "-a $tempfile"
  33. t_cmd atime:mtime "$mtime
  34. " "${WD}/stat_mtime" "$tempfile"
  35. t ref_atime:setup "-d 2007-11-12T10:15:30Z $tempfile"
  36. mtime=$("${WD}/stat_mtime" "$tempfile")
  37. t ref_atime "-a -r $target $tempfile"
  38. t_cmd ref_atime:mtime "$mtime
  39. " "${WD}/stat_mtime" "$tempfile"
  40. t_cmd ref_atime:atime "$("${WD}/stat_atime" "$target")
  41. " "${WD}/stat_atime" "$tempfile"
  42. t amtime "-a -m $tempfile"
  43. t ref_amtime:setup "-d 2007-11-12T10:15:30Z $tempfile"
  44. t ref_amtime "-a -m -r $target $tempfile"
  45. t_cmd ref_amtime:atime "$("${WD}/stat_atime" "$target")
  46. " "${WD}/stat_atime" "$tempfile"
  47. t_cmd ref_amtime:mtime "$("${WD}/stat_mtime" "$target")
  48. " "${WD}/stat_mtime" "$tempfile"
  49. t dir "${tempdir}"
  50. t dir_optd "-d 2003-06-02T13:37:42Z $tempdir"
  51. TZ=UTC t dir_optd_tz:utc "-d 2003-06-02T13:37:42Z $tempdir"
  52. TZ=UTC t dir_optd_tz:0666 "-d 2003-06-02T13:37:42+0666 $tempdir"
  53. t optt "-t 200306021337.42 $tempfile"
  54. touch_empty_str() { "$target" ''; }
  55. t_cmd --exit=1 empty_str "touch: error: Failed opening file '': No such file or directory
  56. " touch_empty_str
  57. t_cmd rm_tempfile '' rm "${tempfile}"
  58. t_cmd rm_tempdir '' rm -r "${tempdir}"