Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/tools/extcheck/TestExtcheckArgs.java
38855 views
/*1* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 635664226* @summary Verify that extcheck exits appropriately when invalid args are given.27* @run shell TestExtcheckArgs.sh28* @author Dave Bristor29*/3031import java.io.File;32import com.sun.tools.extcheck.Main;3334/*35* Test extcheck by using Runtime.exec instead of invoking36* com.sun.tools.extcheck.Main.main, since the latter does its own37* System.exit under the conditions checked here.38*/39public class TestExtcheckArgs {40public static void realMain(String[] args) throws Throwable {41String testJar = System.getenv("TESTJAVA") + File.separator42+ "lib" + File.separator + "jconsole.jar";4344verify(new String[] {45}, Main.INSUFFICIENT);46verify(new String[] {47"-verbose"48}, Main.MISSING);49verify(new String[] {50"-verbose",51"foo"52}, Main.DOES_NOT_EXIST);53verify(new String[] {54testJar,55"bar"56}, Main.EXTRA);57verify(new String[] {58"-verbose",59testJar,60"bar"61}, Main.EXTRA);62}6364static void verify(String[] args, String expected) throws Throwable {65try {66Main.realMain(args);67fail();68} catch (Exception ex) {69if (ex.getMessage().startsWith(expected)) {70pass();71} else {72fail("Unexpected message: " + ex.getMessage());73}74}75}7677//--------------------- Infrastructure ---------------------------78static volatile int passed = 0, failed = 0;79static boolean pass() {passed++; return true;}80static boolean fail() {failed++; Thread.dumpStack(); return false;}81static boolean fail(String msg) {System.out.println(msg); return fail();}82static void unexpected(Throwable t) {failed++; t.printStackTrace();}83static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;}84static boolean equal(Object x, Object y) {85if (x == null ? y == null : x.equals(y)) return pass();86else return fail(x + " not equal to " + y);}87public static void main(String[] args) throws Throwable {88try {realMain(args);} catch (Throwable t) {unexpected(t);}89System.out.println("\nPassed = " + passed + " failed = " + failed);90if (failed > 0) throw new AssertionError("Some tests failed");}91}929394