tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / self-check-is_newest.tap
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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
17 # Sanity check for the automake testsuite: the 'is_newest' subroutine.
18
19 . test-init.sh
20
21 plan_ 21
22
23 # I'm a lazy typist.
24 Y () { command_ok_ "is_newest $*" is_newest "$@"; }
25 N () { command_ok_ "not is_newest $*" not is_newest "$@"; }
26
27 # A simple "touch -r" might not work, since on some file systems, and/or
28 # with some 'touch' versions, it might truncate the timestamp (or even
29 # rounded it upwards maybe).  So the first (apparently redundant) 'touch'
30 # invocation below ensures that the timestamp gets "normalized" in a way
31 # that allows it to be correctly copied by the second 'touch' invocation.
32 copy_timestamp ()
33 {
34   touch -r "$1" "$1" && touch -r "$1" "$2"
35 }
36
37 : > a
38 $sleep
39 : > b
40 : > c
41
42 stat a b c || : # For debugging.
43
44 Y c a
45 Y b a
46 N a b
47 Y c b
48 Y c c
49 Y c a b c
50
51 copy_timestamp c d
52
53 stat c d || : # For debugging.
54
55 Y c d
56
57 # Should work on directories too, both empty and not-empty.  An older
58 # implementation of 'is_newest' failed if the first argument was a
59 # directory containing files newer than itself (see automake bug#9147).
60 mkdir u x
61 touch x/foo
62 $sleep
63 touch x/foo
64 $sleep
65 mkdir v y
66 touch y/foo
67 $sleep
68 touch y/foo
69
70 stat u v x y x/foo y/foo || : # For debugging.
71
72 for older in u x; do
73   for newer in v y; do
74     Y $newer $older
75     N $older $newer
76   done
77 done
78
79 Y x/foo x
80 N x x/foo
81
82 copy_timestamp x u
83 Y x u
84 Y u x
85
86 # A couple of mild "stress" tests.
87 Y y x u v
88 Y y u x/foo a b c
89
90 :