doc: update Vala documentation
[automake.git] / t / java-compile-run-nested.sh
blobe1ded7da1913199718d9b152cae641bd3d208741
1 #! /bin/sh
2 # Copyright (C) 2011-2024 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
74 # The test can fail under a parallel make, so disable.
75 # No evident way to debug or reliably reproduce.
76 .NOTPARALLEL:
77 END
79 ## WRAPPER SCRIPT ##
81 mkdir bin
83 cat > bin/Makefile.am <<'END'
84 bin_SCRIPTS = jprog
86 edit_script = sed -e 's|[@]JAVA@|$(JAVA)|g' \
87 -e 's|[@]jprogdatadir@|$(jprogdatadir)|g' \
88 -e 's|[@]SHELL@|$(SHELL)|g' \
89 -e 's|[@]PATH_SEPARATOR@|$(PATH_SEPARATOR)|g'
91 jprog: jprog.sh
92 rm -f $@ $@-t
93 $(edit_script) `test -f '$@.sh' || echo $(srcdir)/`$@.sh >$@-t
94 chmod a-w $@-t && chmod a+x $@-t && mv -f $@-t $@
95 sed 's/^/ | /' $@ ;: for debugging.
97 EXTRA_DIST = jprog.sh
98 CLEANFILES = jprog
100 # The test can fail under a parallel make, so disable.
101 # No evident way to debug or reliably reproduce.
102 .NOTPARALLEL:
105 cat > bin/jprog.sh <<'END'
106 #!@SHELL@
107 CLASSPATH=${jprog_classpath-'@jprogdatadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
108 export CLASSPATH
109 case $# in
110 0) exec @JAVA@ jprog.Main;;
111 *) exec @JAVA@ jprog.Main "$@";;
112 esac
115 ## JAVA SOURCES ##
117 mkdir jprog
119 cat > jprog/Makefile.am <<'END'
120 dist_jprogclass_JAVA = Main.java HelloStream.java
121 nodist_jprogclass_JAVA = PkgLocation.java
123 # Tell GNU make not to parallelize, since the tests can result in, for example:
124 # /p/bin/install: cannot create regular file '/w/co/automake/t/java-compile-run-nested.dir/_inst/share/java-compile-run-nested/jprog/HelloStream.class':
125 # File exists
126 # No evident way to debug or reliably reproduce.
127 .NOTPARALLEL:
130 cat > jprog/PkgLocation.jin <<'END'
131 package jprog;
132 public class PkgLocation {
133 public static String prefix() {
134 return new String("@prefix@");
139 cat > jprog/Main.java <<'END'
140 package jprog;
141 import jprog.PkgLocation;
142 import jprog.HelloStream;
143 public class Main {
144 public static void main(String[] args) {
145 for (int i = 0; i < args.length; i++) {
146 if (args[i].equals("--print-prefix")) {
147 System.out.println(PkgLocation.prefix());
148 } else if (args[i].equals("--hello-stdout")) {
149 HelloStream.to(System.out);
150 } else if (args[i].equals("--hello-stderr")) {
151 HelloStream.to(System.err);
152 } else {
153 System.err.println("jprog: invalid option '" + args[i] +
154 "'");
155 System.exit(2);
158 System.exit(0);
163 cat > jprog/HelloStream.java <<'END'
164 package jprog;
165 import java.io.PrintStream;
166 class HelloStream {
167 public static void to(PrintStream stream) {
168 stream.println("Hello, Stream!");
173 ## TESTS ##
175 mkdir tests
177 cat > tests/Makefile.am <<'END'
178 AM_TESTS_ENVIRONMENT = \
179 if test x"$$jprog_doing_installcheck" != x"yes"; then \
180 jprog_classpath='$(abs_top_builddir):$(abs_top_srcdir)'; \
181 export jprog_classpath; \
182 PATH='$(abs_top_builddir)/bin$(PATH_SEPARATOR)'$$PATH; \
183 export PATH; \
184 else \
185 unset jprog_classpath || :; \
186 PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
187 export PATH; \
188 fi; \
189 config_time_prefix='@prefix@'; export config_time_prefix;
191 TESTS = \
192 simple.test \
193 prefix.test \
194 stdout.test \
195 stderr.test \
196 badarg.test
198 XFAIL_TESTS = badarg.test
200 EXTRA_DIST = $(TESTS)
202 # The test can fail under a parallel make, so disable.
203 # No evident way to debug or reliably reproduce.
204 .NOTPARALLEL:
207 cat > tests/simple.test <<'END'
208 #!/bin/sh
209 jprog
212 cat > tests/prefix.test <<'END'
213 #!/bin/sh
214 jprefix=`jprog --print-prefix` || exit 1
215 echo "$0: exp prefix: $config_time_prefix"
216 echo "$0: got prefix: $jprefix"
217 test x"$jprefix" = x"$config_time_prefix"
220 cat > tests/stdout.test <<'END'
221 #!/bin/sh
222 rc=0
223 jprog --hello-stdout >stdout.out 2>stdout.err || { echo \$?=$?; rc=1; }
224 sed 's/^/out:/' <stdout.out # For debugging.
225 sed 's/^/err:/' <stdout.err >&2 # Likewise.
226 test -s stdout.err && rc=1
227 test "`cat stdout.out`" = 'Hello, Stream!' || rc=1
228 rm -f stdout.out stdout.err || rc=1
229 exit $rc
232 cat > tests/stderr.test <<'END'
233 #!/bin/sh
234 rc=0
235 jprog --hello-stderr >stderr.out 2>stderr.err || { echo \$?=$?; rc=1; }
236 sed 's/^/out:/' <stderr.out # For debugging.
237 sed 's/^/err:/' <stderr.err >&2 # Likewise.
238 test -s stderr.out && rc=1
239 test "`cat stderr.err`" = 'Hello, Stream!' || rc=1
240 rm -f stderr.out stderr.err || rc=1
241 exit $rc
244 cat > tests/badarg.test <<'END'
245 #!/bin/sh
246 jprog --bad-argument
249 chmod a+x tests/*.test
251 ## DO CHECKS ##
253 $ACLOCAL
254 $AUTOCONF
255 $AUTOMAKE -a
257 # To have the parallel testsuite more verbose.
258 VERBOSE=yes; export VERBOSE
260 ./configure --prefix="$(pwd)/_inst"
261 cat jprog/PkgLocation.java # For debugging.
262 $MAKE check
263 $MAKE install
264 $MAKE test-installed
265 $MAKE run-installed
266 $MAKE distcheck