author | jlahoda |
Wed, 18 May 2016 21:00:43 +0200 | |
changeset 38521 | f2fe39ab9256 |
parent 37005 | 71210037624f |
child 40512 | b9359154240c |
permissions | -rw-r--r-- |
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 |
/* |
|
37005
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
25 |
* @test 8130450 |
33362 | 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; |
|
37005
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
42 |
import static jdk.jshell.Snippet.Status.OVERWRITTEN; |
33362 | 43 |
import static jdk.jshell.Snippet.SubKind.TEMP_VAR_EXPRESSION_SUBKIND; |
44 |
import static jdk.jshell.Snippet.Status.VALID; |
|
45 |
||
46 |
@Test |
|
47 |
public class SimpleRegressionTest extends KullaTesting { |
|
48 |
||
49 |
public void testSnippetMemberAssignment() { |
|
50 |
assertEval("class C { int y; }"); |
|
51 |
assertEval("C c = new C();"); |
|
52 |
assertVarKeyMatch("c.y = 4;", true, "$1", TEMP_VAR_EXPRESSION_SUBKIND, "int", added(VALID)); |
|
53 |
} |
|
54 |
||
55 |
public void testUserTakesTempVarName() { |
|
56 |
assertEval("int $2 = 4;"); |
|
57 |
assertEval("String $1;"); |
|
58 |
assertVarKeyMatch("1234;", true, "$3", TEMP_VAR_EXPRESSION_SUBKIND, "int", added(VALID)); |
|
59 |
} |
|
60 |
||
61 |
public void testCompileThrow() { |
|
62 |
assertEvalException("throw new Exception();"); |
|
63 |
} |
|
64 |
||
65 |
public void testMultiSnippetDependencies() { |
|
66 |
List<SnippetEvent> events = assertEval("int a = 3, b = a+a, c = b *100;", |
|
67 |
DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, |
|
68 |
chain(added(VALID)), |
|
69 |
chain(added(VALID)), |
|
70 |
chain(added(VALID))); |
|
71 |
assertEquals(events.get(0).value(), "3"); |
|
72 |
assertEquals(events.get(1).value(), "6"); |
|
73 |
assertEquals(events.get(2).value(), "600"); |
|
74 |
assertEval("c;", "600"); |
|
75 |
} |
|
76 |
||
77 |
public void testNotStmtCannotResolve() { |
|
78 |
assertDeclareFail("dfasder;", new ExpectedDiagnostic("compiler.err.cant.resolve.location", 0, 7, 0, -1, -1, Diagnostic.Kind.ERROR)); |
|
79 |
} |
|
80 |
||
81 |
public void testNotStmtIncomparable() { |
|
82 |
assertDeclareFail("true == 5.0;", new ExpectedDiagnostic("compiler.err.incomparable.types", 0, 11, 5, -1, -1, Diagnostic.Kind.ERROR)); |
|
83 |
} |
|
84 |
||
85 |
public void testStringAdd() { |
|
86 |
assertEval("String s = \"a\" + \"b\";", "\"ab\""); |
|
87 |
} |
|
88 |
||
89 |
public void testExprSanity() { |
|
90 |
assertEval("int x = 3;", "3"); |
|
91 |
assertEval("int y = 4;", "4"); |
|
92 |
assertEval("x + y;", "7"); |
|
93 |
assertActiveKeys(); |
|
94 |
} |
|
95 |
||
96 |
public void testGenericMethodCrash() { |
|
97 |
assertDeclareWarn1("<T> void f(T...a) {}", (ExpectedDiagnostic) null); |
|
98 |
Snippet sn = methodKey(assertEval("<R> R n(R x) { return x; }", added(VALID))); |
|
99 |
VarSnippet sne = varKey(assertEval("n(5)", added(VALID))); |
|
100 |
assertEquals(sne.typeName(), "Integer"); |
|
101 |
} |
|
37005
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
102 |
|
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
103 |
// 8130450 |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
104 |
public void testDuplicate() { |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
105 |
Snippet snm = methodKey(assertEval("void mm() {}", added(VALID))); |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
106 |
assertEval("void mm() {}", |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
107 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
108 |
ste(snm, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
109 |
Snippet snv = varKey(assertEval("boolean b;", added(VALID))); |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
110 |
assertEval("boolean b;", |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
111 |
ste(MAIN_SNIPPET, VALID, VALID, false, null), |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
112 |
ste(snv, VALID, OVERWRITTEN, false, MAIN_SNIPPET)); |
71210037624f
8130450: JShell: events are not generated for repeated source
rfield
parents:
33362
diff
changeset
|
113 |
} |
33362 | 114 |
} |