Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javac/6917288/GraphicalInstallerTest.java
38813 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/* @test25* @bug 691728826* @summary Unnamed nested class is not generated27*/2829import java.io.*;30import java.util.*;3132public class GraphicalInstallerTest {33public static void main(String... args) throws Exception {34new GraphicalInstallerTest().run();35}3637void run() throws Exception {38File testSrc = new File(System.getProperty("test.src"));39File classes = new File("classes");40classes.mkdirs();41List<String> opts = Arrays.asList("-d", classes.getPath());42int rc = compile(opts, new File(testSrc, "GraphicalInstaller.java"));43if (rc != 0) {44error("compilation failed: rc=" + rc);45return;46}4748check(classes,49"GraphicalInstaller$1.class",50"GraphicalInstaller$1X$1.class",51"GraphicalInstaller$1X.class",52"GraphicalInstaller$BackgroundInstaller.class",53"GraphicalInstaller.class");5455if (errors > 0)56throw new Exception(errors + " errors occurred");57}5859/**60* Compile files with given options.61* Display any output from compiler, and return javac return code.62*/63int compile(List<String> opts, File... files) {64List<String> args = new ArrayList<String>();65args.addAll(opts);66for (File f: files)67args.add(f.getPath());68StringWriter sw = new StringWriter();69PrintWriter pw = new PrintWriter(sw);70int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw);71pw.close();72String out = sw.toString();73if (out.length() > 0)74System.err.println(out);75return rc;76}7778/**79* Check that a directory contains the expected files.80*/81void check(File dir, String... paths) {82Set<String> found = new TreeSet<String>(Arrays.asList(dir.list()));83Set<String> expect = new TreeSet<String>(Arrays.asList(paths));84if (found.equals(expect))85return;86for (String f: found) {87if (!expect.contains(f))88error("Unexpected file found: " + f);89}90for (String e: expect) {91if (!found.contains(e))92error("Expected file not found: " + e);93}94}9596/**97* Record an error message.98*/99void error(String msg) {100System.err.println(msg);101errors++;102}103104int errors;105}106107108