Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/lib/testlibrary/OutputAnalyzerTest.java
38833 views
/*1* Copyright (c) 2013, 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* @summary Test the OutputAnalyzer utility class26*/2728import jdk.testlibrary.OutputAnalyzer;2930public class OutputAnalyzerTest {3132public static void main(String args[]) throws Exception {3334String stdout = "aaaaaa";35String stderr = "bbbbbb";36String nonExistingString = "cccc";3738OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);3940if (!stdout.equals(output.getStdout())) {41throw new Exception("getStdout() returned '" + output.getStdout()42+ "', expected '" + stdout + "'");43}4445if (!stderr.equals(output.getStderr())) {46throw new Exception("getStderr() returned '" + output.getStderr()47+ "', expected '" + stderr + "'");48}4950try {51output.shouldContain(stdout);52output.stdoutShouldContain(stdout);53output.shouldContain(stderr);54output.stderrShouldContain(stderr);55} catch (RuntimeException e) {56throw new Exception("shouldContain() failed", e);57}5859try {60output.shouldContain(nonExistingString);61throw new Exception("shouldContain() failed to throw exception");62} catch (RuntimeException e) {63// expected64}6566try {67output.stdoutShouldContain(stderr);68throw new Exception(69"stdoutShouldContain() failed to throw exception");70} catch (RuntimeException e) {71// expected72}7374try {75output.stderrShouldContain(stdout);76throw new Exception(77"stdoutShouldContain() failed to throw exception");78} catch (RuntimeException e) {79// expected80}8182try {83output.shouldNotContain(nonExistingString);84output.stdoutShouldNotContain(nonExistingString);85output.stderrShouldNotContain(nonExistingString);86} catch (RuntimeException e) {87throw new Exception("shouldNotContain() failed", e);88}8990try {91output.shouldNotContain(stdout);92throw new Exception("shouldContain() failed to throw exception");93} catch (RuntimeException e) {94// expected95}9697try {98output.stdoutShouldNotContain(stdout);99throw new Exception("shouldContain() failed to throw exception");100} catch (RuntimeException e) {101// expected102}103104try {105output.stderrShouldNotContain(stderr);106throw new Exception("shouldContain() failed to throw exception");107} catch (RuntimeException e) {108// expected109}110111String stdoutPattern = "[a]";112String stderrPattern = "[b]";113String nonExistingPattern = "[c]";114115// Should match116try {117output.shouldMatch(stdoutPattern);118output.stdoutShouldMatch(stdoutPattern);119output.shouldMatch(stderrPattern);120output.stderrShouldMatch(stderrPattern);121} catch (RuntimeException e) {122throw new Exception("shouldMatch() failed", e);123}124125try {126output.shouldMatch(nonExistingPattern);127throw new Exception("shouldMatch() failed to throw exception");128} catch (RuntimeException e) {129// expected130}131132try {133output.stdoutShouldMatch(stderrPattern);134throw new Exception(135"stdoutShouldMatch() failed to throw exception");136} catch (RuntimeException e) {137// expected138}139140try {141output.stderrShouldMatch(stdoutPattern);142throw new Exception(143"stderrShouldMatch() failed to throw exception");144} catch (RuntimeException e) {145// expected146}147148// Should not match149try {150output.shouldNotMatch(nonExistingPattern);151output.stdoutShouldNotMatch(nonExistingPattern);152output.stderrShouldNotMatch(nonExistingPattern);153} catch (RuntimeException e) {154throw new Exception("shouldNotMatch() failed", e);155}156157try {158output.shouldNotMatch(stdoutPattern);159throw new Exception("shouldNotMatch() failed to throw exception");160} catch (RuntimeException e) {161// expected162}163164try {165output.stdoutShouldNotMatch(stdoutPattern);166throw new Exception("shouldNotMatch() failed to throw exception");167} catch (RuntimeException e) {168// expected169}170171try {172output.stderrShouldNotMatch(stderrPattern);173throw new Exception("shouldNotMatch() failed to throw exception");174} catch (RuntimeException e) {175// expected176}177}178179}180181182