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 typical "nested" source tree setup (i.e., different
21 # components/aspects are separated into different subdirectories),
22 # and uses the 'parallel-tests' testsuite driver. The sister test
23 # 'java-compile-run-flat.test' do similar checks with a "flat" setup
24 # (i.e., everything in the top-level directory), and forcing the use
25 # of the older non-parallel 'simple-tests' driver.
31 echo "AC_SUBST([PATH_SEPARATOR], ['$PATH_SEPARATOR'])" >> configure.ac
33 cat >> configure.ac <<'END'
34 AC_SUBST([JAVA], [java])
35 AC_CONFIG_SRCDIR([jprog/PkgLocation.jin])
36 AC_SUBST([jprogdatadir], ['${pkgdatadir}'])
37 AC_SUBST([jprogclassdir], ['${jprogdatadir}/jprog'])
38 AC_CONFIG_FILES([jprog/PkgLocation.java:jprog/PkgLocation.jin])
39 AC_CONFIG_FILES([jprog/Makefile bin/Makefile tests/Makefile])
43 ## TOP-LEVEL SETUP AND TARGETS ##
45 cat > Makefile.am <<'END'
46 SUBDIRS = bin jprog tests
49 ls -l $(srcdir)/* ;: For debugging.
50 test $(srcdir) = . || ls -l * ;: Likewise.
51 test -f $(srcdir)/jprog/Main.java
52 test -f $(srcdir)/jprog/HelloStream.java
53 test -f $(srcdir)/jprog/PkgLocation.jin
54 test -f jprog/PkgLocation.java
55 test -f jprog/HelloStream.class
56 test -f jprog/Main.class
57 test -f jprog/PkgLocation.class
58 test -f jprog/classjprogclass.stamp
61 ls -l $(jprogclassdir) ;: For debugging.
62 test -f $(jprogclassdir)/HelloStream.class
63 test -f $(jprogclassdir)/Main.class
64 test -f $(jprogclassdir)/PkgLocation.class
65 if find $(prefix) | grep '\.stamp$$'; then exit 1; else :; fi
68 jprog_doing_installcheck=yes $(MAKE) $(AM_MAKEFLAGS) check
70 check-local: test-built
71 installcheck-local: test-installed run-installed
73 .PHONY: test-built test-installed run-installed
80 cat > bin/Makefile.am <<'END'
83 edit_script = sed -e 's|[@]JAVA@|$(JAVA)|g' \
84 -e 's|[@]jprogdatadir@|$(jprogdatadir)|g' \
85 -e 's|[@]SHELL@|$(SHELL)|g' \
86 -e 's|[@]PATH_SEPARATOR@|$(PATH_SEPARATOR)|g'
90 $(edit_script) `test -f '$@.sh' || echo $(srcdir)/`$@.sh >$@-t
91 chmod a-w $@-t && chmod a+x $@-t && mv -f $@-t $@
92 sed 's/^/ | /' $@ ;: for debugging.
98 cat > bin/jprog.sh <<'END'
100 CLASSPATH=${jprog_classpath-'@jprogdatadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
103 0) exec @JAVA@ jprog.Main;;
104 *) exec @JAVA@ jprog.Main "$@";;
112 cat > jprog/Makefile.am <<'END'
113 dist_jprogclass_JAVA = Main.java HelloStream.java
114 nodist_jprogclass_JAVA = PkgLocation.java
117 cat > jprog/PkgLocation.jin <<'END'
119 public class PkgLocation {
120 public static String prefix() {
121 return new String("@prefix@");
126 cat > jprog/Main.java <<'END'
128 import jprog.PkgLocation;
129 import jprog.HelloStream;
131 public static void main(String[] args) {
132 for (int i = 0; i < args.length; i++) {
133 if (args[i].equals("--print-prefix")) {
134 System.out.println(PkgLocation.prefix());
135 } else if (args[i].equals("--hello-stdout")) {
136 HelloStream.to(System.out);
137 } else if (args[i].equals("--hello-stderr")) {
138 HelloStream.to(System.err);
140 System.err.println("jprog: invalid option '" + args[i] +
150 cat > jprog/HelloStream.java <<'END'
152 import java.io.PrintStream;
154 public static void to(PrintStream stream) {
155 stream.println("Hello, Stream!");
164 cat > tests/Makefile.am <<'END'
165 AM_TESTS_ENVIRONMENT = \
166 if test x"$$jprog_doing_installcheck" != x"yes"; then \
167 jprog_classpath='$(abs_top_builddir):$(abs_top_srcdir)'; \
168 export jprog_classpath; \
169 PATH='$(abs_top_builddir)/bin$(PATH_SEPARATOR)'$$PATH; \
172 unset jprog_classpath || :; \
173 PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
176 config_time_prefix='@prefix@'; export config_time_prefix;
185 XFAIL_TESTS = badarg.test
187 EXTRA_DIST = $(TESTS)
190 cat > tests/simple.test <<'END'
195 cat > tests/prefix.test <<'END'
197 jprefix=`jprog --print-prefix` || exit 1
198 echo "$0: exp prefix: $config_time_prefix"
199 echo "$0: got prefix: $jprefix"
200 test x"$jprefix" = x"$config_time_prefix"
203 cat > tests/stdout.test <<'END'
206 jprog --hello-stdout >stdout.out 2>stdout.err || { echo \$?=$?; rc=1; }
207 sed 's/^/out:/' <stdout.out # For debugging.
208 sed 's/^/err:/' <stdout.err >&2 # Likewise.
209 test -s stdout.err && rc=1
210 test "`cat stdout.out`" = 'Hello, Stream!' || rc=1
211 rm -f stdout.out stdout.err || rc=1
215 cat > tests/stderr.test <<'END'
218 jprog --hello-stderr >stderr.out 2>stderr.err || { echo \$?=$?; rc=1; }
219 sed 's/^/out:/' <stderr.out # For debugging.
220 sed 's/^/err:/' <stderr.err >&2 # Likewise.
221 test -s stderr.out && rc=1
222 test "`cat stderr.err`" = 'Hello, Stream!' || rc=1
223 rm -f stderr.out stderr.err || rc=1
227 cat > tests/badarg.test <<'END'
232 chmod a+x tests/*.test
240 # To have the parallel testsuite more verbose.
241 VERBOSE=yes; export VERBOSE
243 ./configure --prefix="`pwd`/_inst"
244 cat jprog/PkgLocation.java # For debugging.