self-check-is_newest.tap 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Sanity check for the automake testsuite: the 'is_newest' subroutine.
  17. . test-init.sh
  18. plan_ 21
  19. # I'm a lazy typist.
  20. Y () { command_ok_ "is_newest $*" is_newest "$@"; }
  21. N () { command_ok_ "not is_newest $*" not is_newest "$@"; }
  22. # A simple "touch -r" might not work, since on some file systems, and/or
  23. # with some 'touch' versions, it might truncate the timestamp (or even
  24. # rounded it upwards maybe). So the first (apparently redundant) 'touch'
  25. # invocation below ensures that the timestamp gets "normalized" in a way
  26. # that allows it to be correctly copied by the second 'touch' invocation.
  27. copy_timestamp ()
  28. {
  29. touch -r "$1" "$1" && touch -r "$1" "$2"
  30. }
  31. : > a
  32. $sleep
  33. : > b
  34. : > c
  35. stat a b c || : # For debugging.
  36. Y c a
  37. Y b a
  38. N a b
  39. Y c b
  40. Y c c
  41. Y c a b c
  42. copy_timestamp c d
  43. stat c d || : # For debugging.
  44. Y c d
  45. # Should work on directories too, both empty and not-empty. An older
  46. # implementation of 'is_newest' failed if the first argument was a
  47. # directory containing files newer than itself (see automake bug#9147).
  48. mkdir u x
  49. touch x/foo
  50. $sleep
  51. touch x/foo
  52. $sleep
  53. mkdir v y
  54. touch y/foo
  55. $sleep
  56. touch y/foo
  57. stat u v x y x/foo y/foo || : # For debugging.
  58. for older in u x; do
  59. for newer in v y; do
  60. Y $newer $older
  61. N $older $newer
  62. done
  63. done
  64. Y x/foo x
  65. N x x/foo
  66. copy_timestamp x u
  67. Y x u
  68. Y u x
  69. # A couple of mild "stress" tests.
  70. Y y x u v
  71. Y y u x/foo a b c
  72. :