tests: slightly stricter checks in t/cxx-demo.sh
[platform/upstream/automake.git] / t / python-vars.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 # Check that AM_PATH_PYTHON correctly sets all the output variables
18 # advertised in the manual.
19
20 required=python
21 . test-init.sh
22
23 # In case the user's config.site defines pythondir or pyexecdir.
24 CONFIG_SITE=/dev/null; export CONFIG_SITE
25
26 # Update the definition below if the documentation changes.
27 # Note that the value of the 'pythondir' and 'pyexecdir' variables can
28 # vary among different python installations, so we need more relaxed
29 # and ad-hoc checks for them.  Also, more proper "functional" checks
30 # on them should be done in the 'python-virtualenv.sh' test.
31 PYTHON_VERSION=$($PYTHON -c 'import sys; print(sys.version[:3])') || exit 1
32 PYTHON_PLATFORM=$($PYTHON -c 'import sys; print(sys.platform)') || exit 1
33 PYTHON_EXEC_PREFIX='${exec_prefix}'
34 PYTHON_PREFIX='${prefix}'
35 pkgpythondir="\${pythondir}/$me"
36 pkgpyexecdir="\${pyexecdir}/$me"
37
38 pyvars='PYTHON_VERSION PYTHON_PLATFORM PYTHON_PREFIX PYTHON_EXEC_PREFIX
39         pkgpythondir pkgpyexecdir'
40
41 cat >> configure.ac << 'END'
42 AC_CONFIG_FILES([vars-got pythondir pyexecdir])
43 AM_PATH_PYTHON
44 AC_OUTPUT
45 END
46
47 cat > my.py << 'END'
48 def my():
49     return 1
50 END
51
52 cat > Makefile.am << 'END'
53
54 python_PYTHON = my.py
55
56 EXTRA_DIST = vars-exp
57
58 check-local: test-in test-am
59 .PHONY: test-in test-am
60
61 test-in:
62         cat pythondir
63         case `cat pythondir` in '$${prefix}'/*);; *) exit 1;; esac
64         cat pyexecdir
65         case `cat pyexecdir` in '$${exec_prefix}'/*);; *) exit 1;; esac
66         cat $(srcdir)/vars-exp
67         cat $(builddir)/vars-got
68         diff $(srcdir)/vars-exp $(builddir)/vars-got
69
70 ## Note: this target's rules will be extended in the "for" loop below.
71 test-am:
72         case '$(pythondir)' in '$(prefix)'/*);; *) exit 1;; esac
73         case '$(pyexecdir)' in '$(exec_prefix)'/*);; *) exit 1;; esac
74 END
75
76 echo @pythondir@ > pythondir.in
77 echo @pyexecdir@ > pyexecdir.in
78
79 : > vars-exp
80 : > vars-got.in
81
82 for var in $pyvars; do
83   eval val=\$$var
84   echo "var=$val" >> vars-exp
85   echo "var=@$var@" >> vars-got.in
86   echo "${tab}test x'\$($var)' = x'$val'" >> Makefile.am
87 done
88
89 cat Makefile.am
90 cat vars-got.in
91
92 $ACLOCAL
93 $AUTOMAKE --add-missing
94
95 for var in pythondir pyexecdir $pyvars; do
96   grep "^$var *=" Makefile.in
97 done
98
99 $AUTOCONF
100 ./configure PYTHON="$PYTHON"
101
102 $MAKE test-in test-am
103 $MAKE distcheck
104
105 :