2 # Copyright (C) 2011-2012 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 <http://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 "flat" setup for the source tree (i.e., everything in
21 # the top-level directory), and forces the use of the old, non-parallel
22 # testsuite driver. The sister test 'java-compile-run-nested.test' do
23 # similar checks with a more usual, "nested" setup, and using the newer
24 # 'parallel-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([PkgLocation.jin])
35 AC_CONFIG_FILES([PkgLocation.java:PkgLocation.jin])
39 ## TOP-LEVEL SETUP AND TARGETS ##
41 cat > Makefile.am <<'END'
42 EXTRA_DIST = # Will be updated later.
45 ls -l $(srcdir) ;: For debugging.
46 test $(srcdir) = . || ls -l . ;: Likewise.
47 test -f $(srcdir)/Main.java
48 test -f $(srcdir)/HelloStream.java
49 test -f $(srcdir)/PkgLocation.jin
50 test -f PkgLocation.java
51 test -f HelloStream.class
52 test -f PkgLocation.class
54 test -f classjava.stamp
57 ls -l $(javadir) ;: For debugging.
58 test -f $(javadir)/HelloStream.class
59 test -f $(javadir)/PkgLocation.class
60 test -f $(javadir)/Main.class
61 if find $(prefix) | grep '\.stamp$$'; then exit 1; else :; fi
64 jprog_doing_installcheck=yes $(MAKE) $(AM_MAKEFLAGS) check
66 check-local: test-built
67 installcheck-local: test-installed run-installed
69 .PHONY: test-built test-installed run-installed
74 cat >> Makefile.am <<'END'
77 edit_script = sed -e 's|[@]JAVA@|$(JAVA)|g' \
78 -e 's|[@]javadir@|$(javadir)|g' \
79 -e 's|[@]SHELL@|$(SHELL)|g' \
80 -e 's|[@]PATH_SEPARATOR@|$(PATH_SEPARATOR)|g'
84 $(edit_script) `test -f '$@.sh' || echo $(srcdir)/`$@.sh >$@-t
85 chmod a-w $@-t && chmod a+x $@-t && mv -f $@-t $@
86 sed 's/^/ | /' $@ ;: for debugging.
88 EXTRA_DIST += jprog.sh
92 cat > jprog.sh <<'END'
94 CLASSPATH=${jprog_classpath-'@javadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
98 *) exec @JAVA@ Main "$@";;
104 cat >> Makefile.am <<'END'
105 javadir = $(pkgdatadir)/java
107 dist_java_JAVA = Main.java HelloStream.java
108 nodist_java_JAVA = PkgLocation.java
111 cat > PkgLocation.jin <<'END'
112 public class PkgLocation {
113 public static String prefix() {
114 return new String("@prefix@");
119 cat > Main.java <<'END'
121 public static void main(String[] args) {
122 for (int i = 0; i < args.length; i++) {
123 if (args[i].equals("--print-prefix")) {
124 System.out.println(PkgLocation.prefix());
125 } else if (args[i].equals("--hello-stdout")) {
126 HelloStream.to(System.out);
127 } else if (args[i].equals("--hello-stderr")) {
128 HelloStream.to(System.err);
130 System.err.println("jprog: invalid option '" + args[i] +
140 cat > HelloStream.java <<'END'
141 import java.io.PrintStream;
143 public static void to(PrintStream stream) {
144 stream.println("Hello, Stream!");
151 cat >> Makefile.am <<'END'
152 ## We must use 'TESTS_ENVIRONMENT', not 'AM_TESTS_ENVIRONMENT',
153 ## because the latter is not hnoured by the old serial test
155 TESTS_ENVIRONMENT = \
156 if test x"$$jprog_doing_installcheck" != x"yes"; then \
157 jprog_classpath='$(abs_top_builddir):$(abs_top_srcdir)'; \
158 export jprog_classpath; \
159 PATH='$(abs_top_builddir)$(PATH_SEPARATOR)'$$PATH; \
162 unset jprog_classpath || :; \
163 PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
166 config_time_prefix='@prefix@'; export config_time_prefix;
175 XFAIL_TESTS = badarg.test
177 EXTRA_DIST += $(TESTS)
180 cat > simple.test <<'END'
185 cat > prefix.test <<'END'
187 jprefix=`jprog --print-prefix` || exit 1
188 echo "$0: exp prefix: $config_time_prefix"
189 echo "$0: got prefix: $jprefix"
190 test x"$jprefix" = x"$config_time_prefix"
193 cat > stdout.test <<'END'
196 jprog --hello-stdout >stdout.out 2>stdout.err || { echo \$?=$?; rc=1; }
197 sed 's/^/out:/' <stdout.out # For debugging.
198 sed 's/^/err:/' <stdout.err >&2 # Likewise.
199 test -s stdout.err && rc=1
200 test "`cat stdout.out`" = 'Hello, Stream!' || rc=1
201 rm -f stdout.out stdout.err || rc=1
205 cat > stderr.test <<'END'
208 jprog --hello-stderr >stderr.out 2>stderr.err || { echo \$?=$?; rc=1; }
209 sed 's/^/out:/' <stderr.out # For debugging.
210 sed 's/^/err:/' <stderr.err >&2 # Likewise.
211 test -s stderr.out && rc=1
212 test "`cat stderr.err`" = 'Hello, Stream!' || rc=1
213 rm -f stderr.out stderr.err || rc=1
217 cat > badarg.test <<'END'
230 # To have the parallel testsuite more verbose.
231 VERBOSE=yes; export VERBOSE
233 ./configure --prefix="$(pwd)/_inst"
234 cat PkgLocation.java # For debugging.