|
1 /* |
|
2 * Copyright (c) 2018, 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 * @bug 8199193 |
|
27 * @summary Tests for the --enable-preview option |
|
28 * @run testng ToolEnablePreviewTest |
|
29 */ |
|
30 |
|
31 import org.testng.annotations.Test; |
|
32 |
|
33 import static org.testng.Assert.assertTrue; |
|
34 |
|
35 public class ToolEnablePreviewTest extends ReplToolTesting { |
|
36 |
|
37 @Test |
|
38 public void testOptionDebug() { |
|
39 String release = System.getProperty("java.specification.version"); |
|
40 test( |
|
41 (a) -> assertCommand(a, "/debug b", |
|
42 "RemoteVM Options: []\n" |
|
43 + "Compiler options: []"), |
|
44 (a) -> assertCommand(a, "/env --enable-preview", |
|
45 "| Setting new options and restoring state."), |
|
46 (a) -> assertCommandCheckOutput(a, "/debug b", s -> { |
|
47 assertTrue(s.contains("RemoteVM Options: [--enable-preview]")); |
|
48 assertTrue(s.contains("Compiler options: [-source, " + release + ", --enable-preview]") |
|
49 || s.contains("Compiler options: [--enable-preview, -source, " + release + "]"), |
|
50 "\nExpected -- " + "Compiler options: [-source, " + release + ", --enable-preview]" |
|
51 + "\nOr -- " + "Compiler options: [--enable-preview, -source, " + release + "]" |
|
52 + "\nBut got -- " + s); |
|
53 }) |
|
54 ); |
|
55 } |
|
56 |
|
57 @Test |
|
58 public void testCommandLineFlag() { |
|
59 String release = System.getProperty("java.specification.version"); |
|
60 test(new String[] {"--enable-preview"}, |
|
61 (a) -> assertCommandCheckOutput(a, "/debug b", s -> { |
|
62 assertTrue(s.contains("RemoteVM Options: [--enable-preview]")); |
|
63 assertTrue(s.contains("Compiler options: [-source, " + release + ", --enable-preview]") |
|
64 || s.contains("Compiler options: [--enable-preview, -source, " + release + "]"), |
|
65 "\nExpected -- " + "Compiler options: [-source, " + release + ", --enable-preview]" |
|
66 + "\nOr -- " + "Compiler options: [--enable-preview, -source, " + release + "]" |
|
67 + "\nBut got -- " + s); |
|
68 }) |
|
69 ); |
|
70 } |
|
71 |
|
72 @Test |
|
73 public void testCompilerTestFlagEnv() { |
|
74 test(new String[] {"-C", "-XDforcePreview"}, |
|
75 (a) -> assertCommandOutputContains(a, "Function<Integer,Integer> f = i -> i + i", |
|
76 "Error", "preview feature"), |
|
77 (a) -> assertCommand(a, "/env --enable-preview", |
|
78 "| Setting new options and restoring state."), |
|
79 (a) -> assertCommandOutputContains(a, "Function<Integer,Integer> f = i -> i + i", |
|
80 "f ==> ") |
|
81 ); |
|
82 } |
|
83 |
|
84 @Test |
|
85 public void testCompilerTestFlag() { |
|
86 test(new String[] {"-C", "-XDforcePreview", "--enable-preview"}, |
|
87 (a) -> assertCommandOutputContains(a, "Function<Integer,Integer> f = i -> i + i", |
|
88 "f ==> "), |
|
89 (a) -> assertCommandOutputContains(a, "f.apply(2)", "==> 4") |
|
90 ); |
|
91 } |
|
92 |
|
93 } |