source: trunk/openjdk/jdk/test/tools/launcher/Arrrghs.sh

Last change on this file was 278, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b22 from branches/vendor/oracle.

File size: 4.3 KB
Line 
1#!/bin/sh
2# @test
3# @bug 5030233 6214916 6356475 6684582
4# @build Arrrghs
5# @run shell Arrrghs.sh
6# @summary Argument parsing validation.
7# @author Joseph E. Kowalski
8
9#
10# Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
11# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12#
13# This code is free software; you can redistribute it and/or modify it
14# under the terms of the GNU General Public License version 2 only, as
15# published by the Free Software Foundation.
16#
17# This code is distributed in the hope that it will be useful, but WITHOUT
18# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20# version 2 for more details (a copy is included in the LICENSE file that
21# accompanied this code).
22#
23# You should have received a copy of the GNU General Public License version
24# 2 along with this work; if not, write to the Free Software Foundation,
25# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26#
27# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28# or visit www.oracle.com if you need additional information or have any
29# questions.
30#
31
32#
33# This test is intended to validate generic argument parsing and
34# handling.
35#
36# Oh yes, since the response to argument parsing errors is often
37# a visceral one, the name Arrrghs (pronounced "args") seems rather
38# appropriate.
39#
40
41# Verify directory context variables are set
42if [ "${TESTJAVA}" = "" ]
43then
44 echo "TESTJAVA not set. Test cannot execute. Failed."
45 exit 1
46fi
47
48if [ "${TESTSRC}" = "" ]
49then
50 echo "TESTSRC not set. Test cannot execute. Failed."
51 exit 1
52fi
53
54if [ "${TESTCLASSES}" = "" ]
55then
56 echo "TESTCLASSES not set. Test cannot execute. Failed."
57 exit 1
58fi
59
60#
61# Shell routine to test for the proper handling of the cp/classpath
62# option is correct (see 5030233). This option is unique in that it
63# is the only option to the java command (and friends) which is
64# separated from its option argument by a space, rather than an
65# equals sign.
66#
67# Parameters:
68# $1 cmd utility name to be tested (java, javac, ...)
69# $2 option either the -cp or -classpath option to be
70# tested.
71#
72TestCP() {
73 mess="`$TESTJAVA/bin/$1 $2 2>&1 1>/dev/null`"
74 if [ $? -eq 0 ]; then
75 echo "Invalid $1 $2 syntax accepted"
76 exit 1
77 fi
78 if [ -z "$mess" ]; then
79 echo "No Usage message from invalid $1 $2 syntax"
80 exit 1
81 fi
82}
83
84#
85# Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
86#
87TestXUsage() {
88 $TESTJAVA/bin/java -X > /dev/null 2>&1
89 if [ $? -ne 0 ]; then
90 echo "-X option failed"
91 exit 1
92 fi
93}
94
95#
96# Test if java -help works
97#
98TestHelp() {
99 $TESTJAVA/bin/java -help > /dev/null 2>&1
100 if [ $? -ne 0 ]; then
101 echo "-help option failed"
102 exit 1
103 fi
104}
105#
106# Test to ensure that a missing main class is indicated in the error message
107#
108TestMissingMainClass() {
109 # First create a small jar file with no main
110 printf "public class Foo {}\n" > Foo.java
111 $TESTJAVA/bin/javac Foo.java
112 if [ $? -ne 0 ]; then
113 printf "Error: compilation of Foo.java failed\n"
114 exit 1
115 fi
116 printf "Main-Class: Bar\n" > manifest
117 $TESTJAVA/bin/jar -cvfm some.jar manifest Foo.class
118 if [ ! -f some.jar ]; then
119 printf "Error: did not find some.jar\n"
120 exit 1
121 fi
122
123 # test with -jar
124 mess="`$TESTJAVA/bin/java -jar some.jar 2>&1 1>/dev/null`"
125 echo $mess | grep 'Bar' 2>&1 > /dev/null
126 if [ $? -ne 0 ]; then
127 printf "Error: did not find main class missing message\n"
128 exit 1
129 fi
130
131 # test with a non-existent class using classpath
132 mess="`$TESTJAVA/bin/java -cp some.jar Bar 2>&1 1>/dev/null`"
133 echo $mess | grep 'Bar' 2>&1 > /dev/null
134 if [ $? -ne 0 ]; then
135 printf "Error: did not find main class missing message\n"
136 exit 1
137 fi
138
139 # cleanup
140 rm -f some.jar Foo.* manifest
141}
142
143#
144# Main processing:
145#
146
147#
148# Tests for 5030233
149#
150TestCP java -cp
151TestCP java -classpath
152TestCP javac -cp
153TestCP javac -classpath
154TestXUsage
155TestHelp
156TestMissingMainClass
157
158#
159# Tests for 6214916
160#
161#
162# These tests require that a JVM (any JVM) be installed in the system registry.
163# If none is installed, skip this test.
164$TESTJAVA/bin/java -version:1.1+ -version >/dev/null 2>&1
165if [ $? -eq 0 ]; then
166 $TESTJAVA/bin/java -classpath $TESTCLASSES Arrrghs $TESTJAVA/bin/java
167 if [ $? -ne 0 ]; then
168 echo "Argument Passing Tests failed"
169 exit 1
170 fi
171else
172 printf "Warning:Argument Passing Tests were skipped, no java found in system registry."
173fi
174exit 0
Note: See TracBrowser for help on using the repository browser.