test/tools/javac/quid/MakeNegTests.sh

Fri, 21 Aug 2009 14:58:21 -0700

author
jjg
date
Fri, 21 Aug 2009 14:58:21 -0700
changeset 377
d9febdd5ae21
parent 267
e2722bd43f3a
child 385
74760fd5197f
permissions
-rw-r--r--

6873845: refine access to symbol file
Reviewed-by: darcy

     1 #!/bin/sh
     3 #
     4 # Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
     5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6 #
     7 # This code is free software; you can redistribute it and/or modify it
     8 # under the terms of the GNU General Public License version 2 only, as
     9 # published by the Free Software Foundation.
    10 #
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14 # version 2 for more details (a copy is included in the LICENSE file that
    15 # accompanied this code).
    16 #
    17 # You should have received a copy of the GNU General Public License version
    18 # 2 along with this work; if not, write to the Free Software Foundation,
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20 #
    21 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22 # CA 95054 USA or visit www.sun.com if you need additional information or
    23 # have any questions.
    24 #
    26 # @test
    27 # @bug 6746458
    28 # @summary Verify correct rejection of illegal quoted identifiers.
    29 # @run shell MakeNegTests.sh
    31 default_template=QuotedIdent.java
    32 # the rest of this file is a generic "//BAD"-line tester
    34 : ${TESTSRC=.} ${TESTCLASSES=.}
    35 javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
    37 verbose=false quiet=false
    39 main() {
    40   case "${@-}" in
    41   *.java*)
    42     for template in "$@"; do
    43       expand_and_test "$template"
    44     done;;
    45   *) expand_and_test "${TESTSRC}/$default_template";;
    46   esac
    47 }
    49 expand_and_test() {
    50   template=$1
    51   expand "$@"
    52   testneg "$@"
    53 }
    55 expand() {
    56   template=$1
    57   badlines=` grep -n < "$template" '//BAD' `
    58   badcount=` echo "$badlines" | wc -l `
    59   [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; }
    60   $quiet || echo "Expanding $badcount negative test cases from $template:"
    61   $quiet || echo "$badlines"
    62   badnums=` echo "$badlines" | sed 's/:.*//' `
    63   casestem=` getcasestem "$template" `
    64   tclassname=` basename "$template" .java `
    65   rm "$casestem"*.java
    66   for badnum in $badnums; do
    67     casefile="$casestem"${badnum}.java
    68     cclassname=` basename "$casefile" .java `
    69     sed < "$template" > "$casefile" "
    70       s|@compile|@compile/fail|
    71       / @[a-z]/s|@|##|
    72       ${badnum}s:^ *[/*]*:    :
    73       s/${tclassname}/${cclassname}/g
    74     "
    75     $verbose && diff -u "$template" "$casefile"
    76   done
    77 }
    79 getcasestem() {
    80   echo "$1" | sed 's/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/'
    81 }
    83 testneg() {
    84   template=$1
    85   for casefile in ` getcasestem "$template" `*.java; do
    86     $quiet || echo -------- $javac "$casefile"
    87     $javac "$casefile" > "$casefile".errlog 2>&1 && {
    88       echo "*** Compilation unexpectedly succeeded:  $casefile"
    89       exit 1
    90     }
    91     $quiet || echo "Compilation failed as expected"
    92     $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog
    93     rm "$casefile".errlog
    94   done
    95 }
    97 main "$@"

mercurial