tests: prefer including 'test-init.sh' rather than './defs'
[platform/upstream/automake.git] / t / vala-vapi.sh
1 #! /bin/sh
2 # Copyright (C) 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 and that vapi files are correctly handled by Vala support.
18
19 required='valac cc GNUmake'
20 . test-init.sh
21
22 cat >> configure.ac <<'END'
23 AC_PROG_CC
24 AM_PROG_CC_C_O
25 AM_PROG_VALAC([0.7.3])
26 AC_OUTPUT
27 END
28
29 cat > Makefile.am <<'END'
30 bin_PROGRAMS = zardoz
31 AM_VALAFLAGS = --profile=posix
32 zardoz_SOURCES = zardoz.vala foo.vapi foo.h
33 END
34
35 cat > zardoz.vala <<'END'
36 int main ()
37 {
38     stdout.printf (BARBAR);
39     return 0;
40 }
41 END
42
43 # Use printf, not echo, to avoid '\n' being considered and escape
44 # sequence and printed as a newline in 'foo.h'.
45 printf '%s\n' '#define BARBAR "Zardoz!\n"' > foo.h
46
47 cat > foo.vapi <<'END'
48 [CCode (cprefix="", lower_case_cprefix="", cheader_filename="foo.h")]
49 public const string BARBAR;
50 END
51
52 if ! cross_compiling; then
53   unindent >> Makefile.am <<'END'
54     check-local: test2
55     .PHONY: test1 test2
56     test1:
57         ./zardoz
58         ./zardoz | grep 'Zardoz!'
59     test2:
60         ./zardoz
61         ./zardoz | grep 'Quux!'
62 END
63 fi
64
65 $ACLOCAL
66 $AUTOMAKE -a
67 $AUTOCONF
68
69 ./configure --enable-dependency-tracking
70
71 $MAKE
72 ls -l        # For debugging.
73 cat zardoz.c # Likewise.
74 grep 'BARBAR' zardoz.c
75 cross_compiling || $MAKE test1 || exit 1
76
77 # Simple check on remake rules.
78 $sleep
79 # Use printf, not echo, to avoid '\n' being considered and escape
80 # sequence and printed as a newline in 'foo.h'.
81 printf '%s\n' '#define BAZBAZ "Quux!\n"' > foo.h
82 sed 's/BARBAR/BAZBAZ/' zardoz.vala > t && mv -f t zardoz.vala || exit 99
83 $MAKE && exit 1
84 sed 's/BARBAR/BAZBAZ/' foo.vapi > t && mv -f t foo.vapi || exit 99
85 $MAKE
86 cat zardoz.c # For debugging.
87 grep 'BAZBAZ' zardoz.c
88 cross_compiling || $MAKE test2 || exit 1
89
90 # Check the distribution.
91 $MAKE distcheck
92
93 :