8016908: TEST_BUG: removing non-ascii characters causes tests to fail

Wed, 26 Jun 2013 09:54:46 -0700

author
ksrini
date
Wed, 26 Jun 2013 09:54:46 -0700
changeset 1855
c2d9303c3477
parent 1854
aceae9ceebbe
child 1856
3b2e10524627

8016908: TEST_BUG: removing non-ascii characters causes tests to fail
Reviewed-by: jjg, vromero

test/tools/javac/api/6437999/T6437999.java file | annotate | diff | comparison | revisions
test/tools/javac/api/6437999/Utf8.java file | annotate | diff | comparison | revisions
test/tools/javac/api/T6306137.java file | annotate | diff | comparison | revisions
     1.1 --- a/test/tools/javac/api/6437999/T6437999.java	Tue Jun 25 20:08:52 2013 +0400
     1.2 +++ b/test/tools/javac/api/6437999/T6437999.java	Wed Jun 26 09:54:46 2013 -0700
     1.3 @@ -33,11 +33,28 @@
     1.4   */
     1.5  
     1.6  import java.io.File;
     1.7 +import java.io.IOException;
     1.8  import java.nio.charset.Charset;
     1.9 +import java.nio.file.Files;
    1.10 +import java.util.ArrayList;
    1.11  import java.util.Collections;
    1.12 +import java.util.List;
    1.13  import javax.tools.*;
    1.14 +import static java.nio.file.StandardOpenOption.*;
    1.15  
    1.16  public class T6437999 extends ToolTester {
    1.17 +    final File testFile = new File("Utf8.java");
    1.18 +    T6437999() throws IOException {
    1.19 +        createTestFile();
    1.20 +    }
    1.21 +    final void createTestFile() throws IOException {
    1.22 +        List<String> scratch = new ArrayList<>();
    1.23 +        scratch.add("// @author Peter von der Ah" + (char) 0xe9);
    1.24 +        scratch.add("class Utf8{}");
    1.25 +        Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"),
    1.26 +                CREATE, TRUNCATE_EXISTING);
    1.27 +    }
    1.28 +
    1.29      static class MyDiagnosticListener implements DiagnosticListener<JavaFileObject> {
    1.30          boolean error = false;
    1.31          public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    1.32 @@ -55,7 +72,7 @@
    1.33          dl.error = false;
    1.34          fm = getFileManager(tool, dl, Charset.forName("ASCII"));
    1.35          fm.handleOption("-source", sourceLevel.iterator());
    1.36 -        files = fm.getJavaFileObjects(new File(test_src, "Utf8.java"));
    1.37 +        files = fm.getJavaFileObjects(testFile);
    1.38          tool.getTask(null, fm, null, null, null, files).call();
    1.39          if (!dl.error)
    1.40              throw new AssertionError("No error in ASCII mode");
    1.41 @@ -63,12 +80,12 @@
    1.42          dl.error = false;
    1.43          fm = getFileManager(tool, dl, Charset.forName("UTF-8"));
    1.44          fm.handleOption("-source", sourceLevel.iterator());
    1.45 -        files = fm.getJavaFileObjects(new File(test_src, "Utf8.java"));
    1.46 +        files = fm.getJavaFileObjects(testFile);
    1.47          task = tool.getTask(null, fm, null, null, null, files);
    1.48          if (dl.error)
    1.49              throw new AssertionError("Error in UTF-8 mode");
    1.50      }
    1.51 -    public static void main(String... args) {
    1.52 +    public static void main(String... args) throws IOException {
    1.53          new T6437999().test(args);
    1.54      }
    1.55  }
     2.1 --- a/test/tools/javac/api/6437999/Utf8.java	Tue Jun 25 20:08:52 2013 +0400
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,27 +0,0 @@
     2.4 -/*
     2.5 - * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 - *
     2.8 - * This code is free software; you can redistribute it and/or modify it
     2.9 - * under the terms of the GNU General Public License version 2 only, as
    2.10 - * published by the Free Software Foundation.
    2.11 - *
    2.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 - * version 2 for more details (a copy is included in the LICENSE file that
    2.16 - * accompanied this code).
    2.17 - *
    2.18 - * You should have received a copy of the GNU General Public License version
    2.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 - *
    2.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 - * or visit www.oracle.com if you need additional information or have any
    2.24 - * questions.
    2.25 - */
    2.26 -
    2.27 -/**
    2.28 - * @author Peter von der Ah\u00e9
    2.29 - */
    2.30 -class Utf8 {}
     3.1 --- a/test/tools/javac/api/T6306137.java	Tue Jun 25 20:08:52 2013 +0400
     3.2 +++ b/test/tools/javac/api/T6306137.java	Wed Jun 26 09:54:46 2013 -0700
     3.3 @@ -31,8 +31,14 @@
     3.4   */
     3.5  
     3.6  import java.io.File;
     3.7 +import java.io.IOException;
     3.8 +import java.nio.charset.Charset;
     3.9 +import java.nio.file.Files;
    3.10 +import java.util.ArrayList;
    3.11  import java.util.Arrays;
    3.12 +import java.util.List;
    3.13  import javax.tools.*;
    3.14 +import static java.nio.file.StandardOpenOption.*;
    3.15  
    3.16  public class T6306137 {
    3.17      boolean error;
    3.18 @@ -40,8 +46,9 @@
    3.19      final JavaCompiler compiler;
    3.20      Iterable<? extends JavaFileObject> files;
    3.21      DiagnosticListener<JavaFileObject> dl;
    3.22 +    final File testFile = new File("Utf8.java");
    3.23  
    3.24 -    T6306137() {
    3.25 +    T6306137() throws IOException {
    3.26          dl = new DiagnosticListener<JavaFileObject>() {
    3.27                  public void report(Diagnostic<? extends JavaFileObject> message) {
    3.28                      if (message.getKind() == Diagnostic.Kind.ERROR)
    3.29 @@ -56,11 +63,17 @@
    3.30          };
    3.31          compiler = ToolProvider.getSystemJavaCompiler();
    3.32          fm = compiler.getStandardFileManager(dl, null, null);
    3.33 -        String srcdir = System.getProperty("test.src");
    3.34          files =
    3.35 -            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6306137.java")));
    3.36 +            fm.getJavaFileObjectsFromFiles(Arrays.asList(testFile));
    3.37 +        createTestFile();
    3.38      }
    3.39 -
    3.40 +    final void createTestFile() throws IOException {
    3.41 +        List<String> scratch = new ArrayList<>();
    3.42 +        scratch.add("// @author Peter von der Ah" + (char)0xe9);
    3.43 +        scratch.add("class Utf8{}");
    3.44 +        Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"),
    3.45 +                CREATE, TRUNCATE_EXISTING);
    3.46 +    }
    3.47      void test(String encoding, boolean good) {
    3.48          error = false;
    3.49          Iterable<String> args = Arrays.asList("-source", "6", "-encoding", encoding, "-d", ".");
    3.50 @@ -74,7 +87,7 @@
    3.51          }
    3.52      }
    3.53  
    3.54 -    public static void main(String[] args) {
    3.55 +    public static void main(String[] args) throws IOException {
    3.56          T6306137 self = new T6306137();
    3.57          self.test("utf-8", true);
    3.58          self.test("ascii", false);

mercurial