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), and
22 # uses the parallel testsuite driver.
23 # The sister test 'java-compile-run-flat.test' do similar checks with a
24 # "flat" setup (i.e., everything in the top-level directory), and forcing
25 # 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
79 cat > bin/Makefile.am <<'END'
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'
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.
97 cat > bin/jprog.sh <<'END'
99 CLASSPATH=${jprog_classpath-'@jprogdatadir@'}${CLASSPATH+"@PATH_SEPARATOR@$CLASSPATH"}
102 0) exec @JAVA@ jprog.Main;;
103 *) exec @JAVA@ jprog.Main "$@";;
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'
118 public class PkgLocation {
119 public static String prefix() {
120 return new String("@prefix@");
125 cat > jprog/Main.java <<'END'
127 import jprog.PkgLocation;
128 import jprog.HelloStream;
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);
139 System.err.println("jprog: invalid option '" + args[i] +
149 cat > jprog/HelloStream.java <<'END'
151 import java.io.PrintStream;
153 public static void to(PrintStream stream) {
154 stream.println("Hello, Stream!");
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; \
171 unset jprog_classpath || :; \
172 PATH='$(prefix)/bin$(PATH_SEPARATOR)'$$PATH; \
175 config_time_prefix='@prefix@'; export config_time_prefix;
184 XFAIL_TESTS = badarg.test
186 EXTRA_DIST = $(TESTS)
189 cat > tests/simple.test <<'END'
194 cat > tests/prefix.test <<'END'
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'
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
214 cat > tests/stderr.test <<'END'
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
226 cat > tests/badarg.test <<'END'
231 chmod a+x tests/*.test
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.