270 test(new String[] { "--class-path", classpath.toString() }, |
271 test(new String[] { "--class-path", classpath.toString() }, |
271 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
272 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
272 ); |
273 ); |
273 } |
274 } |
274 |
275 |
275 public void testClasspathJar() { |
276 private String makeSimpleJar() { |
276 Compiler compiler = new Compiler(); |
277 Compiler compiler = new Compiler(); |
277 Path outDir = Paths.get("testClasspathJar"); |
278 Path outDir = Paths.get("testClasspathJar"); |
278 compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
279 compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }"); |
279 String jarName = "test.jar"; |
280 String jarName = "test.jar"; |
280 compiler.jar(outDir, jarName, "pkg/A.class"); |
281 compiler.jar(outDir, jarName, "pkg/A.class"); |
281 Path jarPath = compiler.getPath(outDir).resolve(jarName); |
282 return compiler.getPath(outDir).resolve(jarName).toString(); |
|
283 } |
|
284 |
|
285 public void testClasspathJar() { |
|
286 String jarPath = makeSimpleJar(); |
282 test( |
287 test( |
283 (a) -> assertCommand(a, "/env --class-path " + jarPath, |
288 (a) -> assertCommand(a, "/env --class-path " + jarPath, |
284 "| Setting new options and restoring state."), |
289 "| Setting new options and restoring state."), |
285 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
290 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
286 ); |
291 ); |
287 test(new String[] { "--class-path", jarPath.toString() }, |
292 test(new String[] { "--class-path", jarPath }, |
288 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
293 (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A") |
|
294 ); |
|
295 } |
|
296 |
|
297 public void testClasspathUserHomeExpansion() { |
|
298 String jarPath = makeSimpleJar(); |
|
299 String tilde = "~" + File.separator; |
|
300 test( |
|
301 (a) -> assertCommand(a, "/env --class-path " + tilde + "forblato", |
|
302 "| File '" + System.getProperty("user.home") + File.separator |
|
303 + "forblato' for '--class-path' is not found."), |
|
304 (a) -> assertCommand(a, "/env --class-path " + jarPath + File.pathSeparator |
|
305 + tilde + "forblato", |
|
306 "| File '" + System.getProperty("user.home") + File.separator |
|
307 + "forblato' for '--class-path' is not found.") |
|
308 ); |
|
309 } |
|
310 |
|
311 public void testBadClasspath() { |
|
312 String jarPath = makeSimpleJar(); |
|
313 Compiler compiler = new Compiler(); |
|
314 Path t1 = compiler.getPath("whatever/thing.zip"); |
|
315 compiler.writeToFile(t1, ""); |
|
316 Path t2 = compiler.getPath("whatever/thing.jmod"); |
|
317 compiler.writeToFile(t2, ""); |
|
318 test( |
|
319 (a) -> assertCommand(a, "/env --class-path " + t1.toString(), |
|
320 "| Invalid '--class-path' argument: " + t1.toString()), |
|
321 (a) -> assertCommand(a, "/env --class-path " + jarPath + File.pathSeparator + t1.toString(), |
|
322 "| Invalid '--class-path' argument: " + t1.toString()), |
|
323 (a) -> assertCommand(a, "/env --class-path " + t2.toString(), |
|
324 "| Invalid '--class-path' argument: " + t2.toString()) |
289 ); |
325 ); |
290 } |
326 } |
291 |
327 |
292 public void testModulePath() { |
328 public void testModulePath() { |
293 Compiler compiler = new Compiler(); |
329 Compiler compiler = new Compiler(); |
299 test(new String[] { "--module-path", modsPath.toString(), "--add-modules", "org.astro" }, |
335 test(new String[] { "--module-path", modsPath.toString(), "--add-modules", "org.astro" }, |
300 (a) -> assertCommand(a, "import org.astro.World;", ""), |
336 (a) -> assertCommand(a, "import org.astro.World;", ""), |
301 (a) -> evaluateExpression(a, "String", |
337 (a) -> evaluateExpression(a, "String", |
302 "String.format(\"Greetings %s!\", World.name());", |
338 "String.format(\"Greetings %s!\", World.name());", |
303 "\"Greetings world!\"") |
339 "\"Greetings world!\"") |
|
340 ); |
|
341 } |
|
342 |
|
343 public void testModulePathUserHomeExpansion() { |
|
344 String tilde = "~" + File.separatorChar; |
|
345 test( |
|
346 (a) -> assertCommand(a, "/env --module-path " + tilde + "snardugol", |
|
347 "| File '" + System.getProperty("user.home") |
|
348 + File.separatorChar + "snardugol' for '--module-path' is not found.") |
|
349 ); |
|
350 } |
|
351 |
|
352 public void testBadModulePath() { |
|
353 Compiler compiler = new Compiler(); |
|
354 Path t1 = compiler.getPath("whatever/thing.zip"); |
|
355 compiler.writeToFile(t1, ""); |
|
356 test( |
|
357 (a) -> assertCommand(a, "/env --module-path " + t1.toString(), |
|
358 "| Invalid '--module-path' argument: " + t1.toString()) |
304 ); |
359 ); |
305 } |
360 } |
306 |
361 |
307 public void testStartupFileOption() { |
362 public void testStartupFileOption() { |
308 Compiler compiler = new Compiler(); |
363 Compiler compiler = new Compiler(); |