Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / lalib-syntax.at
1 # lalib-syntax.at -- parsing .la files robustly  -*- Autotest -*-
2 #
3 #   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4 #
5 #   This file is part of GNU Libtool.
6 #
7 # GNU Libtool is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of
10 # the License, or (at your option) any later version.
11 #
12 # GNU Libtool is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Libtool; see the file COPYING.  If not, a copy
19 # can be downloaded from  http://www.gnu.org/licenses/gpl.html,
20 # or obtained by writing to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 ####
23
24 AT_SETUP([syntax of .la files])
25 AT_KEYWORDS([libtool])
26 AT_KEYWORDS([libltdl])
27
28 AT_XFAIL_IF([:]) dnl libltdl does not consistently return non-NULL lt_dlerror
29
30 AT_DATA([main.c],
31 [[#include <ltdl.h>
32 #include <stdio.h>
33 #include <assert.h>
34
35 int
36 main (int argc, char* argv[])
37 {
38   int err = 0;
39   lt_dlhandle plugin_handle;
40
41   if (argc < 2)
42     {
43       fprintf (stderr, "usage: %s plugin\n", argv[0]);
44       return 1;
45     }
46
47   lt_dlinit ();
48   plugin_handle = lt_dlopenext (argv[1]);
49   if (NULL != plugin_handle)
50     {
51       printf ("plugin opened successfully!\n");
52       lt_dlclose (plugin_handle);
53     }
54   else
55     {
56       const char *error = lt_dlerror ();
57       assert (error != NULL);
58       printf ("plugin failed to open: %s\n", error);
59       err = 1;
60     }
61   lt_dlexit ();
62   return err;
63 }
64 ]])
65
66 AT_DATA([module.c],
67 [[int foo (void) { return 0; }
68 ]])
69
70 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
71 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
72
73 # Skip this test when called from:
74 #    make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
75 AT_CHECK([case $LIBLTDL in #(
76  */_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
77 esac], [], [ignore])
78
79 CPPFLAGS="$CPPFLAGS $LTDLINCL"
80
81 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c main.c], [], [ignore], [ignore])
82 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c module.c],
83          [], [ignore], [ignore])
84 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o module.la module.lo ]dnl
85          [-module -avoid-version -rpath /somewhere], [], [ignore], [ignore])
86 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main main.$OBJEXT $LIBLTDL],
87          [], [ignore], [ignore])
88
89
90 # Several bogus test cases.
91
92 AT_DATA([missing-closing-quote.la],
93 [[# missing-closing-quote.la - a libtool library file
94 # Generated by libtool
95 dlname='module.so
96 library_names='module.so module.so module.so'
97 old_library='module.a'
98 installed=no
99 shouldnotlink=yes
100 libdir='/somewhere'
101 ]])
102
103 AT_DATA([wrong-quotes.la],
104 [[# wrong-quotes.la - a libtool library file
105 # Generated by libtool
106 dlname="module.so"
107 library_names='module.so module.so module.so'
108 old_library='module.a'
109 installed=no
110 shouldnotlink=yes
111 libdir='/somewhere'
112 ]])
113
114 AT_DATA([no-dlname.la],
115 [[# no-dlname.la - a libtool library file
116 # Generated by libtool
117 installed=no
118 shouldnotlink=yes
119 libdir='/somewhere'
120 ]])
121
122 AT_DATA([nonexistent-dlname.la],
123 [[# nonexistent-dlname.la - a libtool library file
124 # Generated by libtool
125 dlname='does-not-exist.so'
126 installed=no
127 shouldnotlink=yes
128 libdir='/somewhere'
129 ]])
130
131 for file in ./missing-closing-quote.la ./wrong-quotes.la \
132             ./no-dlname.la ./nonexistent-dlname.la; do
133   LT_AT_EXEC_CHECK([./main], [1], [stdout], [ignore], [$file])
134   AT_CHECK([grep 'plugin failed to open' stdout], [], [ignore])
135 done
136
137 AT_CLEANUP