--- old/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java 2014-11-26 18:38:48.765103338 +0300 +++ new/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java 2014-11-26 18:38:48.441103337 +0300 @@ -49,7 +49,7 @@ private static final String PRINT_FLAGS_FINAL_FORMAT = "%s\\s*:?=\\s*%s"; /** - * Verifies that JVM startup behaviour matches our expectations. + * Verifies that JVM startup behavior matches our expectations. * * @param option an option that should be passed to JVM * @param expectedMessages an array of patterns that should occur @@ -59,17 +59,24 @@ * occur in JVM output. If {@code null} then * JVM output could be empty. * @param exitCode expected exit code. + * @param exitErrorMessage message that will be shown if exit code is not + * as expected. + * @param wrongWarningMessage message that will be shown if warning + * messages are not as expected. * @throws Throwable if verification fails or some other issues occur. */ public static void verifyJVMStartup(String option, String expectedMessages[], String unexpectedMessages[], - ExitCode exitCode) throws Throwable { + ExitCode exitCode, String exitErrorMessage, + String wrongWarningMessage) + throws Throwable { CommandLineOptionTest.verifyJVMStartup(expectedMessages, - unexpectedMessages, exitCode, false, option); + unexpectedMessages, exitCode, exitErrorMessage, + wrongWarningMessage, false, option); } /** - * Verifies that JVM startup behaviour matches our expectations. + * Verifies that JVM startup behavior matches our expectations. * * @param expectedMessages an array of patterns that should occur * in JVM output. If {@code null} then @@ -78,6 +85,10 @@ * occur in JVM output. If {@code null} then * JVM output could be empty. * @param exitCode expected exit code. + * @param exitErrorMessage message that will be shown if exit code is not + * as expected. + * @param wrongWarningMessage message that will be shown if warning + * messages are not as expected. * @param addTestVMOptions if {@code true} then test VM options will be * passed to VM. * @param options options that should be passed to VM in addition to mode @@ -85,8 +96,10 @@ * @throws Throwable if verification fails or some other issues occur. */ public static void verifyJVMStartup(String expectedMessages[], - String unexpectedMessages[], ExitCode exitCode, - boolean addTestVMOptions, String... options) throws Throwable { + String unexpectedMessages[], ExitCode exitCode, + String exitErrorMessage, String wrongWarningMessage, + boolean addTestVMOptions, String... options) + throws Throwable { List finalOptions = new ArrayList<>(); if (addTestVMOptions) { Collections.addAll(finalOptions, Utils.getTestJavaOpts()); @@ -99,23 +112,46 @@ new String[finalOptions.size()])); OutputAnalyzer outputAnalyzer = new OutputAnalyzer(processBuilder.start()); - outputAnalyzer.shouldHaveExitValue(exitCode.value); - if (expectedMessages != null) { + try { + outputAnalyzer.shouldHaveExitValue(exitCode.value); + } catch (RuntimeException e) { + String errorMessage = String.format( + "JVMStartup should have exit value '%d'.%n%s", + exitCode.value, exitErrorMessage); + throw new AssertionError(errorMessage, e); + } + + + if (expectedMessages != null) { for (String expectedMessage : expectedMessages) { - outputAnalyzer.shouldMatch(expectedMessage); + try { + outputAnalyzer.shouldMatch(expectedMessage); + } catch (RuntimeException e) { + String errorMessage = String.format( + "Expected message not found: '%s'.%n%s", + expectedMessage, wrongWarningMessage); + throw new AssertionError(errorMessage, e); + } } } if (unexpectedMessages != null) { for (String unexpectedMessage : unexpectedMessages) { - outputAnalyzer.shouldNotMatch(unexpectedMessage); + try { + outputAnalyzer.shouldNotMatch(unexpectedMessage); + } catch (RuntimeException e) { + String errorMessage = String.format( + "Unexpected message found: '%s'.%n%s", + unexpectedMessage, wrongWarningMessage); + throw new AssertionError(errorMessage, e); + } } } } /** - * Verifies that JVM startup behaviour matches our expectations when type + * Verifies that JVM startup behavior matches our expectations when type * of newly started VM is the same as the type of current. * * @param expectedMessages an array of patterns that should occur @@ -125,19 +161,25 @@ * occur in JVM output. If {@code null} then * JVM output could be empty. * @param exitCode expected exit code. + * @param exitErrorMessage Message that will be shown if exit value is not + * as expected. + * @param wrongWarningMessage message that will be shown if warning + * messages are not as expected. * @param options options that should be passed to VM in addition to mode * flag. * @throws Throwable if verification fails or some other issues occur. */ public static void verifySameJVMStartup(String expectedMessages[], - String unexpectedMessages[], ExitCode exitCode, String... options) - throws Throwable { + String unexpectedMessages[], String exitErrorMessage, + String wrongWarningMessage, ExitCode exitCode, String... options) + throws Throwable { List finalOptions = new ArrayList<>(); finalOptions.add(CommandLineOptionTest.getVMTypeOption()); Collections.addAll(finalOptions, options); CommandLineOptionTest.verifyJVMStartup(expectedMessages, - unexpectedMessages, exitCode, false, + unexpectedMessages, exitCode, exitErrorMessage, + wrongWarningMessage, false, finalOptions.toArray(new String[finalOptions.size()])); } @@ -149,13 +191,17 @@ * * @param optionName a name of tested option. * @param expectedValue expected value of tested option. + * @param optionErrorString message will be shown if option value is not as + * expected. * @param additionalVMOpts additional options that should be * passed to JVM. * @throws Throwable if verification fails or some other issues occur. */ public static void verifyOptionValue(String optionName, - String expectedValue, String... additionalVMOpts) throws Throwable { - verifyOptionValue(optionName, expectedValue, true, additionalVMOpts); + String expectedValue, String optionErrorString, + String... additionalVMOpts) throws Throwable { + verifyOptionValue(optionName, expectedValue, optionErrorString, + true, additionalVMOpts); } /** @@ -168,14 +214,17 @@ * @param expectedValue expected value of tested option. * @param addTestVmOptions if {@code true}, then test VM options * will be used. + * @param optionErrorString message will be shown if option value is not as + * expected. * @param additionalVMOpts additional options that should be * passed to JVM. * @throws Throwable if verification fails or some other issues * occur. */ public static void verifyOptionValue(String optionName, - String expectedValue, boolean addTestVmOptions, - String... additionalVMOpts) throws Throwable { + String expectedValue, String optionErrorString, + boolean addTestVmOptions, String... additionalVMOpts) + throws Throwable { List vmOpts = new ArrayList<>(); if (addTestVmOptions) { @@ -191,10 +240,25 @@ OutputAnalyzer outputAnalyzer = new OutputAnalyzer(processBuilder.start()); - outputAnalyzer.shouldHaveExitValue(0); + try { + outputAnalyzer.shouldHaveExitValue(0); + } catch (RuntimeException e) { + String errorMessage = String.format( + "JVMStartup should be successful with option '%s'", + optionName); + throw new AssertionError(errorMessage, e); + } + try { outputAnalyzer.shouldMatch(String.format( CommandLineOptionTest.PRINT_FLAGS_FINAL_FORMAT, optionName, expectedValue)); + } catch (RuntimeException e) { + String errorMessage = String.format( + "Option '%s' is expected to have '%s' value%n%s", + optionName, expectedValue, + optionErrorString); + throw new AssertionError(errorMessage, e); + } } /** @@ -207,18 +271,21 @@ * * @param optionName name of tested option. * @param expectedValue expected value of tested option. + * @param optionErrorString message to show if option has another value * @param additionalVMOpts additional options that should be * passed to JVM. * @throws Throwable if verification fails or some other issues occur. */ public static void verifyOptionValueForSameVM(String optionName, - String expectedValue, String... additionalVMOpts) throws Throwable { + String expectedValue, String optionErrorString, + String... additionalVMOpts) throws Throwable { List finalOptions = new ArrayList<>(); finalOptions.add(CommandLineOptionTest.getVMTypeOption()); Collections.addAll(finalOptions, additionalVMOpts); CommandLineOptionTest.verifyOptionValue(optionName, expectedValue, - false, finalOptions.toArray(new String[finalOptions.size()])); + optionErrorString, false, + finalOptions.toArray(new String[finalOptions.size()])); } /**