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)
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.
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])
42 ## TOP-LEVEL SETUP AND TARGETS ##
44 cat > Makefile.am
<<'END'
45 SUBDIRS = bin jprog tests
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
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
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.
83 cat > bin
/Makefile.am
<<'END'
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'
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.
100 # The test can fail under a parallel make, so disable.
101 # No evident way to debug or reliably reproduce.
105 cat > bin
/jprog.sh
<<'END'
107 CLASSPATH=${jprog_classpath-'@jprogdatadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
110 0) exec @JAVA@ jprog.Main;;
111 *) exec @JAVA@ jprog.Main "$@";;
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':
126 # No evident way to debug or reliably reproduce.
130 cat > jprog
/PkgLocation.jin
<<'END'
132 public class PkgLocation {
133 public static String prefix() {
134 return new String("@prefix@");
139 cat > jprog
/Main.java
<<'END'
141 import jprog.PkgLocation;
142 import jprog.HelloStream;
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);
153 System.err.println("jprog: invalid option '" + args[i] +
163 cat > jprog
/HelloStream.java
<<'END'
165 import java.io.PrintStream;
167 public static void to(PrintStream stream) {
168 stream.println("Hello, Stream!");
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; \
185 unset jprog_classpath || :; \
186 PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
189 config_time_prefix='@prefix@'; export config_time_prefix;
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.
207 cat > tests
/simple.
test <<'END'
212 cat > tests
/prefix.
test <<'END'
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'
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
232 cat > tests
/stderr.
test <<'END'
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
244 cat > tests
/badarg.
test <<'END'
249 chmod a
+x
tests
/*.
test
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.