test/com/sun/tools/extcheck/TestExtcheckArgs.java

Print this page




   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  * @bug 6356642
  27  * @summary Verify that extcheck exits appropriately when invalid args are given.
  28  * @run shell TestExtcheckArgs.sh
  29  * @author Dave Bristor
  30  */
  31 
  32 import java.io.File;
  33 import com.sun.tools.extcheck.Main;
  34 
  35 /*
  36  * Test extcheck by using Runtime.exec instead of invoking
  37  * com.sun.tools.extcheck.Main.main, since the latter does its own
  38  * System.exit under the conditions checked here.
  39  */
  40 public class TestExtcheckArgs {
  41     public static void realMain(String[] args) throws Throwable {
  42         String testJar = System.getenv("TESTJAVA") + File.separator
  43             + "lib" + File.separator + "jconsole.jar";
  44 
  45         verify(new String[] {
  46                }, Main.INSUFFICIENT);
  47         verify(new String[] {
  48                    "-verbose"
  49                }, Main.MISSING);
  50         verify(new String[] {
  51                    "-verbose",
  52                    "foo"
  53                }, Main.DOES_NOT_EXIST);
  54         verify(new String[] {
  55                    testJar,
  56                    "bar"
  57                }, Main.EXTRA);
  58         verify(new String[] {
  59                    "-verbose",
  60                    testJar,
  61                    "bar"
  62                }, Main.EXTRA);





  63     }
  64 
  65     static void verify(String[] args, String expected) throws Throwable {
  66         try {
  67             Main.realMain(args);
  68             fail();
  69         } catch (Exception ex) {
  70             if (ex.getMessage().startsWith(expected)) {
  71                 pass();
  72             } else {
  73                 fail("Unexpected message: " + ex.getMessage());
  74             }
  75         }
  76     }
  77 
  78     //--------------------- Infrastructure ---------------------------
  79     static volatile int passed = 0, failed = 0;
  80     static boolean pass() {passed++; return true;}
  81     static boolean fail() {failed++; Thread.dumpStack(); return false;}
  82     static boolean fail(String msg) {System.out.println(msg); return fail();}


   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  * @bug 6356642 6907367
  27  * @summary Verify that extcheck exits appropriately when invalid args are given.
  28  * @run shell TestExtcheckArgs.sh
  29  * @author Dave Bristor
  30  */
  31 
  32 import java.io.File;
  33 import com.sun.tools.extcheck.Main;
  34 
  35 /*
  36  * Test extcheck by using Runtime.exec instead of invoking
  37  * com.sun.tools.extcheck.Main.main, since the latter does its own
  38  * System.exit under the conditions checked here.
  39  */
  40 public class TestExtcheckArgs {
  41     public static void realMain(String[] args) throws Throwable {
  42         String testJar = System.getenv("TESTJAVA") + File.separator
  43             + "lib" + File.separator + "jconsole.jar";
  44 
  45         verify(new String[] {
  46                }, Main.INSUFFICIENT);
  47         verify(new String[] {
  48                    "-verbose"
  49                }, Main.MISSING);
  50         verify(new String[] {
  51                    "-verbose",
  52                    "foo"
  53                }, Main.DOES_NOT_EXIST);
  54         verify(new String[] {
  55                    testJar,
  56                    "bar"
  57                }, Main.EXTRA);
  58         verify(new String[] {
  59                    "-verbose",
  60                    testJar,
  61                    "bar"
  62                }, Main.EXTRA);
  63 
  64         // extcheck rt.jar
  65         // String rtjar = System.getenv("TESTJAVA") + File.separator
  66         //    + "jre" + File.separator + "lib" + File.separator + "rt.jar";
  67         // Main.realMain(new String[] {"-verbose", rtjar});
  68     }
  69 
  70     static void verify(String[] args, String expected) throws Throwable {
  71         try {
  72             Main.realMain(args);
  73             fail();
  74         } catch (Exception ex) {
  75             if (ex.getMessage().startsWith(expected)) {
  76                 pass();
  77             } else {
  78                 fail("Unexpected message: " + ex.getMessage());
  79             }
  80         }
  81     }
  82 
  83     //--------------------- Infrastructure ---------------------------
  84     static volatile int passed = 0, failed = 0;
  85     static boolean pass() {passed++; return true;}
  86     static boolean fail() {failed++; Thread.dumpStack(); return false;}
  87     static boolean fail(String msg) {System.out.println(msg); return fail();}