531N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
531N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
531N/A *
531N/A * This code is free software; you can redistribute it and/or modify it
531N/A * under the terms of the GNU General Public License version 2 only, as
531N/A * published by the Free Software Foundation.
531N/A *
531N/A * This code is distributed in the hope that it will be useful, but WITHOUT
531N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
531N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
531N/A * version 2 for more details (a copy is included in the LICENSE file that
531N/A * accompanied this code).
531N/A *
531N/A * You should have received a copy of the GNU General Public License version
531N/A * 2 along with this work; if not, write to the Free Software Foundation,
531N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
531N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
531N/A */
531N/A
531N/A/**
531N/A * @test
531N/A * @bug 6356642
531N/A * @summary Verify that extcheck exits appropriately when invalid args are given.
531N/A * @run shell TestExtcheckArgs.sh
531N/A * @author Dave Bristor
531N/A */
531N/A
531N/Aimport java.io.File;
531N/Aimport com.sun.tools.extcheck.Main;
531N/A
531N/A/*
531N/A * Test extcheck by using Runtime.exec instead of invoking
531N/A * com.sun.tools.extcheck.Main.main, since the latter does its own
531N/A * System.exit under the conditions checked here.
531N/A */
531N/Apublic class TestExtcheckArgs {
531N/A public static void realMain(String[] args) throws Throwable {
531N/A String testJar = System.getenv("TESTJAVA") + File.separator
531N/A + "lib" + File.separator + "jconsole.jar";
531N/A
531N/A verify(new String[] {
531N/A }, Main.INSUFFICIENT);
531N/A verify(new String[] {
531N/A "-verbose"
531N/A }, Main.MISSING);
531N/A verify(new String[] {
531N/A "-verbose",
531N/A "foo"
531N/A }, Main.DOES_NOT_EXIST);
531N/A verify(new String[] {
531N/A testJar,
531N/A "bar"
531N/A }, Main.EXTRA);
531N/A verify(new String[] {
531N/A "-verbose",
531N/A testJar,
531N/A "bar"
531N/A }, Main.EXTRA);
531N/A }
531N/A
531N/A static void verify(String[] args, String expected) throws Throwable {
531N/A try {
531N/A Main.realMain(args);
531N/A fail();
531N/A } catch (Exception ex) {
531N/A if (ex.getMessage().startsWith(expected)) {
531N/A pass();
531N/A } else {
531N/A fail("Unexpected message: " + ex.getMessage());
531N/A }
531N/A }
531N/A }
531N/A
531N/A //--------------------- Infrastructure ---------------------------
531N/A static volatile int passed = 0, failed = 0;
531N/A static boolean pass() {passed++; return true;}
531N/A static boolean fail() {failed++; Thread.dumpStack(); return false;}
531N/A static boolean fail(String msg) {System.out.println(msg); return fail();}
531N/A static void unexpected(Throwable t) {failed++; t.printStackTrace();}
531N/A static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;}
531N/A static boolean equal(Object x, Object y) {
531N/A if (x == null ? y == null : x.equals(y)) return pass();
531N/A else return fail(x + " not equal to " + y);}
531N/A public static void main(String[] args) throws Throwable {
531N/A try {realMain(args);} catch (Throwable t) {unexpected(t);}
531N/A System.out.println("\nPassed = " + passed + " failed = " + failed);
531N/A if (failed > 0) throw new AssertionError("Some tests failed");}
531N/A}