Skip to content

Commit

Permalink
8341833: incomplete snippet from loaded files from command line is ig…
Browse files Browse the repository at this point in the history
…nored
  • Loading branch information
lahodaj committed Dec 20, 2024
1 parent bcb1bda commit fd8f2aa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,9 @@ private String getInput(String initial) throws IOException{
continue;
}
if (line == null) {
if (!src.isEmpty()) {
errormsg("jshell.err.incomplete.input", src);
}
//EOF
if (input.interactiveOutput()) {
// End after user ctrl-D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jshell.err.exception.thrown = Exception {0}
jshell.err.exception.thrown.message = Exception {0}: {1}
jshell.err.exception.cause = Caused by: {0}
jshell.err.exception.cause.message = Caused by: {0}: {1}
jshell.err.incomplete.input = Incomplete input: {0}

jshell.console.see.synopsis = <press tab again to see synopsis>
jshell.console.see.full.documentation = <press tab again to see full documentation>
Expand Down
33 changes: 32 additions & 1 deletion test/langtools/jdk/jshell/StartOptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
*/

/*
* @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343 8178023 8186708 8179856 8185840 8190383 8341631
* @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343 8178023 8186708 8179856 8185840 8190383 8341631 8341833
* @summary Testing startExCe-up options.
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.jdeps/com.sun.tools.javap
* jdk.jshell/jdk.internal.jshell.tool
* jdk.jshell/jdk.internal.jshell.tool.resources:+open
* @library /tools/lib
* @build Compiler toolbox.ToolBox
* @run testng StartOptionTest
Expand All @@ -38,13 +39,16 @@
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.function.Consumer;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import jdk.jshell.JShell;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Expand Down Expand Up @@ -133,6 +137,14 @@ protected void startCheckUserOutput(Consumer<String> checkUserOutput,
check(usererr, null, "usererr");
}

protected void startCheckError(Consumer<String> checkError,
String... args) {
runShell(args);
check(cmderr, checkError, "userout");
check(userout, null, "userout");
check(usererr, null, "usererr");
}

// Start with an exit code and command error check
protected void startExCe(int eec, Consumer<String> checkError, String... args) {
StartOptionTest.this.startExCoUoCeCn(
Expand Down Expand Up @@ -411,6 +423,25 @@ public void testInput() {
readPasswordPrompt);
}

public void testErroneousFile() {
String code = """
var v = (
System.console().readLine("prompt: ");
/exit
""";
String readLinePrompt = writeToFile(code);
String expectedErrorFormat =
ResourceBundle.getBundle("jdk.internal.jshell.tool.resources.l10n",
Locale.getDefault(),
JShell.class.getModule())
.getString("jshell.err.incomplete.input");
String expectedError =
new MessageFormat(expectedErrorFormat).format(new Object[] {code});
startCheckError(s -> assertEquals(s, expectedError),
readLinePrompt);
}


@AfterMethod
public void tearDown() {
cmdout = null;
Expand Down

0 comments on commit fd8f2aa

Please sign in to comment.