Thu, 26 Sep 2013 06:34:10 -0700
Merge
ctornqvi@4501 | 1 | /* |
ctornqvi@4501 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
ctornqvi@4501 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ctornqvi@4501 | 4 | * |
ctornqvi@4501 | 5 | * This code is free software; you can redistribute it and/or modify it |
ctornqvi@4501 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ctornqvi@4501 | 7 | * published by the Free Software Foundation. |
ctornqvi@4501 | 8 | * |
ctornqvi@4501 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ctornqvi@4501 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ctornqvi@4501 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ctornqvi@4501 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ctornqvi@4501 | 13 | * accompanied this code). |
ctornqvi@4501 | 14 | * |
ctornqvi@4501 | 15 | * You should have received a copy of the GNU General Public License version |
ctornqvi@4501 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ctornqvi@4501 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ctornqvi@4501 | 18 | * |
ctornqvi@4501 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ctornqvi@4501 | 20 | * or visit www.oracle.com if you need additional information or have any |
ctornqvi@4501 | 21 | * questions. |
ctornqvi@4501 | 22 | */ |
ctornqvi@4501 | 23 | |
ctornqvi@4501 | 24 | /* |
ctornqvi@4501 | 25 | * @test |
ctornqvi@4501 | 26 | * @summary Test the OutputAnalyzer utility class |
ctornqvi@4501 | 27 | * @library /testlibrary |
ctornqvi@4501 | 28 | */ |
ctornqvi@4501 | 29 | |
ctornqvi@4501 | 30 | import com.oracle.java.testlibrary.OutputAnalyzer; |
ctornqvi@4501 | 31 | |
ctornqvi@4501 | 32 | public class OutputAnalyzerTest { |
ctornqvi@4501 | 33 | |
ctornqvi@4501 | 34 | public static void main(String args[]) throws Exception { |
ctornqvi@4501 | 35 | |
ctornqvi@4501 | 36 | String stdout = "aaaaaa"; |
ctornqvi@4501 | 37 | String stderr = "bbbbbb"; |
ctornqvi@4501 | 38 | |
ctornqvi@4885 | 39 | // Regexps used for testing pattern matching of the test input |
ctornqvi@4885 | 40 | String stdoutPattern = "[a]"; |
ctornqvi@4885 | 41 | String stderrPattern = "[b]"; |
ctornqvi@4885 | 42 | String nonExistingPattern = "[c]"; |
ctornqvi@4885 | 43 | |
ctornqvi@4501 | 44 | OutputAnalyzer output = new OutputAnalyzer(stdout, stderr); |
ctornqvi@4501 | 45 | |
ctornqvi@4501 | 46 | if (!stdout.equals(output.getStdout())) { |
ctornqvi@4501 | 47 | throw new Exception("getStdout() returned '" + output.getStdout() + "', expected '" + stdout + "'"); |
ctornqvi@4501 | 48 | } |
ctornqvi@4501 | 49 | |
ctornqvi@4501 | 50 | if (!stderr.equals(output.getStderr())) { |
ctornqvi@4501 | 51 | throw new Exception("getStderr() returned '" + output.getStderr() + "', expected '" + stderr + "'"); |
ctornqvi@4501 | 52 | } |
ctornqvi@4501 | 53 | |
ctornqvi@4501 | 54 | try { |
ctornqvi@4501 | 55 | output.shouldContain(stdout); |
ctornqvi@4501 | 56 | output.stdoutShouldContain(stdout); |
ctornqvi@4501 | 57 | output.shouldContain(stderr); |
ctornqvi@4501 | 58 | output.stderrShouldContain(stderr); |
ctornqvi@4501 | 59 | } catch (RuntimeException e) { |
ctornqvi@4501 | 60 | throw new Exception("shouldContain() failed", e); |
ctornqvi@4501 | 61 | } |
ctornqvi@4501 | 62 | |
ctornqvi@4501 | 63 | try { |
ctornqvi@4501 | 64 | output.shouldContain("cccc"); |
ctornqvi@4501 | 65 | throw new Exception("shouldContain() failed to throw exception"); |
ctornqvi@4501 | 66 | } catch (RuntimeException e) { |
ctornqvi@4501 | 67 | // expected |
ctornqvi@4501 | 68 | } |
ctornqvi@4501 | 69 | |
ctornqvi@4501 | 70 | try { |
ctornqvi@4501 | 71 | output.stdoutShouldContain(stderr); |
ctornqvi@4501 | 72 | throw new Exception("stdoutShouldContain() failed to throw exception"); |
ctornqvi@4501 | 73 | } catch (RuntimeException e) { |
ctornqvi@4501 | 74 | // expected |
ctornqvi@4501 | 75 | } |
ctornqvi@4501 | 76 | |
ctornqvi@4501 | 77 | try { |
ctornqvi@4501 | 78 | output.stderrShouldContain(stdout); |
ctornqvi@4501 | 79 | throw new Exception("stdoutShouldContain() failed to throw exception"); |
ctornqvi@4501 | 80 | } catch (RuntimeException e) { |
ctornqvi@4501 | 81 | // expected |
ctornqvi@4501 | 82 | } |
ctornqvi@4501 | 83 | |
ctornqvi@4501 | 84 | try { |
ctornqvi@4501 | 85 | output.shouldNotContain("cccc"); |
ctornqvi@4501 | 86 | output.stdoutShouldNotContain("cccc"); |
ctornqvi@4501 | 87 | output.stderrShouldNotContain("cccc"); |
ctornqvi@4501 | 88 | } catch (RuntimeException e) { |
ctornqvi@4501 | 89 | throw new Exception("shouldNotContain() failed", e); |
ctornqvi@4501 | 90 | } |
ctornqvi@4501 | 91 | |
ctornqvi@4501 | 92 | try { |
ctornqvi@4501 | 93 | output.shouldNotContain(stdout); |
ctornqvi@4501 | 94 | throw new Exception("shouldContain() failed to throw exception"); |
ctornqvi@4501 | 95 | } catch (RuntimeException e) { |
ctornqvi@4501 | 96 | // expected |
ctornqvi@4501 | 97 | } |
ctornqvi@4501 | 98 | |
ctornqvi@4501 | 99 | try { |
ctornqvi@4501 | 100 | output.stdoutShouldNotContain(stdout); |
ctornqvi@4501 | 101 | throw new Exception("shouldContain() failed to throw exception"); |
ctornqvi@4501 | 102 | } catch (RuntimeException e) { |
ctornqvi@4501 | 103 | // expected |
ctornqvi@4501 | 104 | } |
ctornqvi@4501 | 105 | |
ctornqvi@4501 | 106 | try { |
ctornqvi@4885 | 107 | output.stderrShouldNotContain(stderr); |
ctornqvi@4885 | 108 | throw new Exception("shouldContain() failed to throw exception"); |
ctornqvi@4501 | 109 | } catch (RuntimeException e) { |
ctornqvi@4885 | 110 | // expected |
ctornqvi@4885 | 111 | } |
ctornqvi@4885 | 112 | |
ctornqvi@4885 | 113 | // Should match |
ctornqvi@4885 | 114 | try { |
ctornqvi@4885 | 115 | output.shouldMatch(stdoutPattern); |
ctornqvi@4885 | 116 | output.stdoutShouldMatch(stdoutPattern); |
ctornqvi@4885 | 117 | output.shouldMatch(stderrPattern); |
ctornqvi@4885 | 118 | output.stderrShouldMatch(stderrPattern); |
ctornqvi@4885 | 119 | } catch (RuntimeException e) { |
ctornqvi@4885 | 120 | throw new Exception("shouldMatch() failed", e); |
ctornqvi@4885 | 121 | } |
ctornqvi@4885 | 122 | |
ctornqvi@4885 | 123 | try { |
ctornqvi@4885 | 124 | output.shouldMatch(nonExistingPattern); |
ctornqvi@4885 | 125 | throw new Exception("shouldMatch() failed to throw exception"); |
ctornqvi@4885 | 126 | } catch (RuntimeException e) { |
ctornqvi@4885 | 127 | // expected |
ctornqvi@4885 | 128 | } |
ctornqvi@4885 | 129 | |
ctornqvi@4885 | 130 | try { |
ctornqvi@4885 | 131 | output.stdoutShouldMatch(stderrPattern); |
ctornqvi@4885 | 132 | throw new Exception( |
ctornqvi@4885 | 133 | "stdoutShouldMatch() failed to throw exception"); |
ctornqvi@4885 | 134 | } catch (RuntimeException e) { |
ctornqvi@4885 | 135 | // expected |
ctornqvi@4885 | 136 | } |
ctornqvi@4885 | 137 | |
ctornqvi@4885 | 138 | try { |
ctornqvi@4885 | 139 | output.stderrShouldMatch(stdoutPattern); |
ctornqvi@4885 | 140 | throw new Exception( |
ctornqvi@4885 | 141 | "stderrShouldMatch() failed to throw exception"); |
ctornqvi@4885 | 142 | } catch (RuntimeException e) { |
ctornqvi@4885 | 143 | // expected |
ctornqvi@4885 | 144 | } |
ctornqvi@4885 | 145 | |
ctornqvi@4885 | 146 | // Should not match |
ctornqvi@4885 | 147 | try { |
ctornqvi@4885 | 148 | output.shouldNotMatch(nonExistingPattern); |
ctornqvi@4885 | 149 | output.stdoutShouldNotMatch(nonExistingPattern); |
ctornqvi@4885 | 150 | output.stderrShouldNotMatch(nonExistingPattern); |
ctornqvi@4885 | 151 | } catch (RuntimeException e) { |
ctornqvi@4885 | 152 | throw new Exception("shouldNotMatch() failed", e); |
ctornqvi@4885 | 153 | } |
ctornqvi@4885 | 154 | |
ctornqvi@4885 | 155 | try { |
ctornqvi@4885 | 156 | output.shouldNotMatch(stdoutPattern); |
ctornqvi@4885 | 157 | throw new Exception("shouldNotMatch() failed to throw exception"); |
ctornqvi@4885 | 158 | } catch (RuntimeException e) { |
ctornqvi@4885 | 159 | // expected |
ctornqvi@4885 | 160 | } |
ctornqvi@4885 | 161 | |
ctornqvi@4885 | 162 | try { |
ctornqvi@4885 | 163 | output.stdoutShouldNotMatch(stdoutPattern); |
ctornqvi@4885 | 164 | throw new Exception("shouldNotMatch() failed to throw exception"); |
ctornqvi@4885 | 165 | } catch (RuntimeException e) { |
ctornqvi@4885 | 166 | // expected |
ctornqvi@4885 | 167 | } |
ctornqvi@4885 | 168 | |
ctornqvi@4885 | 169 | try { |
ctornqvi@4885 | 170 | output.stderrShouldNotMatch(stderrPattern); |
ctornqvi@4885 | 171 | throw new Exception("shouldNotMatch() failed to throw exception"); |
ctornqvi@4885 | 172 | } catch (RuntimeException e) { |
ctornqvi@4885 | 173 | // expected |
ctornqvi@4501 | 174 | } |
stefank@5706 | 175 | |
stefank@5706 | 176 | { |
stefank@5706 | 177 | String aaaa = "aaaa"; |
stefank@5706 | 178 | String result = output.firstMatch(aaaa); |
stefank@5706 | 179 | if (!aaaa.equals(result)) { |
stefank@5706 | 180 | throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result); |
stefank@5706 | 181 | } |
stefank@5706 | 182 | } |
stefank@5706 | 183 | |
stefank@5706 | 184 | { |
stefank@5706 | 185 | String aa = "aa"; |
stefank@5706 | 186 | String aa_grouped_aa = aa + "(" + aa + ")"; |
stefank@5706 | 187 | String result = output.firstMatch(aa_grouped_aa, 1); |
stefank@5706 | 188 | if (!aa.equals(result)) { |
stefank@5706 | 189 | throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result); |
stefank@5706 | 190 | } |
stefank@5706 | 191 | } |
ctornqvi@4501 | 192 | } |
ctornqvi@4501 | 193 | } |