tests: Let 'ltorder.sh' run successfully with Guix dynamic loader
[automake.git] / t / java-compile-run-nested.sh
blob4e93e02029fb385bae8bd7f52f05e30eed967a93
1 #! /bin/sh
2 # Copyright (C) 2011-2018 Free Software Foundation, Inc.
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.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Test on compilation and execution of Java class files.
18 # Also meddle with wrapper scripts, as would be probably seen in a real
19 # "UNIX-style" use case.
20 # This test uses a typical "nested" source tree setup (i.e., different
21 # components/aspects are separated into different subdirectories), and
22 # uses the parallel testsuite driver.
23 # The sister test 'java-compile-run-flat.sh' do similar checks with
24 # a "flat" setup (i.e., everything in the top-level directory), and
25 # forcing the use of the older 'serial-tests' driver.
27 required='java javac'
28 . test-init.sh
30 echo "AC_SUBST([PATH_SEPARATOR], ['$PATH_SEPARATOR'])" >> configure.ac
32 cat >> configure.ac <<'END'
33 AC_SUBST([JAVA], [java])
34 AC_CONFIG_SRCDIR([jprog/PkgLocation.jin])
35 AC_SUBST([jprogdatadir], ['${pkgdatadir}'])
36 AC_SUBST([jprogclassdir], ['${jprogdatadir}/jprog'])
37 AC_CONFIG_FILES([jprog/PkgLocation.java:jprog/PkgLocation.jin])
38 AC_CONFIG_FILES([jprog/Makefile bin/Makefile tests/Makefile])
39 AC_OUTPUT
40 END
42 ## TOP-LEVEL SETUP AND TARGETS ##
44 cat > Makefile.am <<'END'
45 SUBDIRS = bin jprog tests
47 test-built:
48 ls -l $(srcdir)/* ;: For debugging.
49 test $(srcdir) = . || ls -l * ;: Likewise.
50 test -f $(srcdir)/jprog/Main.java
51 test -f $(srcdir)/jprog/HelloStream.java
52 test -f $(srcdir)/jprog/PkgLocation.jin
53 test -f jprog/PkgLocation.java
54 test -f jprog/HelloStream.class
55 test -f jprog/Main.class
56 test -f jprog/PkgLocation.class
57 test -f jprog/classjprogclass.stamp
59 test-installed:
60 ls -l $(jprogclassdir) ;: For debugging.
61 test -f $(jprogclassdir)/HelloStream.class
62 test -f $(jprogclassdir)/Main.class
63 test -f $(jprogclassdir)/PkgLocation.class
64 if find $(prefix) | grep '\.stamp$$'; then exit 1; else :; fi
66 run-installed:
67 jprog_doing_installcheck=yes $(MAKE) $(AM_MAKEFLAGS) check
69 check-local: test-built
70 installcheck-local: test-installed run-installed
72 .PHONY: test-built test-installed run-installed
73 END
75 ## WRAPPER SCRIPT ##
77 mkdir bin
79 cat > bin/Makefile.am <<'END'
80 bin_SCRIPTS = jprog
82 edit_script = sed -e 's|[@]JAVA@|$(JAVA)|g' \
83 -e 's|[@]jprogdatadir@|$(jprogdatadir)|g' \
84 -e 's|[@]SHELL@|$(SHELL)|g' \
85 -e 's|[@]PATH_SEPARATOR@|$(PATH_SEPARATOR)|g'
87 jprog: jprog.sh
88 rm -f $@ $@-t
89 $(edit_script) `test -f '$@.sh' || echo $(srcdir)/`$@.sh >$@-t
90 chmod a-w $@-t && chmod a+x $@-t && mv -f $@-t $@
91 sed 's/^/ | /' $@ ;: for debugging.
93 EXTRA_DIST = jprog.sh
94 CLEANFILES = jprog
95 END
97 cat > bin/jprog.sh <<'END'
98 #!@SHELL@
99 CLASSPATH=${jprog_classpath-'@jprogdatadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
100 export CLASSPATH
101 case $# in
102 0) exec @JAVA@ jprog.Main;;
103 *) exec @JAVA@ jprog.Main "$@";;
104 esac
107 ## JAVA SOURCES ##
109 mkdir jprog
111 cat > jprog/Makefile.am <<'END'
112 dist_jprogclass_JAVA = Main.java HelloStream.java
113 nodist_jprogclass_JAVA = PkgLocation.java
116 cat > jprog/PkgLocation.jin <<'END'
117 package jprog;
118 public class PkgLocation {
119 public static String prefix() {
120 return new String("@prefix@");
125 cat > jprog/Main.java <<'END'
126 package jprog;
127 import jprog.PkgLocation;
128 import jprog.HelloStream;
129 public class Main {
130 public static void main(String[] args) {
131 for (int i = 0; i < args.length; i++) {
132 if (args[i].equals("--print-prefix")) {
133 System.out.println(PkgLocation.prefix());
134 } else if (args[i].equals("--hello-stdout")) {
135 HelloStream.to(System.out);
136 } else if (args[i].equals("--hello-stderr")) {
137 HelloStream.to(System.err);
138 } else {
139 System.err.println("jprog: invalid option '" + args[i] +
140 "'");
141 System.exit(2);
144 System.exit(0);
149 cat > jprog/HelloStream.java <<'END'
150 package jprog;
151 import java.io.PrintStream;
152 class HelloStream {
153 public static void to(PrintStream stream) {
154 stream.println("Hello, Stream!");
159 ## TESTS ##
161 mkdir tests
163 cat > tests/Makefile.am <<'END'
164 AM_TESTS_ENVIRONMENT = \
165 if test x"$$jprog_doing_installcheck" != x"yes"; then \
166 jprog_classpath='$(abs_top_builddir):$(abs_top_srcdir)'; \
167 export jprog_classpath; \
168 PATH='$(abs_top_builddir)/bin$(PATH_SEPARATOR)'$$PATH; \
169 export PATH; \
170 else \
171 unset jprog_classpath || :; \
172 PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
173 export PATH; \
174 fi; \
175 config_time_prefix='@prefix@'; export config_time_prefix;
177 TESTS = \
178 simple.test \
179 prefix.test \
180 stdout.test \
181 stderr.test \
182 badarg.test
184 XFAIL_TESTS = badarg.test
186 EXTRA_DIST = $(TESTS)
189 cat > tests/simple.test <<'END'
190 #!/bin/sh
191 jprog
194 cat > tests/prefix.test <<'END'
195 #!/bin/sh
196 jprefix=`jprog --print-prefix` || exit 1
197 echo "$0: exp prefix: $config_time_prefix"
198 echo "$0: got prefix: $jprefix"
199 test x"$jprefix" = x"$config_time_prefix"
202 cat > tests/stdout.test <<'END'
203 #!/bin/sh
204 rc=0
205 jprog --hello-stdout >stdout.out 2>stdout.err || { echo \$?=$?; rc=1; }
206 sed 's/^/out:/' <stdout.out # For debugging.
207 sed 's/^/err:/' <stdout.err >&2 # Likewise.
208 test -s stdout.err && rc=1
209 test "`cat stdout.out`" = 'Hello, Stream!' || rc=1
210 rm -f stdout.out stdout.err || rc=1
211 exit $rc
214 cat > tests/stderr.test <<'END'
215 #!/bin/sh
216 rc=0
217 jprog --hello-stderr >stderr.out 2>stderr.err || { echo \$?=$?; rc=1; }
218 sed 's/^/out:/' <stderr.out # For debugging.
219 sed 's/^/err:/' <stderr.err >&2 # Likewise.
220 test -s stderr.out && rc=1
221 test "`cat stderr.err`" = 'Hello, Stream!' || rc=1
222 rm -f stderr.out stderr.err || rc=1
223 exit $rc
226 cat > tests/badarg.test <<'END'
227 #!/bin/sh
228 jprog --bad-argument
231 chmod a+x tests/*.test
233 ## DO CHECKS ##
235 $ACLOCAL
236 $AUTOCONF
237 $AUTOMAKE -a
239 # To have the parallel testsuite more verbose.
240 VERBOSE=yes; export VERBOSE
242 ./configure --prefix="$(pwd)/_inst"
243 cat jprog/PkgLocation.java # For debugging.
244 $MAKE check
245 $MAKE install
246 $MAKE test-installed
247 $MAKE run-installed
248 $MAKE distcheck