tests: expose automake bug#14560
[platform/upstream/automake.git] / t / cscope.tap
1 #! /bin/sh
2 # Copyright (C) 2009-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 # Test cscope functionality.
18
19 . test-init.sh
20
21 plan_ 18
22
23 ocwd=$(pwd) || fatal_ "getting top-level directory"
24
25 cat >> configure.ac << 'END'
26 AC_CONFIG_FILES([sub/Makefile])
27 AC_SUBST([CC],  [who-cares])
28 AC_SUBST([CXX], [who-cares])
29 AC_SUBST([FC],  [who-cares])
30 AC_SUBST([GCJ], [who-cares])
31 AM_PATH_LISPDIR
32 AC_OUTPUT
33 END
34
35 mkdir sub sub/subsub
36
37 cat > Makefile.am <<'END'
38 SUBDIRS = sub
39 bin_PROGRAMS = foo
40 foo_SOURCES = foo.c bar.cpp baz.f90
41 lisp_LISP = foo.el
42 EXTRA_DIST = foo.el
43 END
44
45 cat > sub/Makefile.am <<'END'
46 bin_PROGRAMS = bar
47 bar_SOURCES = subsub/dist.c
48 nodist_bar_SOURCES = subsub/gen.c
49 subsub/gen.c:
50         $(MKDIR_P) subsub
51         echo 'int generated_subsub () { return 0; }' > $@
52 CLEANFILES = subsub/gen.c
53 END
54
55 echo 'int foo_func () { return 0; }' > foo.c
56 echo 'int main () { return 0; }' > bar.cpp
57 cat > baz.f90 <<'END'
58       subroutine baz
59       end
60 END
61 : > foo.el
62 echo 'int main () { return 0; }' > sub/subsub/dist.c
63
64 $ACLOCAL || fatal_ "aclocal failed"
65 $AUTOCONF || fatal_ "autoconf failed"
66 $AUTOMAKE -i -a || fatal_ "automake -i -a failed"
67
68 # Sun cscope is interactive without redirection; also, it might not
69 # support the '-q' option, which is required by our generated recipes.
70 if cscope -q --version </dev/null; then
71   have_cscope=yes
72 else
73   have_cscope=no
74 fi
75
76 test_cleanup ()
77 {
78   r=ok
79   if test -f configure; then
80     # In-tree build.
81     $MAKE distclean
82   else
83     # VPATH build.
84     $MAKE distcleancheck
85   fi \
86     && test ! -e cscope.files \
87     && test ! -e cscope.out \
88     && test ! -e cscope.in.out \
89     && test ! -e cscope.po.out \
90     || r='not ok'
91   result_ "$r" "[$pfx] make distcheck"
92 }
93
94 test_cscope ()
95 {
96   r=ok
97   $MAKE -n cscope || r='not ok'
98   result_ "$r" "[$pfx] make -n cscope"
99
100   if test $have_cscope = no; then
101     # For later tests.
102     touch cscope.files cscope.out cscope.in.out cscope.po.out
103     skip_row_ 3 -r "no proper cscope program available"
104     return 0
105   fi
106
107   r=ok
108   run_make -E cscope || r='not ok'
109   grep 'cannot find file' stderr && r='not ok'
110   rm -f stderr
111   result_ "$r" "[$pfx] make cscope"
112
113   r=ok
114   test -f cscope.files \
115     && $FGREP foo.c cscope.files \
116     && $FGREP bar.cpp cscope.files \
117     && $FGREP sub/subsub/dist.c cscope.files \
118     && $FGREP sub/subsub/gen.c cscope.files \
119     || r='not ok'
120   result_ "$r" "[$pfx] cscope.files looks correct"
121
122   r=ok
123   # cscope.files might not exist of the earlier "make cscope" failed.
124   cp cscope.files cscope.files1 \
125     && $MAKE cscope \
126     && diff cscope.files cscope.files1 \
127     || r='not ok'
128   rm -f cscope.files1
129   result_ "$r" "[$pfx] second \"make cscope\" is consistent"
130 }
131
132 my_configure ()
133 {
134   command_ok_ "[$pfx] configure" \
135               "$1"/configure EMACS=no --with-lispdir=/who/cares
136 }
137
138 if using_gmake; then
139
140   cd "$ocwd"
141   pfx="relative VPATH"
142   mkdir build
143   cd build
144   my_configure ..
145   test_cscope
146   test_cleanup
147
148   cd "$ocwd"
149   pfx="absolute VPATH"
150   mkdir build2
151   cd build2
152   my_configure "$ocwd"
153   test_cscope
154   test_cleanup
155
156 else
157
158   skip_row_ 12 -r "cscope in VPATH requires GNU make"
159
160 fi
161
162 cd "$ocwd"
163 pfx="in-tree build"
164 my_configure .
165 test_cscope
166 test_cleanup
167
168 :