33362
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @summary simple regression test
|
|
27 |
* @build KullaTesting TestingInputStream
|
|
28 |
* @run testng SimpleRegressionTest
|
|
29 |
*/
|
|
30 |
|
|
31 |
|
|
32 |
import java.util.List;
|
|
33 |
|
|
34 |
import javax.tools.Diagnostic;
|
|
35 |
|
|
36 |
import jdk.jshell.Snippet;
|
|
37 |
import jdk.jshell.VarSnippet;
|
|
38 |
import jdk.jshell.SnippetEvent;
|
|
39 |
import org.testng.annotations.Test;
|
|
40 |
|
|
41 |
import static org.testng.Assert.assertEquals;
|
|
42 |
import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND;
|
|
43 |
import static jdk.jshell.Snippet.Status.VALID;
|
|
44 |
|
|
45 |
@Test
|
|
46 |
public class SimpleRegressionTest extends KullaTesting {
|
|
47 |
|
|
48 |
public void testSnippetMemberAssignment() {
|
|
49 |
assertEval("class C { int y; }");
|
|
50 |
assertEval("C c = new C();");
|
|
51 |
assertVarKeyMatch("c.y = 4;", true, "$1", TEMP_VAR_EXPRESSION_SUBKIND, "int", added(VALID));
|
|
52 |
}
|
|
53 |
|
|
54 |
public void testUserTakesTempVarName() {
|
|
55 |
assertEval("int $2 = 4;");
|
|
56 |
assertEval("String $1;");
|
|
57 |
assertVarKeyMatch("1234;", true, "$3", TEMP_VAR_EXPRESSION_SUBKIND, "int", added(VALID));
|
|
58 |
}
|
|
59 |
|
|
60 |
public void testCompileThrow() {
|
|
61 |
assertEvalException("throw new Exception();");
|
|
62 |
}
|
|
63 |
|
|
64 |
public void testMultiSnippetDependencies() {
|
|
65 |
List<SnippetEvent> events = assertEval("int a = 3, b = a+a, c = b *100;",
|
|
66 |
DiagCheck.DIAG_OK, DiagCheck.DIAG_OK,
|
|
67 |
chain(added(VALID)),
|
|
68 |
chain(added(VALID)),
|
|
69 |
chain(added(VALID)));
|
|
70 |
assertEquals(events.get(0).value(), "3");
|
|
71 |
assertEquals(events.get(1).value(), "6");
|
|
72 |
assertEquals(events.get(2).value(), "600");
|
|
73 |
assertEval("c;", "600");
|
|
74 |
}
|
|
75 |
|
|
76 |
public void testNotStmtCannotResolve() {
|
|
77 |
assertDeclareFail("dfasder;", new ExpectedDiagnostic("compiler.err.cant.resolve.location", 0, 7, 0, -1, -1, Diagnostic.Kind.ERROR));
|
|
78 |
}
|
|
79 |
|
|
80 |
public void testNotStmtIncomparable() {
|
|
81 |
assertDeclareFail("true == 5.0;", new ExpectedDiagnostic("compiler.err.incomparable.types", 0, 11, 5, -1, -1, Diagnostic.Kind.ERROR));
|
|
82 |
}
|
|
83 |
|
|
84 |
public void testStringAdd() {
|
|
85 |
assertEval("String s = \"a\" + \"b\";", "\"ab\"");
|
|
86 |
}
|
|
87 |
|
|
88 |
public void testExprSanity() {
|
|
89 |
assertEval("int x = 3;", "3");
|
|
90 |
assertEval("int y = 4;", "4");
|
|
91 |
assertEval("x + y;", "7");
|
|
92 |
assertActiveKeys();
|
|
93 |
}
|
|
94 |
|
|
95 |
public void testGenericMethodCrash() {
|
|
96 |
assertDeclareWarn1("<T> void f(T...a) {}", (ExpectedDiagnostic) null);
|
|
97 |
Snippet sn = methodKey(assertEval("<R> R n(R x) { return x; }", added(VALID)));
|
|
98 |
VarSnippet sne = varKey(assertEval("n(5)", added(VALID)));
|
|
99 |
assertEquals(sne.typeName(), "Integer");
|
|
100 |
}
|
|
101 |
}
|