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