< prev index next >

test/langtools/tools/javac/6917288/T6917288.java

Print this page
rev 50604 : imported patch jep181-rev1
   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  52      */
  53     void test(Kind k) throws Exception {
  54         System.err.println("Test " + (++count) + ": " + k);
  55         File testDir = new File("test" + count);
  56         File srcDir = new File(testDir, "src");
  57         srcDir.mkdirs();
  58         File classesDir = new File(testDir, "classes");
  59         classesDir.mkdirs();
  60 
  61         List<String> opts = new ArrayList<String>();
  62         opts.add("-d");
  63         opts.add(classesDir.getPath());
  64 
  65         File f = writeFile(srcDir, k);
  66         int rc = compile(opts, f);
  67         if (rc != 0) {
  68             error("compilation failed: rc=" + rc);
  69             return;
  70         }
  71 



  72         check(classesDir, "Test.class", "Test$Inner.class", "Test$1.class");




  73     }
  74 
  75     /**
  76      *  Compile files with given options.
  77      *  Display any output from compiler, and return javac return code.
  78      */
  79     int compile(List<String> opts, File... files) {
  80         List<String> args = new ArrayList<String>();
  81         args.addAll(opts);
  82         for (File f: files)
  83             args.add(f.getPath());
  84         StringWriter sw = new StringWriter();
  85         PrintWriter pw = new PrintWriter(sw);
  86         int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
  87         pw.close();
  88         String out = sw.toString();
  89         if (out.length() > 0)
  90             System.err.println(out);
  91         return rc;
  92     }


   1 /*
   2  * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  52      */
  53     void test(Kind k) throws Exception {
  54         System.err.println("Test " + (++count) + ": " + k);
  55         File testDir = new File("test" + count);
  56         File srcDir = new File(testDir, "src");
  57         srcDir.mkdirs();
  58         File classesDir = new File(testDir, "classes");
  59         classesDir.mkdirs();
  60 
  61         List<String> opts = new ArrayList<String>();
  62         opts.add("-d");
  63         opts.add(classesDir.getPath());
  64 
  65         File f = writeFile(srcDir, k);
  66         int rc = compile(opts, f);
  67         if (rc != 0) {
  68             error("compilation failed: rc=" + rc);
  69             return;
  70         }
  71 
  72         switch (k) {
  73             case ALWAYS:
  74             case TRUE:
  75                 check(classesDir, "Test.class", "Test$Inner.class", "Test$1.class");
  76                 break;
  77             default:
  78                 check(classesDir, "Test.class", "Test$Inner.class");
  79         }
  80     }
  81 
  82     /**
  83      *  Compile files with given options.
  84      *  Display any output from compiler, and return javac return code.
  85      */
  86     int compile(List<String> opts, File... files) {
  87         List<String> args = new ArrayList<String>();
  88         args.addAll(opts);
  89         for (File f: files)
  90             args.add(f.getPath());
  91         StringWriter sw = new StringWriter();
  92         PrintWriter pw = new PrintWriter(sw);
  93         int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);
  94         pw.close();
  95         String out = sw.toString();
  96         if (out.length() > 0)
  97             System.err.println(out);
  98         return rc;
  99     }


< prev index next >