tests: prefer "test ! -e FILE" to check that a file doesn't exist
[platform/upstream/automake.git] / t / cscope.tap
1 #! /bin/sh
2 # Copyright (C) 2009-2012 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 . ./defs || exit 1
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   $MAKE cscope 2>stderr || r='not ok'
109   cat stderr >&2
110   grep 'cannot find file' stderr && r='not ok'
111   rm -f stderr
112   result_ "$r" "[$pfx] make cscope"
113
114   r=ok
115   test -f cscope.files \
116     && $FGREP foo.c cscope.files \
117     && $FGREP bar.cpp cscope.files \
118     && $FGREP sub/subsub/dist.c cscope.files \
119     && $FGREP sub/subsub/gen.c cscope.files \
120     || r='not ok'
121   result_ "$r" "[$pfx] cscope.files looks correct"
122
123   r=ok
124   # cscope.files might not exist of the earlier "make cscope" failed.
125   cp cscope.files cscope.files1 \
126     && $MAKE cscope \
127     && diff cscope.files cscope.files1 \
128     || r='not ok'
129   rm -f cscope.files1
130   result_ "$r" "[$pfx] second \"make cscope\" is consistent"
131 }
132
133 my_configure ()
134 {
135   command_ok_ "[$pfx] configure" \
136               "$1"/configure EMACS=no --with-lispdir=/who/cares
137 }
138
139 if using_gmake; then
140
141   cd "$ocwd"
142   pfx="relative VPATH"
143   mkdir build
144   cd build
145   my_configure ..
146   test_cscope
147   test_cleanup
148
149   cd "$ocwd"
150   pfx="absolute VPATH"
151   mkdir build2
152   cd build2
153   my_configure "$ocwd"
154   test_cscope
155   test_cleanup
156
157 else
158
159   skip_row_ 12 -r "cscope in VPATH required GNU make"
160
161 fi
162
163 cd "$ocwd"
164 pfx="in-tree build"
165 my_configure .
166 test_cscope
167 test_cleanup
168
169 :