< prev index next >

test/langtools/jdk/jshell/StartOptionTest.java

Print this page
rev 48495 : 8189102: All tools should support -?, -h and --help
Reviewed-by: kvn, jjg, weijun, alanb, rfield, ksrini
   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  */


 197     protected void setIn(String s) {
 198         cmdInStream = new ByteArrayInputStream(s.getBytes());
 199     }
 200 
 201     // Test load files
 202     public void testCommandFile() {
 203         String fn = writeToFile("String str = \"Hello \"\n" +
 204                 "/list\n" +
 205                 "System.out.println(str + str)\n" +
 206                 "/exit\n");
 207         startExCoUoCeCn(0,
 208                 "1 : String str = \"Hello \";\n",
 209                 "Hello Hello",
 210                 null,
 211                 null,
 212                 "--no-startup", fn, "-s");
 213     }
 214 
 215     // Test that the usage message is printed
 216     public void testUsage() {
 217         for (String opt : new String[]{"-h", "--help"}) {
 218             startCo(s -> {
 219                 assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
 220                 assertTrue(s.startsWith("Usage:   jshell <option>..."), "Unexpect usage start: " + s);
 221                 assertTrue(s.contains("--show-version"), "Expected help: " + s);
 222                 assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
 223             }, opt);
 224         }
 225     }
 226 
 227     // Test the --help-extra message
 228     public void testHelpExtra() {
 229         for (String opt : new String[]{"-X", "--help-extra"}) {
 230             startCo(s -> {
 231                 assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s);
 232                 assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s);
 233                 assertTrue(s.contains("--execution"), "Expected --add-exports: " + s);
 234                 assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
 235             }, opt);
 236         }
 237     }


   1 /*
   2  * Copyright (c) 2015, 2018, 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  */


 197     protected void setIn(String s) {
 198         cmdInStream = new ByteArrayInputStream(s.getBytes());
 199     }
 200 
 201     // Test load files
 202     public void testCommandFile() {
 203         String fn = writeToFile("String str = \"Hello \"\n" +
 204                 "/list\n" +
 205                 "System.out.println(str + str)\n" +
 206                 "/exit\n");
 207         startExCoUoCeCn(0,
 208                 "1 : String str = \"Hello \";\n",
 209                 "Hello Hello",
 210                 null,
 211                 null,
 212                 "--no-startup", fn, "-s");
 213     }
 214 
 215     // Test that the usage message is printed
 216     public void testUsage() {
 217         for (String opt : new String[]{"-?", "-h", "--help"}) {
 218             startCo(s -> {
 219                 assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
 220                 assertTrue(s.startsWith("Usage:   jshell <option>..."), "Unexpect usage start: " + s);
 221                 assertTrue(s.contains("--show-version"), "Expected help: " + s);
 222                 assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
 223             }, opt);
 224         }
 225     }
 226 
 227     // Test the --help-extra message
 228     public void testHelpExtra() {
 229         for (String opt : new String[]{"-X", "--help-extra"}) {
 230             startCo(s -> {
 231                 assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s);
 232                 assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s);
 233                 assertTrue(s.contains("--execution"), "Expected --add-exports: " + s);
 234                 assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
 235             }, opt);
 236         }
 237     }


< prev index next >