Wed, 25 Sep 2013 17:47:22 +0200
8024677: [TESTBUG] Move tests for classes in /testlibrary
Summary: Moved the tests to /testlibrary_tests and updated TEST.groups
Reviewed-by: dholmes, sla
test/TEST.groups | file | annotate | diff | comparison | revisions | |
test/testlibrary/AssertsTest.java | file | annotate | diff | comparison | revisions | |
test/testlibrary/OutputAnalyzerReportingTest.java | file | annotate | diff | comparison | revisions | |
test/testlibrary/OutputAnalyzerTest.java | file | annotate | diff | comparison | revisions | |
test/testlibrary_tests/AssertsTest.java | file | annotate | diff | comparison | revisions | |
test/testlibrary_tests/OutputAnalyzerReportingTest.java | file | annotate | diff | comparison | revisions | |
test/testlibrary_tests/OutputAnalyzerTest.java | file | annotate | diff | comparison | revisions |
1.1 --- a/test/TEST.groups Wed Sep 25 13:58:13 2013 +0200 1.2 +++ b/test/TEST.groups Wed Sep 25 17:47:22 2013 +0200 1.3 @@ -193,6 +193,7 @@ 1.4 serviceability/ \ 1.5 compiler/ \ 1.6 testlibrary/ \ 1.7 + testlibrary_tests/ \ 1.8 sanity/ \ 1.9 runtime/ \ 1.10 gc/ \
2.1 --- a/test/testlibrary/AssertsTest.java Wed Sep 25 13:58:13 2013 +0200 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,237 +0,0 @@ 2.4 -/* 2.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 - * 2.8 - * This code is free software; you can redistribute it and/or modify it 2.9 - * under the terms of the GNU General Public License version 2 only, as 2.10 - * published by the Free Software Foundation. 2.11 - * 2.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 - * version 2 for more details (a copy is included in the LICENSE file that 2.16 - * accompanied this code). 2.17 - * 2.18 - * You should have received a copy of the GNU General Public License version 2.19 - * 2 along with this work; if not, write to the Free Software Foundation, 2.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 - * 2.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 - * or visit www.oracle.com if you need additional information or have any 2.24 - * questions. 2.25 - */ 2.26 - 2.27 -import static com.oracle.java.testlibrary.Asserts.*; 2.28 - 2.29 -/* @test 2.30 - * @summary Tests the different assertions in the Assert class 2.31 - * @library /testlibrary 2.32 - */ 2.33 -public class AssertsTest { 2.34 - private static class Foo implements Comparable<Foo> { 2.35 - final int id; 2.36 - public Foo(int id) { 2.37 - this.id = id; 2.38 - } 2.39 - 2.40 - public int compareTo(Foo f) { 2.41 - return new Integer(id).compareTo(new Integer(f.id)); 2.42 - } 2.43 - } 2.44 - 2.45 - public static void main(String[] args) throws Exception { 2.46 - testLessThan(); 2.47 - testLessThanOrEqual(); 2.48 - testEquals(); 2.49 - testGreaterThanOrEqual(); 2.50 - testGreaterThan(); 2.51 - testNotEquals(); 2.52 - testNull(); 2.53 - testNotNull(); 2.54 - testTrue(); 2.55 - testFalse(); 2.56 - } 2.57 - 2.58 - private static void testLessThan() throws Exception { 2.59 - expectPass(Assertion.LT, 1, 2); 2.60 - 2.61 - expectFail(Assertion.LT, 2, 2); 2.62 - expectFail(Assertion.LT, 2, 1); 2.63 - expectFail(Assertion.LT, null, 2); 2.64 - expectFail(Assertion.LT, 2, null); 2.65 - } 2.66 - 2.67 - private static void testLessThanOrEqual() throws Exception { 2.68 - expectPass(Assertion.LTE, 1, 2); 2.69 - expectPass(Assertion.LTE, 2, 2); 2.70 - 2.71 - expectFail(Assertion.LTE, 3, 2); 2.72 - expectFail(Assertion.LTE, null, 2); 2.73 - expectFail(Assertion.LTE, 2, null); 2.74 - } 2.75 - 2.76 - private static void testEquals() throws Exception { 2.77 - expectPass(Assertion.EQ, 1, 1); 2.78 - expectPass(Assertion.EQ, null, null); 2.79 - 2.80 - Foo f1 = new Foo(1); 2.81 - expectPass(Assertion.EQ, f1, f1); 2.82 - 2.83 - Foo f2 = new Foo(1); 2.84 - expectFail(Assertion.EQ, f1, f2); 2.85 - expectFail(Assertion.LTE, null, 2); 2.86 - expectFail(Assertion.LTE, 2, null); 2.87 - } 2.88 - 2.89 - private static void testGreaterThanOrEqual() throws Exception { 2.90 - expectPass(Assertion.GTE, 1, 1); 2.91 - expectPass(Assertion.GTE, 2, 1); 2.92 - 2.93 - expectFail(Assertion.GTE, 1, 2); 2.94 - expectFail(Assertion.GTE, null, 2); 2.95 - expectFail(Assertion.GTE, 2, null); 2.96 - } 2.97 - 2.98 - private static void testGreaterThan() throws Exception { 2.99 - expectPass(Assertion.GT, 2, 1); 2.100 - 2.101 - expectFail(Assertion.GT, 1, 1); 2.102 - expectFail(Assertion.GT, 1, 2); 2.103 - expectFail(Assertion.GT, null, 2); 2.104 - expectFail(Assertion.GT, 2, null); 2.105 - } 2.106 - 2.107 - private static void testNotEquals() throws Exception { 2.108 - expectPass(Assertion.NE, null, 1); 2.109 - expectPass(Assertion.NE, 1, null); 2.110 - 2.111 - Foo f1 = new Foo(1); 2.112 - Foo f2 = new Foo(1); 2.113 - expectPass(Assertion.NE, f1, f2); 2.114 - 2.115 - expectFail(Assertion.NE, null, null); 2.116 - expectFail(Assertion.NE, f1, f1); 2.117 - expectFail(Assertion.NE, 1, 1); 2.118 - } 2.119 - 2.120 - private static void testNull() throws Exception { 2.121 - expectPass(Assertion.NULL, null); 2.122 - 2.123 - expectFail(Assertion.NULL, 1); 2.124 - } 2.125 - 2.126 - private static void testNotNull() throws Exception { 2.127 - expectPass(Assertion.NOTNULL, 1); 2.128 - 2.129 - expectFail(Assertion.NOTNULL, null); 2.130 - } 2.131 - 2.132 - private static void testTrue() throws Exception { 2.133 - expectPass(Assertion.TRUE, true); 2.134 - 2.135 - expectFail(Assertion.TRUE, false); 2.136 - } 2.137 - 2.138 - private static void testFalse() throws Exception { 2.139 - expectPass(Assertion.FALSE, false); 2.140 - 2.141 - expectFail(Assertion.FALSE, true); 2.142 - } 2.143 - 2.144 - private static <T extends Comparable<T>> void expectPass(Assertion assertion, T ... args) 2.145 - throws Exception { 2.146 - Assertion.run(assertion, args); 2.147 - } 2.148 - 2.149 - private static <T extends Comparable<T>> void expectFail(Assertion assertion, T ... args) 2.150 - throws Exception { 2.151 - try { 2.152 - Assertion.run(assertion, args); 2.153 - } catch (RuntimeException e) { 2.154 - return; 2.155 - } 2.156 - throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) + 2.157 - " to throw a RuntimeException"); 2.158 - } 2.159 - 2.160 -} 2.161 - 2.162 -enum Assertion { 2.163 - LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE; 2.164 - 2.165 - public static <T extends Comparable<T>> void run(Assertion assertion, T ... args) { 2.166 - String msg = "Expected " + format(assertion, args) + " to pass"; 2.167 - switch (assertion) { 2.168 - case LT: 2.169 - assertLessThan(args[0], args[1], msg); 2.170 - break; 2.171 - case LTE: 2.172 - assertLessThanOrEqual(args[0], args[1], msg); 2.173 - break; 2.174 - case EQ: 2.175 - assertEquals(args[0], args[1], msg); 2.176 - break; 2.177 - case GTE: 2.178 - assertGreaterThanOrEqual(args[0], args[1], msg); 2.179 - break; 2.180 - case GT: 2.181 - assertGreaterThan(args[0], args[1], msg); 2.182 - break; 2.183 - case NE: 2.184 - assertNotEquals(args[0], args[1], msg); 2.185 - break; 2.186 - case NULL: 2.187 - assertNull(args == null ? args : args[0], msg); 2.188 - break; 2.189 - case NOTNULL: 2.190 - assertNotNull(args == null ? args : args[0], msg); 2.191 - break; 2.192 - case FALSE: 2.193 - assertFalse((Boolean) args[0], msg); 2.194 - break; 2.195 - case TRUE: 2.196 - assertTrue((Boolean) args[0], msg); 2.197 - break; 2.198 - default: 2.199 - // do nothing 2.200 - } 2.201 - } 2.202 - 2.203 - public static String format(Assertion assertion, Object ... args) { 2.204 - switch (assertion) { 2.205 - case LT: 2.206 - return asString("assertLessThan", args); 2.207 - case LTE: 2.208 - return asString("assertLessThanOrEqual", args); 2.209 - case EQ: 2.210 - return asString("assertEquals", args); 2.211 - case GTE: 2.212 - return asString("assertGreaterThanOrEquals", args); 2.213 - case GT: 2.214 - return asString("assertGreaterThan", args); 2.215 - case NE: 2.216 - return asString("assertNotEquals", args); 2.217 - case NULL: 2.218 - return asString("assertNull", args); 2.219 - case NOTNULL: 2.220 - return asString("assertNotNull", args); 2.221 - case FALSE: 2.222 - return asString("assertFalse", args); 2.223 - case TRUE: 2.224 - return asString("assertTrue", args); 2.225 - default: 2.226 - return ""; 2.227 - } 2.228 - } 2.229 - 2.230 - private static String asString(String assertion, Object ... args) { 2.231 - if (args == null) { 2.232 - return String.format("%s(null)", assertion); 2.233 - } 2.234 - if (args.length == 1) { 2.235 - return String.format("%s(%s)", assertion, args[0]); 2.236 - } else { 2.237 - return String.format("%s(%s, %s)", assertion, args[0], args[1]); 2.238 - } 2.239 - } 2.240 -}
3.1 --- a/test/testlibrary/OutputAnalyzerReportingTest.java Wed Sep 25 13:58:13 2013 +0200 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,124 +0,0 @@ 3.4 -/* 3.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 - * 3.8 - * This code is free software; you can redistribute it and/or modify it 3.9 - * under the terms of the GNU General Public License version 2 only, as 3.10 - * published by the Free Software Foundation. 3.11 - * 3.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 - * version 2 for more details (a copy is included in the LICENSE file that 3.16 - * accompanied this code). 3.17 - * 3.18 - * You should have received a copy of the GNU General Public License version 3.19 - * 2 along with this work; if not, write to the Free Software Foundation, 3.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 - * 3.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 - * or visit www.oracle.com if you need additional information or have any 3.24 - * questions. 3.25 - */ 3.26 - 3.27 - 3.28 -/* 3.29 - * @test 3.30 - * @summary Test the OutputAnalyzer reporting functionality, 3.31 - * such as printing additional diagnostic info 3.32 - * (exit code, stdout, stderr, command line, etc.) 3.33 - * @library /testlibrary 3.34 - */ 3.35 - 3.36 -import java.io.ByteArrayOutputStream; 3.37 -import java.io.PrintStream; 3.38 - 3.39 -import com.oracle.java.testlibrary.OutputAnalyzer; 3.40 -import com.oracle.java.testlibrary.ProcessTools; 3.41 - 3.42 - 3.43 -public class OutputAnalyzerReportingTest { 3.44 - 3.45 - public static void main(String[] args) throws Exception { 3.46 - // Create the output analyzer under test 3.47 - String stdout = "aaaaaa"; 3.48 - String stderr = "bbbbbb"; 3.49 - OutputAnalyzer output = new OutputAnalyzer(stdout, stderr); 3.50 - 3.51 - // Expected summary values should be the same for all cases, 3.52 - // since the outputAnalyzer object is the same 3.53 - String expectedExitValue = "-1"; 3.54 - String expectedSummary = 3.55 - " stdout: [" + stdout + "];\n" + 3.56 - " stderr: [" + stderr + "]\n" + 3.57 - " exitValue = " + expectedExitValue + "\n"; 3.58 - 3.59 - 3.60 - DiagnosticSummaryTestRunner testRunner = 3.61 - new DiagnosticSummaryTestRunner(); 3.62 - 3.63 - // should have exit value 3.64 - testRunner.init(expectedSummary); 3.65 - int unexpectedExitValue = 2; 3.66 - try { 3.67 - output.shouldHaveExitValue(unexpectedExitValue); 3.68 - } catch (RuntimeException e) { } 3.69 - testRunner.closeAndCheckResults(); 3.70 - 3.71 - // should not contain 3.72 - testRunner.init(expectedSummary); 3.73 - try { 3.74 - output.shouldNotContain(stdout); 3.75 - } catch (RuntimeException e) { } 3.76 - testRunner.closeAndCheckResults(); 3.77 - 3.78 - // should contain 3.79 - testRunner.init(expectedSummary); 3.80 - try { 3.81 - output.shouldContain("unexpected-stuff"); 3.82 - } catch (RuntimeException e) { } 3.83 - testRunner.closeAndCheckResults(); 3.84 - 3.85 - // should not match 3.86 - testRunner.init(expectedSummary); 3.87 - try { 3.88 - output.shouldNotMatch("[a]"); 3.89 - } catch (RuntimeException e) { } 3.90 - testRunner.closeAndCheckResults(); 3.91 - 3.92 - // should match 3.93 - testRunner.init(expectedSummary); 3.94 - try { 3.95 - output.shouldMatch("[qwerty]"); 3.96 - } catch (RuntimeException e) { } 3.97 - testRunner.closeAndCheckResults(); 3.98 - 3.99 - } 3.100 - 3.101 - private static class DiagnosticSummaryTestRunner { 3.102 - private ByteArrayOutputStream byteStream = 3.103 - new ByteArrayOutputStream(10000); 3.104 - 3.105 - private String expectedSummary = ""; 3.106 - private PrintStream errStream; 3.107 - 3.108 - 3.109 - public void init(String expectedSummary) { 3.110 - this.expectedSummary = expectedSummary; 3.111 - byteStream.reset(); 3.112 - errStream = new PrintStream(byteStream); 3.113 - System.setErr(errStream); 3.114 - } 3.115 - 3.116 - public void closeAndCheckResults() { 3.117 - // check results 3.118 - errStream.close(); 3.119 - String stdErrStr = byteStream.toString(); 3.120 - if (!stdErrStr.contains(expectedSummary)) { 3.121 - throw new RuntimeException("The output does not contain " 3.122 - + "the diagnostic message, or the message is incorrect"); 3.123 - } 3.124 - } 3.125 - } 3.126 - 3.127 -}
4.1 --- a/test/testlibrary/OutputAnalyzerTest.java Wed Sep 25 13:58:13 2013 +0200 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,193 +0,0 @@ 4.4 -/* 4.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 4.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 - * 4.8 - * This code is free software; you can redistribute it and/or modify it 4.9 - * under the terms of the GNU General Public License version 2 only, as 4.10 - * published by the Free Software Foundation. 4.11 - * 4.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 - * version 2 for more details (a copy is included in the LICENSE file that 4.16 - * accompanied this code). 4.17 - * 4.18 - * You should have received a copy of the GNU General Public License version 4.19 - * 2 along with this work; if not, write to the Free Software Foundation, 4.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 - * 4.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 - * or visit www.oracle.com if you need additional information or have any 4.24 - * questions. 4.25 - */ 4.26 - 4.27 -/* 4.28 - * @test 4.29 - * @summary Test the OutputAnalyzer utility class 4.30 - * @library /testlibrary 4.31 - */ 4.32 - 4.33 -import com.oracle.java.testlibrary.OutputAnalyzer; 4.34 - 4.35 -public class OutputAnalyzerTest { 4.36 - 4.37 - public static void main(String args[]) throws Exception { 4.38 - 4.39 - String stdout = "aaaaaa"; 4.40 - String stderr = "bbbbbb"; 4.41 - 4.42 - // Regexps used for testing pattern matching of the test input 4.43 - String stdoutPattern = "[a]"; 4.44 - String stderrPattern = "[b]"; 4.45 - String nonExistingPattern = "[c]"; 4.46 - 4.47 - OutputAnalyzer output = new OutputAnalyzer(stdout, stderr); 4.48 - 4.49 - if (!stdout.equals(output.getStdout())) { 4.50 - throw new Exception("getStdout() returned '" + output.getStdout() + "', expected '" + stdout + "'"); 4.51 - } 4.52 - 4.53 - if (!stderr.equals(output.getStderr())) { 4.54 - throw new Exception("getStderr() returned '" + output.getStderr() + "', expected '" + stderr + "'"); 4.55 - } 4.56 - 4.57 - try { 4.58 - output.shouldContain(stdout); 4.59 - output.stdoutShouldContain(stdout); 4.60 - output.shouldContain(stderr); 4.61 - output.stderrShouldContain(stderr); 4.62 - } catch (RuntimeException e) { 4.63 - throw new Exception("shouldContain() failed", e); 4.64 - } 4.65 - 4.66 - try { 4.67 - output.shouldContain("cccc"); 4.68 - throw new Exception("shouldContain() failed to throw exception"); 4.69 - } catch (RuntimeException e) { 4.70 - // expected 4.71 - } 4.72 - 4.73 - try { 4.74 - output.stdoutShouldContain(stderr); 4.75 - throw new Exception("stdoutShouldContain() failed to throw exception"); 4.76 - } catch (RuntimeException e) { 4.77 - // expected 4.78 - } 4.79 - 4.80 - try { 4.81 - output.stderrShouldContain(stdout); 4.82 - throw new Exception("stdoutShouldContain() failed to throw exception"); 4.83 - } catch (RuntimeException e) { 4.84 - // expected 4.85 - } 4.86 - 4.87 - try { 4.88 - output.shouldNotContain("cccc"); 4.89 - output.stdoutShouldNotContain("cccc"); 4.90 - output.stderrShouldNotContain("cccc"); 4.91 - } catch (RuntimeException e) { 4.92 - throw new Exception("shouldNotContain() failed", e); 4.93 - } 4.94 - 4.95 - try { 4.96 - output.shouldNotContain(stdout); 4.97 - throw new Exception("shouldContain() failed to throw exception"); 4.98 - } catch (RuntimeException e) { 4.99 - // expected 4.100 - } 4.101 - 4.102 - try { 4.103 - output.stdoutShouldNotContain(stdout); 4.104 - throw new Exception("shouldContain() failed to throw exception"); 4.105 - } catch (RuntimeException e) { 4.106 - // expected 4.107 - } 4.108 - 4.109 - try { 4.110 - output.stderrShouldNotContain(stderr); 4.111 - throw new Exception("shouldContain() failed to throw exception"); 4.112 - } catch (RuntimeException e) { 4.113 - // expected 4.114 - } 4.115 - 4.116 - // Should match 4.117 - try { 4.118 - output.shouldMatch(stdoutPattern); 4.119 - output.stdoutShouldMatch(stdoutPattern); 4.120 - output.shouldMatch(stderrPattern); 4.121 - output.stderrShouldMatch(stderrPattern); 4.122 - } catch (RuntimeException e) { 4.123 - throw new Exception("shouldMatch() failed", e); 4.124 - } 4.125 - 4.126 - try { 4.127 - output.shouldMatch(nonExistingPattern); 4.128 - throw new Exception("shouldMatch() failed to throw exception"); 4.129 - } catch (RuntimeException e) { 4.130 - // expected 4.131 - } 4.132 - 4.133 - try { 4.134 - output.stdoutShouldMatch(stderrPattern); 4.135 - throw new Exception( 4.136 - "stdoutShouldMatch() failed to throw exception"); 4.137 - } catch (RuntimeException e) { 4.138 - // expected 4.139 - } 4.140 - 4.141 - try { 4.142 - output.stderrShouldMatch(stdoutPattern); 4.143 - throw new Exception( 4.144 - "stderrShouldMatch() failed to throw exception"); 4.145 - } catch (RuntimeException e) { 4.146 - // expected 4.147 - } 4.148 - 4.149 - // Should not match 4.150 - try { 4.151 - output.shouldNotMatch(nonExistingPattern); 4.152 - output.stdoutShouldNotMatch(nonExistingPattern); 4.153 - output.stderrShouldNotMatch(nonExistingPattern); 4.154 - } catch (RuntimeException e) { 4.155 - throw new Exception("shouldNotMatch() failed", e); 4.156 - } 4.157 - 4.158 - try { 4.159 - output.shouldNotMatch(stdoutPattern); 4.160 - throw new Exception("shouldNotMatch() failed to throw exception"); 4.161 - } catch (RuntimeException e) { 4.162 - // expected 4.163 - } 4.164 - 4.165 - try { 4.166 - output.stdoutShouldNotMatch(stdoutPattern); 4.167 - throw new Exception("shouldNotMatch() failed to throw exception"); 4.168 - } catch (RuntimeException e) { 4.169 - // expected 4.170 - } 4.171 - 4.172 - try { 4.173 - output.stderrShouldNotMatch(stderrPattern); 4.174 - throw new Exception("shouldNotMatch() failed to throw exception"); 4.175 - } catch (RuntimeException e) { 4.176 - // expected 4.177 - } 4.178 - 4.179 - { 4.180 - String aaaa = "aaaa"; 4.181 - String result = output.firstMatch(aaaa); 4.182 - if (!aaaa.equals(result)) { 4.183 - throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result); 4.184 - } 4.185 - } 4.186 - 4.187 - { 4.188 - String aa = "aa"; 4.189 - String aa_grouped_aa = aa + "(" + aa + ")"; 4.190 - String result = output.firstMatch(aa_grouped_aa, 1); 4.191 - if (!aa.equals(result)) { 4.192 - throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result); 4.193 - } 4.194 - } 4.195 - } 4.196 -}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/testlibrary_tests/AssertsTest.java Wed Sep 25 17:47:22 2013 +0200 5.3 @@ -0,0 +1,237 @@ 5.4 +/* 5.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + */ 5.26 + 5.27 +import static com.oracle.java.testlibrary.Asserts.*; 5.28 + 5.29 +/* @test 5.30 + * @summary Tests the different assertions in the Assert class 5.31 + * @library /testlibrary 5.32 + */ 5.33 +public class AssertsTest { 5.34 + private static class Foo implements Comparable<Foo> { 5.35 + final int id; 5.36 + public Foo(int id) { 5.37 + this.id = id; 5.38 + } 5.39 + 5.40 + public int compareTo(Foo f) { 5.41 + return new Integer(id).compareTo(new Integer(f.id)); 5.42 + } 5.43 + } 5.44 + 5.45 + public static void main(String[] args) throws Exception { 5.46 + testLessThan(); 5.47 + testLessThanOrEqual(); 5.48 + testEquals(); 5.49 + testGreaterThanOrEqual(); 5.50 + testGreaterThan(); 5.51 + testNotEquals(); 5.52 + testNull(); 5.53 + testNotNull(); 5.54 + testTrue(); 5.55 + testFalse(); 5.56 + } 5.57 + 5.58 + private static void testLessThan() throws Exception { 5.59 + expectPass(Assertion.LT, 1, 2); 5.60 + 5.61 + expectFail(Assertion.LT, 2, 2); 5.62 + expectFail(Assertion.LT, 2, 1); 5.63 + expectFail(Assertion.LT, null, 2); 5.64 + expectFail(Assertion.LT, 2, null); 5.65 + } 5.66 + 5.67 + private static void testLessThanOrEqual() throws Exception { 5.68 + expectPass(Assertion.LTE, 1, 2); 5.69 + expectPass(Assertion.LTE, 2, 2); 5.70 + 5.71 + expectFail(Assertion.LTE, 3, 2); 5.72 + expectFail(Assertion.LTE, null, 2); 5.73 + expectFail(Assertion.LTE, 2, null); 5.74 + } 5.75 + 5.76 + private static void testEquals() throws Exception { 5.77 + expectPass(Assertion.EQ, 1, 1); 5.78 + expectPass(Assertion.EQ, null, null); 5.79 + 5.80 + Foo f1 = new Foo(1); 5.81 + expectPass(Assertion.EQ, f1, f1); 5.82 + 5.83 + Foo f2 = new Foo(1); 5.84 + expectFail(Assertion.EQ, f1, f2); 5.85 + expectFail(Assertion.LTE, null, 2); 5.86 + expectFail(Assertion.LTE, 2, null); 5.87 + } 5.88 + 5.89 + private static void testGreaterThanOrEqual() throws Exception { 5.90 + expectPass(Assertion.GTE, 1, 1); 5.91 + expectPass(Assertion.GTE, 2, 1); 5.92 + 5.93 + expectFail(Assertion.GTE, 1, 2); 5.94 + expectFail(Assertion.GTE, null, 2); 5.95 + expectFail(Assertion.GTE, 2, null); 5.96 + } 5.97 + 5.98 + private static void testGreaterThan() throws Exception { 5.99 + expectPass(Assertion.GT, 2, 1); 5.100 + 5.101 + expectFail(Assertion.GT, 1, 1); 5.102 + expectFail(Assertion.GT, 1, 2); 5.103 + expectFail(Assertion.GT, null, 2); 5.104 + expectFail(Assertion.GT, 2, null); 5.105 + } 5.106 + 5.107 + private static void testNotEquals() throws Exception { 5.108 + expectPass(Assertion.NE, null, 1); 5.109 + expectPass(Assertion.NE, 1, null); 5.110 + 5.111 + Foo f1 = new Foo(1); 5.112 + Foo f2 = new Foo(1); 5.113 + expectPass(Assertion.NE, f1, f2); 5.114 + 5.115 + expectFail(Assertion.NE, null, null); 5.116 + expectFail(Assertion.NE, f1, f1); 5.117 + expectFail(Assertion.NE, 1, 1); 5.118 + } 5.119 + 5.120 + private static void testNull() throws Exception { 5.121 + expectPass(Assertion.NULL, null); 5.122 + 5.123 + expectFail(Assertion.NULL, 1); 5.124 + } 5.125 + 5.126 + private static void testNotNull() throws Exception { 5.127 + expectPass(Assertion.NOTNULL, 1); 5.128 + 5.129 + expectFail(Assertion.NOTNULL, null); 5.130 + } 5.131 + 5.132 + private static void testTrue() throws Exception { 5.133 + expectPass(Assertion.TRUE, true); 5.134 + 5.135 + expectFail(Assertion.TRUE, false); 5.136 + } 5.137 + 5.138 + private static void testFalse() throws Exception { 5.139 + expectPass(Assertion.FALSE, false); 5.140 + 5.141 + expectFail(Assertion.FALSE, true); 5.142 + } 5.143 + 5.144 + private static <T extends Comparable<T>> void expectPass(Assertion assertion, T ... args) 5.145 + throws Exception { 5.146 + Assertion.run(assertion, args); 5.147 + } 5.148 + 5.149 + private static <T extends Comparable<T>> void expectFail(Assertion assertion, T ... args) 5.150 + throws Exception { 5.151 + try { 5.152 + Assertion.run(assertion, args); 5.153 + } catch (RuntimeException e) { 5.154 + return; 5.155 + } 5.156 + throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) + 5.157 + " to throw a RuntimeException"); 5.158 + } 5.159 + 5.160 +} 5.161 + 5.162 +enum Assertion { 5.163 + LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE; 5.164 + 5.165 + public static <T extends Comparable<T>> void run(Assertion assertion, T ... args) { 5.166 + String msg = "Expected " + format(assertion, args) + " to pass"; 5.167 + switch (assertion) { 5.168 + case LT: 5.169 + assertLessThan(args[0], args[1], msg); 5.170 + break; 5.171 + case LTE: 5.172 + assertLessThanOrEqual(args[0], args[1], msg); 5.173 + break; 5.174 + case EQ: 5.175 + assertEquals(args[0], args[1], msg); 5.176 + break; 5.177 + case GTE: 5.178 + assertGreaterThanOrEqual(args[0], args[1], msg); 5.179 + break; 5.180 + case GT: 5.181 + assertGreaterThan(args[0], args[1], msg); 5.182 + break; 5.183 + case NE: 5.184 + assertNotEquals(args[0], args[1], msg); 5.185 + break; 5.186 + case NULL: 5.187 + assertNull(args == null ? args : args[0], msg); 5.188 + break; 5.189 + case NOTNULL: 5.190 + assertNotNull(args == null ? args : args[0], msg); 5.191 + break; 5.192 + case FALSE: 5.193 + assertFalse((Boolean) args[0], msg); 5.194 + break; 5.195 + case TRUE: 5.196 + assertTrue((Boolean) args[0], msg); 5.197 + break; 5.198 + default: 5.199 + // do nothing 5.200 + } 5.201 + } 5.202 + 5.203 + public static String format(Assertion assertion, Object ... args) { 5.204 + switch (assertion) { 5.205 + case LT: 5.206 + return asString("assertLessThan", args); 5.207 + case LTE: 5.208 + return asString("assertLessThanOrEqual", args); 5.209 + case EQ: 5.210 + return asString("assertEquals", args); 5.211 + case GTE: 5.212 + return asString("assertGreaterThanOrEquals", args); 5.213 + case GT: 5.214 + return asString("assertGreaterThan", args); 5.215 + case NE: 5.216 + return asString("assertNotEquals", args); 5.217 + case NULL: 5.218 + return asString("assertNull", args); 5.219 + case NOTNULL: 5.220 + return asString("assertNotNull", args); 5.221 + case FALSE: 5.222 + return asString("assertFalse", args); 5.223 + case TRUE: 5.224 + return asString("assertTrue", args); 5.225 + default: 5.226 + return ""; 5.227 + } 5.228 + } 5.229 + 5.230 + private static String asString(String assertion, Object ... args) { 5.231 + if (args == null) { 5.232 + return String.format("%s(null)", assertion); 5.233 + } 5.234 + if (args.length == 1) { 5.235 + return String.format("%s(%s)", assertion, args[0]); 5.236 + } else { 5.237 + return String.format("%s(%s, %s)", assertion, args[0], args[1]); 5.238 + } 5.239 + } 5.240 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/testlibrary_tests/OutputAnalyzerReportingTest.java Wed Sep 25 17:47:22 2013 +0200 6.3 @@ -0,0 +1,124 @@ 6.4 +/* 6.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 + 6.28 +/* 6.29 + * @test 6.30 + * @summary Test the OutputAnalyzer reporting functionality, 6.31 + * such as printing additional diagnostic info 6.32 + * (exit code, stdout, stderr, command line, etc.) 6.33 + * @library /testlibrary 6.34 + */ 6.35 + 6.36 +import java.io.ByteArrayOutputStream; 6.37 +import java.io.PrintStream; 6.38 + 6.39 +import com.oracle.java.testlibrary.OutputAnalyzer; 6.40 +import com.oracle.java.testlibrary.ProcessTools; 6.41 + 6.42 + 6.43 +public class OutputAnalyzerReportingTest { 6.44 + 6.45 + public static void main(String[] args) throws Exception { 6.46 + // Create the output analyzer under test 6.47 + String stdout = "aaaaaa"; 6.48 + String stderr = "bbbbbb"; 6.49 + OutputAnalyzer output = new OutputAnalyzer(stdout, stderr); 6.50 + 6.51 + // Expected summary values should be the same for all cases, 6.52 + // since the outputAnalyzer object is the same 6.53 + String expectedExitValue = "-1"; 6.54 + String expectedSummary = 6.55 + " stdout: [" + stdout + "];\n" + 6.56 + " stderr: [" + stderr + "]\n" + 6.57 + " exitValue = " + expectedExitValue + "\n"; 6.58 + 6.59 + 6.60 + DiagnosticSummaryTestRunner testRunner = 6.61 + new DiagnosticSummaryTestRunner(); 6.62 + 6.63 + // should have exit value 6.64 + testRunner.init(expectedSummary); 6.65 + int unexpectedExitValue = 2; 6.66 + try { 6.67 + output.shouldHaveExitValue(unexpectedExitValue); 6.68 + } catch (RuntimeException e) { } 6.69 + testRunner.closeAndCheckResults(); 6.70 + 6.71 + // should not contain 6.72 + testRunner.init(expectedSummary); 6.73 + try { 6.74 + output.shouldNotContain(stdout); 6.75 + } catch (RuntimeException e) { } 6.76 + testRunner.closeAndCheckResults(); 6.77 + 6.78 + // should contain 6.79 + testRunner.init(expectedSummary); 6.80 + try { 6.81 + output.shouldContain("unexpected-stuff"); 6.82 + } catch (RuntimeException e) { } 6.83 + testRunner.closeAndCheckResults(); 6.84 + 6.85 + // should not match 6.86 + testRunner.init(expectedSummary); 6.87 + try { 6.88 + output.shouldNotMatch("[a]"); 6.89 + } catch (RuntimeException e) { } 6.90 + testRunner.closeAndCheckResults(); 6.91 + 6.92 + // should match 6.93 + testRunner.init(expectedSummary); 6.94 + try { 6.95 + output.shouldMatch("[qwerty]"); 6.96 + } catch (RuntimeException e) { } 6.97 + testRunner.closeAndCheckResults(); 6.98 + 6.99 + } 6.100 + 6.101 + private static class DiagnosticSummaryTestRunner { 6.102 + private ByteArrayOutputStream byteStream = 6.103 + new ByteArrayOutputStream(10000); 6.104 + 6.105 + private String expectedSummary = ""; 6.106 + private PrintStream errStream; 6.107 + 6.108 + 6.109 + public void init(String expectedSummary) { 6.110 + this.expectedSummary = expectedSummary; 6.111 + byteStream.reset(); 6.112 + errStream = new PrintStream(byteStream); 6.113 + System.setErr(errStream); 6.114 + } 6.115 + 6.116 + public void closeAndCheckResults() { 6.117 + // check results 6.118 + errStream.close(); 6.119 + String stdErrStr = byteStream.toString(); 6.120 + if (!stdErrStr.contains(expectedSummary)) { 6.121 + throw new RuntimeException("The output does not contain " 6.122 + + "the diagnostic message, or the message is incorrect"); 6.123 + } 6.124 + } 6.125 + } 6.126 + 6.127 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/testlibrary_tests/OutputAnalyzerTest.java Wed Sep 25 17:47:22 2013 +0200 7.3 @@ -0,0 +1,193 @@ 7.4 +/* 7.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + */ 7.26 + 7.27 +/* 7.28 + * @test 7.29 + * @summary Test the OutputAnalyzer utility class 7.30 + * @library /testlibrary 7.31 + */ 7.32 + 7.33 +import com.oracle.java.testlibrary.OutputAnalyzer; 7.34 + 7.35 +public class OutputAnalyzerTest { 7.36 + 7.37 + public static void main(String args[]) throws Exception { 7.38 + 7.39 + String stdout = "aaaaaa"; 7.40 + String stderr = "bbbbbb"; 7.41 + 7.42 + // Regexps used for testing pattern matching of the test input 7.43 + String stdoutPattern = "[a]"; 7.44 + String stderrPattern = "[b]"; 7.45 + String nonExistingPattern = "[c]"; 7.46 + 7.47 + OutputAnalyzer output = new OutputAnalyzer(stdout, stderr); 7.48 + 7.49 + if (!stdout.equals(output.getStdout())) { 7.50 + throw new Exception("getStdout() returned '" + output.getStdout() + "', expected '" + stdout + "'"); 7.51 + } 7.52 + 7.53 + if (!stderr.equals(output.getStderr())) { 7.54 + throw new Exception("getStderr() returned '" + output.getStderr() + "', expected '" + stderr + "'"); 7.55 + } 7.56 + 7.57 + try { 7.58 + output.shouldContain(stdout); 7.59 + output.stdoutShouldContain(stdout); 7.60 + output.shouldContain(stderr); 7.61 + output.stderrShouldContain(stderr); 7.62 + } catch (RuntimeException e) { 7.63 + throw new Exception("shouldContain() failed", e); 7.64 + } 7.65 + 7.66 + try { 7.67 + output.shouldContain("cccc"); 7.68 + throw new Exception("shouldContain() failed to throw exception"); 7.69 + } catch (RuntimeException e) { 7.70 + // expected 7.71 + } 7.72 + 7.73 + try { 7.74 + output.stdoutShouldContain(stderr); 7.75 + throw new Exception("stdoutShouldContain() failed to throw exception"); 7.76 + } catch (RuntimeException e) { 7.77 + // expected 7.78 + } 7.79 + 7.80 + try { 7.81 + output.stderrShouldContain(stdout); 7.82 + throw new Exception("stdoutShouldContain() failed to throw exception"); 7.83 + } catch (RuntimeException e) { 7.84 + // expected 7.85 + } 7.86 + 7.87 + try { 7.88 + output.shouldNotContain("cccc"); 7.89 + output.stdoutShouldNotContain("cccc"); 7.90 + output.stderrShouldNotContain("cccc"); 7.91 + } catch (RuntimeException e) { 7.92 + throw new Exception("shouldNotContain() failed", e); 7.93 + } 7.94 + 7.95 + try { 7.96 + output.shouldNotContain(stdout); 7.97 + throw new Exception("shouldContain() failed to throw exception"); 7.98 + } catch (RuntimeException e) { 7.99 + // expected 7.100 + } 7.101 + 7.102 + try { 7.103 + output.stdoutShouldNotContain(stdout); 7.104 + throw new Exception("shouldContain() failed to throw exception"); 7.105 + } catch (RuntimeException e) { 7.106 + // expected 7.107 + } 7.108 + 7.109 + try { 7.110 + output.stderrShouldNotContain(stderr); 7.111 + throw new Exception("shouldContain() failed to throw exception"); 7.112 + } catch (RuntimeException e) { 7.113 + // expected 7.114 + } 7.115 + 7.116 + // Should match 7.117 + try { 7.118 + output.shouldMatch(stdoutPattern); 7.119 + output.stdoutShouldMatch(stdoutPattern); 7.120 + output.shouldMatch(stderrPattern); 7.121 + output.stderrShouldMatch(stderrPattern); 7.122 + } catch (RuntimeException e) { 7.123 + throw new Exception("shouldMatch() failed", e); 7.124 + } 7.125 + 7.126 + try { 7.127 + output.shouldMatch(nonExistingPattern); 7.128 + throw new Exception("shouldMatch() failed to throw exception"); 7.129 + } catch (RuntimeException e) { 7.130 + // expected 7.131 + } 7.132 + 7.133 + try { 7.134 + output.stdoutShouldMatch(stderrPattern); 7.135 + throw new Exception( 7.136 + "stdoutShouldMatch() failed to throw exception"); 7.137 + } catch (RuntimeException e) { 7.138 + // expected 7.139 + } 7.140 + 7.141 + try { 7.142 + output.stderrShouldMatch(stdoutPattern); 7.143 + throw new Exception( 7.144 + "stderrShouldMatch() failed to throw exception"); 7.145 + } catch (RuntimeException e) { 7.146 + // expected 7.147 + } 7.148 + 7.149 + // Should not match 7.150 + try { 7.151 + output.shouldNotMatch(nonExistingPattern); 7.152 + output.stdoutShouldNotMatch(nonExistingPattern); 7.153 + output.stderrShouldNotMatch(nonExistingPattern); 7.154 + } catch (RuntimeException e) { 7.155 + throw new Exception("shouldNotMatch() failed", e); 7.156 + } 7.157 + 7.158 + try { 7.159 + output.shouldNotMatch(stdoutPattern); 7.160 + throw new Exception("shouldNotMatch() failed to throw exception"); 7.161 + } catch (RuntimeException e) { 7.162 + // expected 7.163 + } 7.164 + 7.165 + try { 7.166 + output.stdoutShouldNotMatch(stdoutPattern); 7.167 + throw new Exception("shouldNotMatch() failed to throw exception"); 7.168 + } catch (RuntimeException e) { 7.169 + // expected 7.170 + } 7.171 + 7.172 + try { 7.173 + output.stderrShouldNotMatch(stderrPattern); 7.174 + throw new Exception("shouldNotMatch() failed to throw exception"); 7.175 + } catch (RuntimeException e) { 7.176 + // expected 7.177 + } 7.178 + 7.179 + { 7.180 + String aaaa = "aaaa"; 7.181 + String result = output.firstMatch(aaaa); 7.182 + if (!aaaa.equals(result)) { 7.183 + throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result); 7.184 + } 7.185 + } 7.186 + 7.187 + { 7.188 + String aa = "aa"; 7.189 + String aa_grouped_aa = aa + "(" + aa + ")"; 7.190 + String result = output.firstMatch(aa_grouped_aa, 1); 7.191 + if (!aa.equals(result)) { 7.192 + throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result); 7.193 + } 7.194 + } 7.195 + } 7.196 +}