< prev index next >

test/langtools/jdk/jshell/ToolBasicTest.java

Print this page

        

@@ -21,11 +21,11 @@
  * questions.
  */
 
 /*
  * @test
- * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232 8196133
+ * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232 8196133 8199912
  * @summary Tests for Basic tests for REPL tool
  * @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

@@ -37,10 +37,12 @@
 
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;

@@ -50,10 +52,11 @@
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import com.sun.net.httpserver.HttpServer;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;

@@ -489,10 +492,53 @@
                             "|  File '" + unknown + "' for '/open' is not found.")
             );
         }
     }
 
+    public void testOpenLocalFileUrl() {
+        Compiler compiler = new Compiler();
+        Path path = compiler.getPath("testOpen.repl");
+        compiler.writeToFile(path, "int a = 10;int b = 20;int c = a + b;\n");
+        for (String s : new String[]{"/o", "/open"}) {
+            test(
+                    (a) -> assertCommand(a, s + " file://" + path.toString(), ""),
+                    (a) -> assertCommand(a, "a", "a ==> 10"),
+                    (a) -> assertCommand(a, "b", "b ==> 20"),
+                    (a) -> assertCommand(a, "c", "c ==> 30")
+            );
+        }
+    }
+
+    public void testOpenFileOverHttp() throws IOException {
+        var script = "int a = 10;int b = 20;int c = a + b;";
+
+        var localhostAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 0);
+        var httpServer = HttpServer.create(localhostAddress, 0);
+        try {
+            httpServer.createContext("/script", exchange -> {
+                exchange.sendResponseHeaders(200, script.length());
+                try (var output = exchange.getResponseBody()) {
+                    output.write(script.getBytes());
+                }
+            });
+            httpServer.setExecutor(null);
+            httpServer.start();
+
+            var urlAddress = "http:/" + httpServer.getAddress().toString() + "/script";
+            for (String s : new String[]{"/o", "/open"}) {
+                test(
+                        (a) -> assertCommand(a, s + " " + urlAddress, ""),
+                        (a) -> assertCommand(a, "a", "a ==> 10"),
+                        (a) -> assertCommand(a, "b", "b ==> 20"),
+                        (a) -> assertCommand(a, "c", "c ==> 30")
+                );
+            }
+        } finally {
+            httpServer.stop(0);
+        }
+    }
+
     public void testOpenResource() {
         test(
                 (a) -> assertCommand(a, "/open PRINTING", ""),
                 (a) -> assertCommandOutputContains(a, "/list",
                         "void println", "System.out.printf"),
< prev index next >