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