1 /*
2  * Copyright (c) 2016, 2020, 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 8168615 8172102
27  * @summary Test all the ToolSimpleTest tests, but in local execution. Verify --execution flag
28  * @modules jdk.compiler/com.sun.tools.javac.api
29  *          jdk.compiler/com.sun.tools.javac.main
30  *          jdk.jdeps/com.sun.tools.javap
31  *          jdk.jshell/jdk.internal.jshell.tool
32  * @build KullaTesting TestingInputStream ToolSimpleTest
33  * @run testng/othervm ToolLocalSimpleTest
34  */
35 
36 import java.util.Locale;
37 import org.testng.annotations.Test;
38 import static org.testng.Assert.assertEquals;
39 
40 public class ToolLocalSimpleTest extends ToolSimpleTest {
41 
42     @Override
43     public void test(Locale locale, boolean isDefaultStartUp, String[] args, String startUpMessage, ReplTest... tests) {
44         String[] wargs = new String[args.length + 2];
45         wargs[0] = "--execution";
46         wargs[1] = "local";
47         System.arraycopy(args, 0, wargs, 2, args.length);
48         super.test(locale, isDefaultStartUp, wargs, startUpMessage, tests);
testSetFormat()49     }
50 
51     @Test
52     public void verifyLocal() {
53         System.setProperty("LOCAL_CHECK", "Here");
54         assertEquals(System.getProperty("LOCAL_CHECK"), "Here");
55         test(new String[]{"--no-startup"},
56                 a -> assertCommand(a, "System.getProperty(\"LOCAL_CHECK\")", "$1 ==> \"Here\""),
57                 a -> assertCommand(a, "System.setProperty(\"LOCAL_CHECK\", \"After\")", "$2 ==> \"Here\"")
58         );
59         assertEquals(System.getProperty("LOCAL_CHECK"), "After");
60     }
61 
62     @Override
63     @Test
64     public void testOptionR() {
65         test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"},
66                 (a) -> assertCommand(a, "System.getProperty(\"the.sound\")",
67                         "$1 ==> null")
68         );
69     }
70 
71     @Override
72     @Test
73     public void testCompoundStart() {
74         test(new String[]{"--startup", "DEFAULT", "--startup", "PRINTING"},
75                 (a) -> assertCommandOutputContains(a, "/list -start",
76                         "System.out.println", "import java.util.concurrent")
77         );
78     }
79 
80     @Test
81     public void testOptionBadR() {
82         test(new String[]{"-R-RottenLiver"},
83                 (a) -> assertCommand(a, "43",
84                         "$1 ==> 43")
85         );
86     }
87 
88     @Test
testSetFormatOverride()89     public void testRawString() {
90         // can't set --enable-preview for local, ignore
91     }
92 
93     @Test
94     public void testSwitchExpression() {
95         // can't set --enable-preview for local, ignore
96     }
97 
98     @Test
99     public void testSwitchExpressionCompletion() {
100         // can't set --enable-preview for local, ignore
101     }
102 
103     @Override
104     public void testRecords() {
105         // can't set --enable-preview for local, ignore
106     }
107 }
108