Path: blob/master/test/langtools/jdk/javadoc/tool/ReleaseOption.java
40957 views
/*1* Copyright (c) 2015, 2017, 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.File;24import java.io.PrintWriter;25import java.io.StringWriter;26import java.util.ArrayList;27import java.util.Arrays;28import java.util.List;29import java.util.function.Predicate;3031import jdk.javadoc.internal.tool.Main;32import jdk.javadoc.internal.tool.Main.Result;3334import static jdk.javadoc.internal.tool.Main.Result.*;3536/**37* @test38* @bug 808673739* @summary Test --release option in javadoc40* @run main ReleaseOption41* @modules jdk.javadoc/jdk.javadoc.internal.tool42*/43public class ReleaseOption {44public static void main(String... args) {45new ReleaseOption().run();46}4748void run() {49doRunTest(ERROR, out -> out.contains("compiler.err.doesnt.exist: java.util.stream"), "--release", "7");50doRunTest(OK, out -> !out.contains("compiler.err.doesnt.exist: java.util.stream"), "--release", "8");51doRunTest(CMDERR, out -> true, "--release", "7", "-source", "7");52doRunTest(CMDERR, out -> true, "--release", "7", "-bootclasspath", "any");53}5455void doRunTest(Result expectedResult, Predicate<String> validate, String... args) {56System.err.println("running with args: " + Arrays.asList(args));57List<String> options = new ArrayList<>();58options.addAll(Arrays.asList(args));59options.add("-XDrawDiagnostics");60options.add(new File(System.getProperty("test.src", "."), "ReleaseOptionSource.java").getPath());61StringWriter out = new StringWriter();62PrintWriter pw = new PrintWriter(out);63int actualResult = Main.execute(options.toArray(new String[0]), pw);64System.err.println("actual result=" + actualResult);65System.err.println("actual output=" + out.toString());66if (actualResult != expectedResult.exitCode)67throw new Error("Exit code not as expected");68if (!validate.test(out.toString())) {69throw new Error("Output not as expected");70}71}72}737475