Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/testlibrary_tests/OutputAnalyzerTest.java
32278 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* @library /testlibrary27*/2829import com.oracle.java.testlibrary.OutputAnalyzer;3031public class OutputAnalyzerTest {3233public static void main(String args[]) throws Exception {3435String stdout = "aaaaaa";36String stderr = "bbbbbb";3738// Regexps used for testing pattern matching of the test input39String stdoutPattern = "[a]";40String stderrPattern = "[b]";41String nonExistingPattern = "[c]";4243OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);4445if (!stdout.equals(output.getStdout())) {46throw new Exception("getStdout() returned '" + output.getStdout() + "', expected '" + stdout + "'");47}4849if (!stderr.equals(output.getStderr())) {50throw new Exception("getStderr() returned '" + output.getStderr() + "', expected '" + stderr + "'");51}5253try {54output.shouldContain(stdout);55output.stdoutShouldContain(stdout);56output.shouldContain(stderr);57output.stderrShouldContain(stderr);58} catch (RuntimeException e) {59throw new Exception("shouldContain() failed", e);60}6162try {63output.shouldContain("cccc");64throw new Exception("shouldContain() failed to throw exception");65} catch (RuntimeException e) {66// expected67}6869try {70output.stdoutShouldContain(stderr);71throw new Exception("stdoutShouldContain() failed to throw exception");72} catch (RuntimeException e) {73// expected74}7576try {77output.stderrShouldContain(stdout);78throw new Exception("stdoutShouldContain() failed to throw exception");79} catch (RuntimeException e) {80// expected81}8283try {84output.shouldNotContain("cccc");85output.stdoutShouldNotContain("cccc");86output.stderrShouldNotContain("cccc");87} catch (RuntimeException e) {88throw new Exception("shouldNotContain() failed", e);89}9091try {92output.shouldNotContain(stdout);93throw new Exception("shouldContain() failed to throw exception");94} catch (RuntimeException e) {95// expected96}9798try {99output.stdoutShouldNotContain(stdout);100throw new Exception("shouldContain() failed to throw exception");101} catch (RuntimeException e) {102// expected103}104105try {106output.stderrShouldNotContain(stderr);107throw new Exception("shouldContain() failed to throw exception");108} catch (RuntimeException e) {109// expected110}111112// Should match113try {114output.shouldMatch(stdoutPattern);115output.stdoutShouldMatch(stdoutPattern);116output.shouldMatch(stderrPattern);117output.stderrShouldMatch(stderrPattern);118} catch (RuntimeException e) {119throw new Exception("shouldMatch() failed", e);120}121122try {123output.shouldMatch(nonExistingPattern);124throw new Exception("shouldMatch() failed to throw exception");125} catch (RuntimeException e) {126// expected127}128129try {130output.stdoutShouldMatch(stderrPattern);131throw new Exception(132"stdoutShouldMatch() failed to throw exception");133} catch (RuntimeException e) {134// expected135}136137try {138output.stderrShouldMatch(stdoutPattern);139throw new Exception(140"stderrShouldMatch() failed to throw exception");141} catch (RuntimeException e) {142// expected143}144145// Should not match146try {147output.shouldNotMatch(nonExistingPattern);148output.stdoutShouldNotMatch(nonExistingPattern);149output.stderrShouldNotMatch(nonExistingPattern);150} catch (RuntimeException e) {151throw new Exception("shouldNotMatch() failed", e);152}153154try {155output.shouldNotMatch(stdoutPattern);156throw new Exception("shouldNotMatch() failed to throw exception");157} catch (RuntimeException e) {158// expected159}160161try {162output.stdoutShouldNotMatch(stdoutPattern);163throw new Exception("shouldNotMatch() failed to throw exception");164} catch (RuntimeException e) {165// expected166}167168try {169output.stderrShouldNotMatch(stderrPattern);170throw new Exception("shouldNotMatch() failed to throw exception");171} catch (RuntimeException e) {172// expected173}174175{176String aaaa = "aaaa";177String result = output.firstMatch(aaaa);178if (!aaaa.equals(result)) {179throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result);180}181}182183{184String aa = "aa";185String aa_grouped_aa = aa + "(" + aa + ")";186String result = output.firstMatch(aa_grouped_aa, 1);187if (!aa.equals(result)) {188throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result);189}190}191}192}193194195