summaryrefslogtreecommitdiff
path: root/test/files/run/t6502.scala
diff options
context:
space:
mode:
authormpociecha <michal.pociecha@gmail.com>2014-11-30 22:59:04 +0100
committermpociecha <michal.pociecha@gmail.com>2014-12-05 01:16:28 +0100
commit04620a0e2a0cf64f2d33e32007d85afabad5e201 (patch)
tree3c417f0d96a866b20299252572712319e371ef74 /test/files/run/t6502.scala
parent3f94c77a8c257db23fc1be3203946a1b865104ed (diff)
downloadscala-04620a0e2a0cf64f2d33e32007d85afabad5e201.tar.gz
scala-04620a0e2a0cf64f2d33e32007d85afabad5e201.tar.bz2
scala-04620a0e2a0cf64f2d33e32007d85afabad5e201.zip
Integrate flat classpath with the compiler
This commit integrates with the compiler the whole flat classpath representation build next to the recursive one as an alternative. From now flat classpath really works and can be turned on. There's added flag -YclasspathImpl with two options: recursive (the default one) and flat. It was needed to make the dynamic dispatch to the particular classpath representation according to the chosen type of a classpath representation. There's added PathResolverFactory which is used instead of a concrete implementation of a path resolver. It turned out that only a small subset of path resolvers methods is used outside this class in Scala sources. Therefore, PathResolverFactory returns an instance of a base interface PathResolverResult providing only these used methods. PathResolverFactory in combination with matches in some other places ensures that in all places using classpath we create/get the proper representation. Also the classPath method in Global is modified to use the dynamic dispatch. This is very important change as a return type changed to the base ClassFileLookup providing subset of old ClassPath public methods. It can be problematic if someone was using in his project the explicit ClassPath type or public methods which are not provided via ClassFileLookup. I tested flat classpath with sbt and Scala IDE and there were no problems. Also was looking at sources of some other projects like e.g. Scala plugin for IntelliJ and there shouldn't be problems, I think, but it would be better to check these changes using the community build. Scalap's Main.scala is changed to be able to use both implementations and also to use flags related to the classpath implementation. The classpath invalidation is modified to work properly with the old (recursive) classpath representation after changes made in a Global. In the case of the attempt to use the invalidation for the flat cp it just throws exception with a message that the flat one currently doesn't support the invalidation. And also that's why the partest's test for the invalidation has been changed to use (always) the old implementation. There's added an adequate comment with TODO to this file. There's added partest test generating various dependencies (directories, zips and jars with sources and class files) and testing whether the compilation and further running an application works correctly, when there are these various types of entries specified as -classpath and -sourcepath. It should be a good approximation of real use cases.
Diffstat (limited to 'test/files/run/t6502.scala')
-rw-r--r--test/files/run/t6502.scala27
1 files changed, 21 insertions, 6 deletions
diff --git a/test/files/run/t6502.scala b/test/files/run/t6502.scala
index ced1b5812d..4ce034a482 100644
--- a/test/files/run/t6502.scala
+++ b/test/files/run/t6502.scala
@@ -1,6 +1,7 @@
-import scala.tools.partest._
-import java.io.File
+import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.ILoop
+import scala.tools.nsc.settings.ClassPathRepresentationType
+import scala.tools.partest._
object Test extends StoreReporterDirectTest {
def code = ???
@@ -10,6 +11,14 @@ object Test extends StoreReporterDirectTest {
compileString(newCompiler("-cp", classpath, "-d", s"${testOutput.path}/$jarFileName"))(code)
}
+ // TODO flat classpath doesn't support the classpath invalidation yet so we force using the recursive one
+ // it's the only test which needed such a workaround
+ override def settings = {
+ val settings = new Settings
+ settings.YclasspathImpl.value = ClassPathRepresentationType.Recursive
+ settings
+ }
+
def app1 = """
package test
@@ -41,7 +50,8 @@ object Test extends StoreReporterDirectTest {
val jar = "test1.jar"
compileCode(app1, jar)
- val output = ILoop.run(List(s":require ${testOutput.path}/$jar", "test.Test.test()"))
+ val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar", "test.Test.test()")
+ val output = ILoop.run(codeToRun, settings)
val lines = output.split("\n")
val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar")
val res2 = lines(lines.length-3).contains("testing...")
@@ -56,7 +66,8 @@ object Test extends StoreReporterDirectTest {
val jar2 = "test2.jar"
compileCode(app2, jar2)
- val output = ILoop.run(List(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar2"))
+ val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar2")
+ val output = ILoop.run(codeToRun, settings)
val lines = output.split("\n")
val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar")
val res2 = lines(lines.length-3).contains("test2.jar") && lines(lines.length-3).contains("existing classpath entries conflict")
@@ -71,7 +82,8 @@ object Test extends StoreReporterDirectTest {
val jar3 = "test3.jar"
compileCode(app3, jar3)
- val output = ILoop.run(List(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar3", "test.Test3.test()"))
+ val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar3", "test.Test3.test()")
+ val output = ILoop.run(codeToRun, settings)
val lines = output.split("\n")
val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar")
val res2 = lines(lines.length-3).contains("new object in existing package")
@@ -83,7 +95,8 @@ object Test extends StoreReporterDirectTest {
def test4(): Unit = {
// twice the same jar should be rejected
val jar1 = "test1.jar"
- val output = ILoop.run(List(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar1"))
+ val codeToRun = toCodeInSeparateLines(s":require ${testOutput.path}/$jar1", s":require ${testOutput.path}/$jar1")
+ val output = ILoop.run(codeToRun, settings)
val lines = output.split("\n")
val res1 = lines(4).contains("Added") && lines(4).contains("test1.jar")
val res2 = lines(lines.length-3).contains("test1.jar") && lines(lines.length-3).contains("existing classpath entries conflict")
@@ -98,4 +111,6 @@ object Test extends StoreReporterDirectTest {
test3()
test4()
}
+
+ def toCodeInSeparateLines(lines: String*): String = lines.map(_ + "\n").mkString
}