Path: blob/master/test/langtools/jdk/jshell/BadExecutionControlSpecTest.java
40931 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 816861526* @summary Test bad input to ExecutionControl.generate27* @modules jdk.compiler/com.sun.tools.javac.api28* jdk.compiler/com.sun.tools.javac.main29* jdk.jdeps/com.sun.tools.javap30* jdk.jshell/jdk.internal.jshell.tool31* @run testng BadExecutionControlSpecTest32*/3334import java.io.ByteArrayInputStream;35import java.io.ByteArrayOutputStream;36import java.io.InputStream;37import java.io.PrintStream;38import java.util.Collections;39import java.util.List;40import org.testng.annotations.Test;41import jdk.jshell.spi.ExecutionControl;42import jdk.jshell.spi.ExecutionEnv;43import static org.testng.Assert.fail;4445@Test46public class BadExecutionControlSpecTest {47private static void assertIllegal(String spec) throws Throwable {48try {49ExecutionEnv env = new ExecutionEnv() {50@Override51public InputStream userIn() {52return new ByteArrayInputStream(new byte[0]);53}5455@Override56public PrintStream userOut() {57return new PrintStream(new ByteArrayOutputStream());58}5960@Override61public PrintStream userErr() {62return new PrintStream(new ByteArrayOutputStream());63}6465@Override66public List<String> extraRemoteVMOptions() {67return Collections.emptyList();68}6970@Override71public void closeDown() {72}7374};75ExecutionControl.generate(env, spec);76fail("Expected exception -- " + spec);77} catch (IllegalArgumentException ex) {78// The expected happened79}80}8182public void syntaxTest() throws Throwable {83assertIllegal(":launch(true)");84assertIllegal("jdi:launch(true");85assertIllegal("jdi:launch(true)$");86assertIllegal("jdi:,");87}8889public void notFoundTest() throws Throwable {90assertIllegal("fruitbats");91assertIllegal("jdi:baz(true)");92assertIllegal("random:launch(true)");93assertIllegal("jdi:,");94}95}969798