diff options
author | Antoine Gourlay <antoine@gourlay.fr> | 2014-08-26 09:43:49 +0200 |
---|---|---|
committer | Antoine Gourlay <antoine@gourlay.fr> | 2014-08-26 13:26:59 +0200 |
commit | 9519eb094130ab121fa10767916e812b76bdc947 (patch) | |
tree | 98286a0cf6f92abdec8256f37ed68c977ffadf3c /test | |
parent | 3555e0ec840a7ab843794e53a17142bd6ee49d87 (diff) | |
download | scala-9519eb094130ab121fa10767916e812b76bdc947.tar.gz scala-9519eb094130ab121fa10767916e812b76bdc947.tar.bz2 scala-9519eb094130ab121fa10767916e812b76bdc947.zip |
SI-5254 running an empty scala script should succeed
The script runner made the assumption that "compilation succeeded"
implies "there is a Main class to run", but this can be wrong if the
script is empty (or only contains imports/comments).
The ScriptRunner now uses the ClassPath utility to check if there really
is a main class. If not, it doesn't try to run it and returns
peacefully. This also makes `scala -e ''` succeed.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/tools/nsc/ScriptRunnerTest.scala | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/ScriptRunnerTest.scala b/test/junit/scala/tools/nsc/ScriptRunnerTest.scala new file mode 100644 index 0000000000..9bae7a0487 --- /dev/null +++ b/test/junit/scala/tools/nsc/ScriptRunnerTest.scala @@ -0,0 +1,23 @@ +package scala.tools.nsc + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class ScriptRunnerTest { + @Test + def testEmptyScriptSucceeds: Unit = { + val s = new GenericRunnerSettings(s => ()) + s.nc.value = true + s.usejavacp.value = true + + // scala -nc -e '' + assertTrue(ScriptRunner.runCommand(s, "", Nil)) + + // scala -nc -save -e '' + s.save.value = true + assertTrue(ScriptRunner.runCommand(s, "", Nil)) + } +} |