blob: c2fe084d02fdfd701c5a776e0df712604a8e5c22 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001#!/bin/sh
2# @test Arrrghs.sh
3# @bug 5030233 6214916 6356475 6571029
4# @build Arrrghs
5# @run shell Arrrghs.sh
6# @summary Argument parsing validation.
7# @author Joseph E. Kowalski
8
9#
10# Copyright 2004-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
28# CA 95054 USA or visit www.sun.com if you need additional information or
29# have any 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#
107# Main processing:
108#
109
110#
111# Tests for 5030233
112#
113TestCP java -cp
114TestCP java -classpath
115TestCP java -jar
116TestCP javac -cp
117TestCP javac -classpath
118TestXUsage
119TestHelp
120
121#
122# Tests for 6214916
123#
124#
125# These tests require that a JVM (any JVM) be installed in the system registry.
126# If none is installed, skip this test.
127$TESTJAVA/bin/java -version:1.1+ -version >/dev/null 2>&1
128if [ $? -eq 0 ]; then
129 $TESTJAVA/bin/java -classpath $TESTCLASSES Arrrghs $TESTJAVA/bin/java
130 if [ $? -ne 0 ]; then
131 echo "Argument Passing Tests failed"
132 exit 1
133 fi
134else
135 printf "Warning:Argument Passing Tests were skipped, no java found in system registry."
136fi
137exit 0