ToolLocalSimpleTest.java revision 3849:b2e915d476be
1/* 2 * Copyright (c) 2016, 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 ToolLocalSimpleTest 34 */ 35 36import java.util.Locale; 37import org.testng.annotations.Test; 38import static org.testng.Assert.assertEquals; 39 40public 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); 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} 89