quid: improve error message, add negative unit tests
authorjrose
Tue Sep 09 16:15:01 2008 -0700 (14 months ago)
changeset 38e333e7c4b62
parent 2c1612cfa2222
child 47d810bbd3a83
quid: improve error message, add negative unit tests
quid.patch
--- a/quid.patch Tue Sep 09 13:12:17 2008 -0700
+++ b/quid.patch Tue Sep 09 16:15:01 2008 -0700
@@ -10,7 +10,7 @@ diff --git a/src/share/classes/com/sun/t
+ if (ch == '\"') {
+ scanChar();
+ if (ch == '\"')
-+ lexError(pos, "empty.bytecode.ident");
++ lexError(pos, "empty.bytecode.ident");
+ while (ch != '\"' && ch != CR && ch != LF && bp < buflen) {
+ switch (ch) {
+ // reject any "dangerous" char which is illegal somewhere in the JVM spec
@@ -18,7 +18,7 @@ diff --git a/src/share/classes/com/sun/t
+ case '/': case '.': case ';': // illegal everywhere
+ case '<': case '>': // illegal in methods, dangerous in classes
+ case '[': // illegal in classes
-+ lexError(pos, "illegal.bytecode.ident.char", String.valueOf((int)ch));
++ lexError(bp, "illegal.bytecode.ident.char", String.valueOf((int)ch));
+ }
+ scanLitChar();
+ }
@@ -66,11 +66,111 @@ diff --git a/src/share/classes/com/sun/t
compiler.err.unclosed.char.lit=\
unclosed character literal
compiler.err.unclosed.comment=\
-diff --git a/test/tools/javac/QuotedIdent.java b/test/tools/javac/QuotedIdent.java
+diff --git a/test/tools/javac/quid/MakeNegTests.sh b/test/tools/javac/quid/MakeNegTests.sh
new file mode 100644
--- /dev/null
-+++ b/test/tools/javac/QuotedIdent.java
-@@ -0,0 +1,121 @@
++++ b/test/tools/javac/quid/MakeNegTests.sh
+@@ -0,0 +1,95 @@
++#!/bin/sh
++
++#
++# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
++# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++#
++# This code is free software; you can redistribute it and/or modify it
++# under the terms of the GNU General Public License version 2 only, as
++# published by the Free Software Foundation.
++#
++# This code is distributed in the hope that it will be useful, but WITHOUT
++# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
++# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
++# version 2 for more details (a copy is included in the LICENSE file that
++# accompanied this code).
++#
++# You should have received a copy of the GNU General Public License version
++# 2 along with this work; if not, write to the Free Software Foundation,
++# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
++#
++# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
++# CA 95054 USA or visit www.sun.com if you need additional information or
++# have any questions.
++#
++
++# @test
++# @bug 6746458
++# @summary Verify correct rejection of illegal quoted identifiers.
++# @run shell MakeNegTests.sh
++
++default_template=QuotedIdent.java
++# the rest of this file is a generic "//BAD"-line tester
++
++: ${TESTSRC=.} ${TESTCLASSES=.}
++javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
++
++verbose=false quiet=false
++
++main() {
++ case "${@-}" in
++ *.java*)
++ for template; do
++ expand_and_test "$template"
++ done;;
++ *) expand_and_test "${TESTSRC}/$default_template";;
++ esac
++}
++
++expand_and_test() {
++ template=$1
++ expand "$@"
++ testneg "$@"
++}
++
++expand() {
++ template=$1
++ badlines=` grep -n < "$template" '//BAD' `
++ badcount=` echo "$badlines" | wc -l `
++ [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; }
++ $quiet || echo "Expanding $badcount negative test cases from $template:"
++ $quiet || echo "$badlines"
++ badnums=` echo "$badlines" | sed 's/:.*//' `
++ casestem=` getcasestem "$template" `
++ tclassname=` basename "$template" .java `
++ rm "$casestem"*.java
++ for badnum in $badnums; do
++ casefile="$casestem"${badnum}.java
++ cclassname=` basename "$casefile" .java `
++ sed < "$template" > "$casefile" "
++ ${badnum}s:^ *[/*]*: :
++ s/${tclassname}/${cclassname}/g
++ "
++ $verbose && diff -u "$template" "$casefile"
++ done
++}
++
++getcasestem() {
++ echo "$1" | sed 's/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/'
++}
++
++testneg() {
++ template=$1
++ for casefile in ` getcasestem "$template" `*.java; do
++ $quiet || echo -------- $javac "$casefile"
++ $javac "$casefile" > "$casefile".errlog 2>&1 && {
++ echo "*** Compilation unexpectedly succeeded: $casefile"
++ exit 1
++ }
++ $quiet || echo "Compilation failed as expected"
++ $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog
++ rm "$casefile".errlog
++ done
++}
++
++main "$@"
+diff --git a/test/tools/javac/quid/QuotedIdent.java b/test/tools/javac/quid/QuotedIdent.java
+new file mode 100644
+--- /dev/null
++++ b/test/tools/javac/quid/QuotedIdent.java
+@@ -0,0 +1,120 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -96,6 +196,7 @@ new file mode 100644
+
+/*
+ * @test
++ * @bug 6746458
+ * @summary Verify correct lexing of quoted identifiers.
+ * @author jrose
+ *
@@ -103,12 +204,11 @@ new file mode 100644
+ * <code>
+ * $ cd $MY_REPO_DIR/langtools
+ * $ (cd make; make)
-+ * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/QuotedIdent.java
++ * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
+ * $ java -version # should print 1.6 or later
+ * $ java -cp dist QuotedIdent
+ * </code>
+ *
-+ * @compile QuotedIdent.java
+ * @run main QuotedIdent
+ */
+
@@ -125,12 +225,11 @@ new file mode 100644
+ }
+ }
+
-+ /* negative tests, FTR:
-+ static class #"" { } // BAD
-+ static class #"<foo>" { } // BAD
-+ static class #" // BAD
-+ " { } // BAD
-+ */
++ // negative tests:
++ //static class #"" { } //BAD empty ident name
++ //static class #"<foo>" { } //BAD bad char in ident name
++ /*static class /*(//BAD ident name interrupted by newline)*/ #"jump:
++ " { } /* uncomment previous line to attempt class w/ bad name */
+
+ static class #"int" extends Number {
+ final int #"int";