6764226: ListTest fails on javap output with bad characters

Mon, 27 Oct 2008 14:25:59 -0700

author
jjg
date
Mon, 27 Oct 2008 14:25:59 -0700
changeset 164
5ebe90e0afff
parent 163
8d7fa40da0eb
child 165
4f7b344a1ce0

6764226: ListTest fails on javap output with bad characters
Reviewed-by: darcy

test/tools/javap/ListTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/test/tools/javap/ListTest.java	Fri Oct 24 20:47:47 2008 -0700
     1.2 +++ b/test/tools/javap/ListTest.java	Mon Oct 27 14:25:59 2008 -0700
     1.3 @@ -82,16 +82,16 @@
     1.4          String[] args = new String[options.size() + 1];
     1.5          options.toArray(args);
     1.6          args[args.length - 1] = testClassName;
     1.7 -        String oldOut = runOldJavap(args);
     1.8 -        String newOut = runNewJavap(args);
     1.9 -        boolean ok = oldOut.equals(newOut);
    1.10 +        byte[] oldOut = runOldJavap(args);
    1.11 +        byte[] newOut = runNewJavap(args);
    1.12 +        boolean ok = equal(oldOut, newOut);
    1.13          System.err.println((ok ? "pass" : "FAIL") + ": " + testClassName);
    1.14          if (!ok && viewResults)
    1.15              view(oldOut, newOut);
    1.16          return ok;
    1.17      }
    1.18  
    1.19 -    String runOldJavap(String[] args) {
    1.20 +    byte[] runOldJavap(String[] args) {
    1.21          //System.err.println("OLD: " + Arrays.asList(args));
    1.22          PrintStream oldOut = System.out;
    1.23          ByteArrayOutputStream out = new ByteArrayOutputStream();
    1.24 @@ -101,29 +101,34 @@
    1.25          } finally {
    1.26              System.setOut(oldOut);
    1.27          }
    1.28 -        return out.toString();
    1.29 +        return out.toByteArray();
    1.30      }
    1.31  
    1.32 -    String runNewJavap(String[] args) {
    1.33 +    byte[] runNewJavap(String[] args) {
    1.34          String[] nArgs = new String[args.length + 2];
    1.35          nArgs[0] = "-XDcompat";
    1.36          nArgs[1] = "-XDignore.symbol.file";
    1.37          System.arraycopy(args, 0, nArgs, 2, args.length);
    1.38          //System.err.println("NEW: " + Arrays.asList(nArgs));
    1.39 -        StringWriter out = new StringWriter();
    1.40 -        com.sun.tools.javap.Main.run(nArgs, new PrintWriter(out, true));
    1.41 -        return out.toString();
    1.42 +        ByteArrayOutputStream out = new ByteArrayOutputStream();
    1.43 +        com.sun.tools.javap.Main.run(nArgs,
    1.44 +                                     new PrintWriter(new OutputStreamWriter(out), true));
    1.45 +        return out.toByteArray();
    1.46      }
    1.47  
    1.48 -    File write(String text, String suffix) throws IOException {
    1.49 -        File f = File.createTempFile("ListTest", suffix);
    1.50 -        FileWriter out = new FileWriter(f);
    1.51 +    File write(byte[] text, String suffix) throws IOException {
    1.52 +        File f = new File("ListTest." + suffix);
    1.53 +        FileOutputStream out = new FileOutputStream(f);
    1.54          out.write(text);
    1.55          out.close();
    1.56          return f;
    1.57      }
    1.58  
    1.59 -    void view(String oldOut, String newOut) throws Exception {
    1.60 +    boolean equal(byte[] a1, byte[] a2) {
    1.61 +        return Arrays.equals(a1, a2);
    1.62 +    }
    1.63 +
    1.64 +    void view(byte[] oldOut, byte[] newOut) throws Exception {
    1.65          File oldFile = write(oldOut, "old");
    1.66          File newFile = write(newOut, "new");
    1.67          List<String> cmd = new ArrayList<String>();

mercurial