test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / aclocal-path-install-serial.sh
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 # ACLOCAL_PATH, acdir and '--install' interactions when serial number
18 # are involved.
19
20 am_create_testdir=empty
21 . test-init.sh
22
23 cat > configure.ac << 'END'
24 AC_INIT
25 AM_FOO
26 END
27
28 set_serial ()
29 {
30   serial=$1 file=$2
31   sed '/^# serial/d' $file > t
32   case $serial in
33     none) mv -f t $file;;
34        *) (echo "# serial $serial" && cat t) > $file; rm -f t;;
35   esac
36   cat $file # For debugging.
37 }
38
39 win ()
40 {
41   case $1 in
42     sdir) ok=sdir ko=pdir;;
43     pdir) ok=pdir ko=sdir;;
44        *) fatal_ "win(): invalid argument '$1'";;
45   esac
46   # This is required on fast machine, to avoid caching and timestamp
47   # issues with the autotools (already happened in practice).
48   rm -rf configure aclocal.m4 autom4te*.cache m4/*
49   $ACLOCAL -I m4 --install
50   test -f m4/foo.m4 # Sanity check.
51   $AUTOCONF
52   $FGREP "::$ok:"  m4/foo.m4
53   $FGREP "::$ok::" configure
54   $FGREP "::$ko::" m4/foo.m4 configure && exit 1
55   :
56 }
57
58 mkdir sdir pdir m4
59
60 ACLOCAL="$ACLOCAL --system-acdir=$(pwd)/sdir"
61 ACLOCAL_PATH=./pdir; export ACLOCAL_PATH
62
63 cat > sdir/foo.m4 << 'END'
64 AC_DEFUN([AM_FOO], [::sdir::])
65 END
66 cat > pdir/foo.m4 << 'END'
67 AC_DEFUN([AM_FOO], [::pdir::])
68 END
69
70 set_serial 2 sdir/foo.m4
71 set_serial 1 pdir/foo.m4
72 win sdir
73
74 set_serial 3.3 sdir/foo.m4
75 set_serial 5.7 pdir/foo.m4
76 win pdir
77
78 set_serial 0    sdir/foo.m4
79 set_serial none pdir/foo.m4
80 win sdir
81
82 set_serial none  sdir/foo.m4
83 set_serial 1.2.3 pdir/foo.m4
84 win pdir
85
86 :