Path: blob/master/test/jdk/tools/lib/tests/Result.java
41152 views
/*1* Copyright (c) 2015, 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*/2223package tests;2425import java.nio.file.Path;2627public class Result {28private final int exitCode;29private final String message;30private final Path imageFile;3132public Result(int exitCode, String message, Path imageFile) {33this.exitCode = exitCode;34this.message = message;35this.imageFile = imageFile;36}3738public int getExitCode() {39return exitCode;40}4142public String getMessage() {43return message;44}4546public Path getFile() {47return imageFile;48}4950public void assertFailure() {51assertFailure(null);52}5354public void assertFailure(String expected) {55if (getExitCode() == 0) {56System.err.println(getMessage());57throw new AssertionError("Failure expected: " + getFile());58}59if (getExitCode() != 1 && getExitCode() != 2) {60System.err.println(getMessage());61throw new AssertionError("Abnormal exit: " + getFile());62}63if (expected != null) {64if (expected.isEmpty()) {65throw new AssertionError("Expected error is empty");66}67if (!getMessage().matches(expected) && !getMessage().contains(expected)) {68System.err.println(getMessage());69throw new AssertionError("Output does not fit regexp: " + expected);70}71}72System.err.println("Failed as expected. " + (expected != null ? expected : ""));73System.err.println(getMessage());74}7576public Path assertSuccess() {77if (getExitCode() != 0) {78System.err.println(getMessage());79throw new AssertionError("Unexpected failure: " + getExitCode());80}81return getFile();82}83}848586