test/jdk/tools/jpackage/share/HelpTest.java
branchJDK-8200758-branch
changeset 58648 3bf53ffa9ae7
parent 58647 2c43b89b1679
child 58670 6fb9e12d5595
equal deleted inserted replaced
58647:2c43b89b1679 58648:3bf53ffa9ae7
     1 /*
       
     2  * Copyright (c) 2018, 2019, 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 
       
    24  /*
       
    25  * @test
       
    26  * @summary jpackage help test
       
    27  * @library ../helpers
       
    28  * @build JPackageHelper
       
    29  * @build JPackagePath
       
    30  * @modules jdk.jpackage
       
    31  * @run main/othervm -Xmx512m HelpTest
       
    32  */
       
    33 public class HelpTest {
       
    34 
       
    35     // Platform specific help messages.
       
    36     private static final String WINDOWS_HELP =
       
    37             "--win-dir-chooser";
       
    38     private static final String OSX_HELP =
       
    39             "--mac-package-identifier";
       
    40     private static final String LINUX_HELP =
       
    41             "--linux-package-name";
       
    42 
       
    43     private static void validate(String output1, String output2)
       
    44             throws Exception {
       
    45         if (output1.split("\n").length < 25) {
       
    46             throw new AssertionError("jpacakger --help failed");
       
    47         }
       
    48 
       
    49         if (output2.split("\n").length < 25) {
       
    50             throw new AssertionError("jpacakger -h failed");
       
    51         }
       
    52 
       
    53         // Make sure output matches for --help and -h
       
    54         if (!output1.equals(output2)) {
       
    55             System.err.println("================= --help =================");
       
    56             System.err.println(output1);
       
    57 
       
    58             System.err.println("=================== -h ===================");
       
    59             System.err.println(output2);
       
    60 
       
    61             throw new AssertionError(
       
    62                     "jpacakger help text does not match between --help and -h");
       
    63         }
       
    64 
       
    65         if (JPackageHelper.isWindows()) {
       
    66             if (!output1.contains(WINDOWS_HELP)) {
       
    67                 throw new AssertionError(
       
    68                   "jpacakger help text missing Windows specific help");
       
    69             }
       
    70 
       
    71             if (output1.contains(OSX_HELP) || output1.contains(LINUX_HELP)) {
       
    72                 throw new AssertionError(
       
    73                   "jpacakger help text contains other platforms specific help");
       
    74 
       
    75             }
       
    76         } else if (JPackageHelper.isOSX()) {
       
    77             if (!output1.contains(OSX_HELP)) {
       
    78                 throw new AssertionError(
       
    79                   "jpacakger help text missing OS X specific help");
       
    80             }
       
    81 
       
    82             if (output1.contains(WINDOWS_HELP) ||
       
    83                     output1.contains(LINUX_HELP)) {
       
    84                 throw new AssertionError(
       
    85                  "jpacakger help text contains other platforms specific help");
       
    86             }
       
    87         } else if (JPackageHelper.isLinux()) {
       
    88             if (!output1.contains(LINUX_HELP)) {
       
    89                 throw new AssertionError(
       
    90                   "jpacakger help text missing Linux specific help");
       
    91             }
       
    92 
       
    93             if (output1.contains(OSX_HELP) || output1.contains(WINDOWS_HELP)) {
       
    94                 throw new AssertionError(
       
    95                   "jpacakger help text contains other platforms specific help");
       
    96             }
       
    97         }
       
    98     }
       
    99 
       
   100     private static void testHelp() throws Exception {
       
   101         String output1 = JPackageHelper.executeCLI(true, "--help");
       
   102         String output2 = JPackageHelper.executeCLI(true, "-h");
       
   103         validate(output1, output2);
       
   104     }
       
   105 
       
   106     private static void testHelpToolProvider() throws Exception {
       
   107         String output1 = JPackageHelper.executeToolProvider(true, "--help");
       
   108         String output2 = JPackageHelper.executeToolProvider(true, "-h");
       
   109         validate(output1, output2);
       
   110     }
       
   111 
       
   112     public static void main(String[] args) throws Exception {
       
   113         testHelp();
       
   114         testHelpToolProvider();
       
   115     }
       
   116 
       
   117 }