Path: blob/master/test/jdk/tools/launcher/8261785/Test8261785.java
41149 views
/*1* Copyright (c) 2021, 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*/2223import java.io.IOException;24import java.nio.file.Files;25import java.nio.file.Path;26import java.nio.file.Paths;27import org.testng.annotations.Test;28import static org.testng.Assert.assertEquals;29import static org.testng.Assert.assertTrue;3031/*32* @test33* @bug 826178534* @summary Test static main methods in anonymous/local class won't cause launcher crash35* @modules jdk.compiler jdk.zipfs36* @compile ../TestHelper.java37* @run testng Test826178538*/39public class Test8261785 {40private final Path inputDir;4142public Test8261785() {43inputDir = Paths.get(System.getProperty("test.src", "."));44}4546public void compile() {47Path file = inputDir.resolve("CrashTheJVM.java");48TestHelper.compile("-d", ".", file.toAbsolutePath().toString());49}5051@Test52public void run() throws IOException {53System.out.println("Current folder: " + Paths.get(".").toAbsolutePath().toString());54compile();55String[] clz = Files.list(Paths.get("."))56.peek(p -> System.out.println("Found " + p.toString()))57.map(Path::getFileName)58.map(Path::toString)59.filter(f -> f.endsWith(".class"))60.map(f -> f.substring(0, f.length() - 6))61.toArray(String[]::new);62assertEquals(clz.length, 8);63for (String f: clz) {64System.out.println("Running class " + f);65var result = TestHelper.doExec(TestHelper.javaCmd, "-cp", ".", f);66assertTrue(result.isOK());67};68}69}707172