diff options
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/reflection-sync-potpourri.check | 0 | ||||
-rw-r--r-- | test/files/run/reflection-sync-potpourri.scala | 32 | ||||
-rw-r--r-- | test/files/run/reflection-sync-subtypes.check | 0 | ||||
-rw-r--r-- | test/files/run/reflection-sync-subtypes.scala | 20 | ||||
-rw-r--r-- | test/files/run/t6240-universe-code-gen.check | 0 | ||||
-rw-r--r-- | test/files/run/t6240-universe-code-gen.scala | 82 | ||||
-rw-r--r-- | test/files/run/t6240a.check | 1 | ||||
-rw-r--r-- | test/files/run/t6240a/StepOne.java | 41 | ||||
-rw-r--r-- | test/files/run/t6240a/StepTwo.scala | 7 | ||||
-rw-r--r-- | test/files/run/t6240a/Test.scala | 16 | ||||
-rw-r--r-- | test/files/run/t6240b.check | 1 | ||||
-rw-r--r-- | test/files/run/t6240b/StepOne.java | 41 | ||||
-rw-r--r-- | test/files/run/t6240b/StepThree.scala | 4 | ||||
-rw-r--r-- | test/files/run/t6240b/StepTwo.scala | 10 | ||||
-rw-r--r-- | test/files/run/t6240b/Test.scala | 16 | ||||
-rw-r--r-- | test/files/run/t7045.check | 2 | ||||
-rw-r--r-- | test/files/run/t7045.scala | 12 |
17 files changed, 285 insertions, 0 deletions
diff --git a/test/files/run/reflection-sync-potpourri.check b/test/files/run/reflection-sync-potpourri.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/reflection-sync-potpourri.check diff --git a/test/files/run/reflection-sync-potpourri.scala b/test/files/run/reflection-sync-potpourri.scala new file mode 100644 index 0000000000..0ad5f2ab66 --- /dev/null +++ b/test/files/run/reflection-sync-potpourri.scala @@ -0,0 +1,32 @@ +import scala.reflect.runtime.universe._ + +// this test checks that under heavily multithreaded conditions: +// 1) scala.reflect.runtime.universe, its rootMirror and definitions are initialized correctly +// 2) symbols are correctly materialized into PackageScopes (no dupes) +// 3) unpickling works okay even we unpickle the same symbol a lot of times + +object Test extends App { + def foo[T: TypeTag](x: T) = typeOf[T].toString + val n = 1000 + val rng = new scala.util.Random() + val types = List( + () => typeOf[java.lang.reflect.Method], + () => typeOf[java.lang.annotation.Annotation], + () => typeOf[scala.io.BufferedSource], + () => typeOf[scala.io.Codec]) + val perms = types.permutations.toList + def force(lazytpe: () => Type): String = { + lazytpe().typeSymbol.typeSignature + lazytpe().toString + } + val diceRolls = List.fill(n)(rng.nextInt(perms.length)) + val threads = (1 to n) map (i => new Thread(s"Reflector-$i") { + override def run(): Unit = { + val s1 = foo("42") + val s2 = perms(diceRolls(i - 1)).map(x => force(x)).sorted.mkString(", ") + assert(s1 == "java.lang.String") + assert(s2 == "java.lang.annotation.Annotation, java.lang.reflect.Method, scala.io.BufferedSource, scala.io.Codec") + } + }) + threads foreach (_.start) +}
\ No newline at end of file diff --git a/test/files/run/reflection-sync-subtypes.check b/test/files/run/reflection-sync-subtypes.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/reflection-sync-subtypes.check diff --git a/test/files/run/reflection-sync-subtypes.scala b/test/files/run/reflection-sync-subtypes.scala new file mode 100644 index 0000000000..7f75a464ac --- /dev/null +++ b/test/files/run/reflection-sync-subtypes.scala @@ -0,0 +1,20 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + val n = 1000 + val rng = new scala.util.Random() + val tasks = List( + () => typeOf[List[Int]] <:< typeOf[List[T] forSome { type T }], + () => typeOf[List[T] forSome { type T }] <:< typeOf[List[Any]], + () => typeOf[Map[Int, Object]] <:< typeOf[Iterable[(Int, String)]], + () => typeOf[Expr[Any] { val mirror: rootMirror.type }] <:< typeOf[Expr[List[List[List[Int]]]]{ val mirror: rootMirror.type }]) + val perms = tasks.permutations.toList + val diceRolls = List.fill(n)(rng.nextInt(perms.length)) + val threads = (1 to n) map (i => new Thread(s"Reflector-$i") { + override def run(): Unit = { + val result = perms(diceRolls(i - 1)).map(_()) + assert(result.sorted == List(false, false, true, true)) + } + }) + threads foreach (_.start) +}
\ No newline at end of file diff --git a/test/files/run/t6240-universe-code-gen.check b/test/files/run/t6240-universe-code-gen.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/t6240-universe-code-gen.check diff --git a/test/files/run/t6240-universe-code-gen.scala b/test/files/run/t6240-universe-code-gen.scala new file mode 100644 index 0000000000..84691639bd --- /dev/null +++ b/test/files/run/t6240-universe-code-gen.scala @@ -0,0 +1,82 @@ +import scala.tools.partest.nest.FileManager._ + +object Test extends App { + val cm = reflect.runtime.currentMirror + val u = cm.universe + import u._ + + val JavaUniverseTpe = typeOf[reflect.runtime.JavaUniverse] + val DefinitionsModule = JavaUniverseTpe.member(TermName("definitions")) + + def forceCode(prefix: String, tp: Type): String = { + def isLazyAccessorOrObject(sym: Symbol) = ( + (sym.isMethod && sym.asMethod.isLazy) + || sym.isModule + ) + val forcables = tp.members.sorted.filter(isLazyAccessorOrObject) + forcables.map { + sym => + val path = s"$prefix.${sym.name}" + " " + ( + if (sym.isPrivate || sym.isProtected) s"// inaccessible: $path" + else path + ) + }.mkString("\n") + } + + val code = + s"""|// Generated Code, validated by run/t6240-universe-code-gen.scala + |package scala.reflect + |package runtime + | + |trait JavaUniverseForce { self: runtime.JavaUniverse => + | def force() { + | Literal(Constant(42)).duplicate + | nme.flattenedName() + | nme.raw + | WeakTypeTag + | TypeTag + | TypeTag.Byte.tpe + | TypeTag.Short.tpe + | TypeTag.Char.tpe + | TypeTag.Int.tpe + | TypeTag.Long.tpe + | TypeTag.Float.tpe + | TypeTag.Double.tpe + | TypeTag.Boolean.tpe + | TypeTag.Unit.tpe + | TypeTag.Any.tpe + | TypeTag.AnyVal.tpe + | TypeTag.AnyRef.tpe + | TypeTag.Object.tpe + | TypeTag.Nothing.tpe + | TypeTag.Null.tpe + | + |${forceCode("this", JavaUniverseTpe)} + |${forceCode("definitions", DefinitionsModule.typeSignature)} + |${forceCode("refChecks", typeOf[scala.reflect.internal.transform.RefChecks])} + |${forceCode("uncurry", typeOf[scala.reflect.internal.transform.UnCurry])} + |${forceCode("erasure", typeOf[scala.reflect.internal.transform.Erasure])} + | } + |}""".stripMargin + + import java.io.File + val testFile = new File(sys.props("partest.test-path")) + val actualFile = new java.io.File(testFile.getParent + "/../../../src/reflect/scala/reflect/runtime/JavaUniverseForce.scala").getCanonicalFile + val actual = scala.io.Source.fromFile(actualFile) + val actualLines = actual.getLines.toList + val generatedLines = code.lines.toList + if (actualLines != generatedLines) { + val msg = s"""|${actualFile} must be updated. + |=========================================================== + | DIFF: + |=========================================================== + |${compareContents(actualLines, generatedLines)} + |=========================================================== + | NEW CONTENTS: + |=========================================================== + |${code}""".stripMargin + + assert(false, msg) + } +} diff --git a/test/files/run/t6240a.check b/test/files/run/t6240a.check new file mode 100644 index 0000000000..29f695b6f4 --- /dev/null +++ b/test/files/run/t6240a.check @@ -0,0 +1 @@ +StepTwo.type diff --git a/test/files/run/t6240a/StepOne.java b/test/files/run/t6240a/StepOne.java new file mode 100644 index 0000000000..7abd148d69 --- /dev/null +++ b/test/files/run/t6240a/StepOne.java @@ -0,0 +1,41 @@ +import java.io.File; +import java.io.IOException; +import java.lang.ClassNotFoundException; +import java.lang.NoSuchMethodException; +import java.lang.IllegalAccessException; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.MalformedURLException; + +public class StepOne { + public static void main(String[] args) + throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { + String[] launchPaths = System.getProperty("launch.classpath").split(":"); + + // move away StepThree + File tempDir = File.createTempFile("temp", Long.toString(System.nanoTime())); + System.setProperty("launch.step.three", tempDir.getAbsolutePath()); + tempDir.delete(); + tempDir.mkdir(); + File[] testClasses = new File(launchPaths[0]).listFiles(); + for (int i = 0; i < testClasses.length; i++) { + File testClass = testClasses[i]; + if (testClass.getPath().contains("StepThree")) { + File testClassMoved = new File(tempDir.getAbsolutePath() + "/" + testClass.getName()); + testClass.renameTo(testClassMoved); + } + } + + // launch StepTwo + URL[] launchURLs = new URL[launchPaths.length]; + for (int i = 0; i < launchPaths.length; i++) { + launchURLs[i] = new File(launchPaths[i]).toURL(); + } + URLClassLoader classLoader = new URLClassLoader(launchURLs, Object.class.getClassLoader()); + Class<?> stepTwo = classLoader.loadClass("StepTwo"); + Method main = stepTwo.getDeclaredMethod("main", String[].class); + main.invoke(null, (Object)(new String[]{})); + } +}
\ No newline at end of file diff --git a/test/files/run/t6240a/StepTwo.scala b/test/files/run/t6240a/StepTwo.scala new file mode 100644 index 0000000000..fc3221921d --- /dev/null +++ b/test/files/run/t6240a/StepTwo.scala @@ -0,0 +1,7 @@ +import java.io.File +import java.net.URLClassLoader + +object StepTwo extends App { + import scala.reflect.runtime.universe._ + println(typeOf[StepTwo.type]) +}
\ No newline at end of file diff --git a/test/files/run/t6240a/Test.scala b/test/files/run/t6240a/Test.scala new file mode 100644 index 0000000000..6ae43c4809 --- /dev/null +++ b/test/files/run/t6240a/Test.scala @@ -0,0 +1,16 @@ +import java.io.File +import scala.sys.process._ + +object Test extends App { + def prop(key: String) = { + val value = System.getProperties.getProperty(key) + assert(value != null, key) + value + } + val testClassesDir = prop("partest.output") + assert(new File(testClassesDir).exists, testClassesDir) + val fullTestClassesClasspath = testClassesDir + prop("path.separator") + prop("java.class.path") + val javaBinary = if (new File(prop("javacmd")).isAbsolute) prop("javacmd") else prop("java.home") + "/bin/" + prop("javacmd") + assert(new File(javaBinary).exists, javaBinary) + List(javaBinary, "-cp", testClassesDir, "-Dlaunch.classpath=" + fullTestClassesClasspath, "StepOne").! +}
\ No newline at end of file diff --git a/test/files/run/t6240b.check b/test/files/run/t6240b.check new file mode 100644 index 0000000000..255836105a --- /dev/null +++ b/test/files/run/t6240b.check @@ -0,0 +1 @@ +StepThree.type diff --git a/test/files/run/t6240b/StepOne.java b/test/files/run/t6240b/StepOne.java new file mode 100644 index 0000000000..7abd148d69 --- /dev/null +++ b/test/files/run/t6240b/StepOne.java @@ -0,0 +1,41 @@ +import java.io.File; +import java.io.IOException; +import java.lang.ClassNotFoundException; +import java.lang.NoSuchMethodException; +import java.lang.IllegalAccessException; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.net.URL; +import java.net.URLClassLoader; +import java.net.MalformedURLException; + +public class StepOne { + public static void main(String[] args) + throws MalformedURLException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException { + String[] launchPaths = System.getProperty("launch.classpath").split(":"); + + // move away StepThree + File tempDir = File.createTempFile("temp", Long.toString(System.nanoTime())); + System.setProperty("launch.step.three", tempDir.getAbsolutePath()); + tempDir.delete(); + tempDir.mkdir(); + File[] testClasses = new File(launchPaths[0]).listFiles(); + for (int i = 0; i < testClasses.length; i++) { + File testClass = testClasses[i]; + if (testClass.getPath().contains("StepThree")) { + File testClassMoved = new File(tempDir.getAbsolutePath() + "/" + testClass.getName()); + testClass.renameTo(testClassMoved); + } + } + + // launch StepTwo + URL[] launchURLs = new URL[launchPaths.length]; + for (int i = 0; i < launchPaths.length; i++) { + launchURLs[i] = new File(launchPaths[i]).toURL(); + } + URLClassLoader classLoader = new URLClassLoader(launchURLs, Object.class.getClassLoader()); + Class<?> stepTwo = classLoader.loadClass("StepTwo"); + Method main = stepTwo.getDeclaredMethod("main", String[].class); + main.invoke(null, (Object)(new String[]{})); + } +}
\ No newline at end of file diff --git a/test/files/run/t6240b/StepThree.scala b/test/files/run/t6240b/StepThree.scala new file mode 100644 index 0000000000..210795d68f --- /dev/null +++ b/test/files/run/t6240b/StepThree.scala @@ -0,0 +1,4 @@ +object StepThree extends App { + import scala.reflect.runtime.universe._ + println(typeOf[StepThree.type]) +}
\ No newline at end of file diff --git a/test/files/run/t6240b/StepTwo.scala b/test/files/run/t6240b/StepTwo.scala new file mode 100644 index 0000000000..88e46492e3 --- /dev/null +++ b/test/files/run/t6240b/StepTwo.scala @@ -0,0 +1,10 @@ +import java.io.File +import java.net.URLClassLoader + +object StepTwo extends App { + val classes = new File(System.getProperty("launch.step.three")) + val cl = new URLClassLoader(Array(classes.toURI.toURL), getClass.getClassLoader) + val stepThree = cl.loadClass("StepThree") + val main = stepThree.getDeclaredMethod("main", classOf[Array[String]]) + main.invoke(null, Array[String]()) +}
\ No newline at end of file diff --git a/test/files/run/t6240b/Test.scala b/test/files/run/t6240b/Test.scala new file mode 100644 index 0000000000..6ae43c4809 --- /dev/null +++ b/test/files/run/t6240b/Test.scala @@ -0,0 +1,16 @@ +import java.io.File +import scala.sys.process._ + +object Test extends App { + def prop(key: String) = { + val value = System.getProperties.getProperty(key) + assert(value != null, key) + value + } + val testClassesDir = prop("partest.output") + assert(new File(testClassesDir).exists, testClassesDir) + val fullTestClassesClasspath = testClassesDir + prop("path.separator") + prop("java.class.path") + val javaBinary = if (new File(prop("javacmd")).isAbsolute) prop("javacmd") else prop("java.home") + "/bin/" + prop("javacmd") + assert(new File(javaBinary).exists, javaBinary) + List(javaBinary, "-cp", testClassesDir, "-Dlaunch.classpath=" + fullTestClassesClasspath, "StepOne").! +}
\ No newline at end of file diff --git a/test/files/run/t7045.check b/test/files/run/t7045.check new file mode 100644 index 0000000000..28134535c8 --- /dev/null +++ b/test/files/run/t7045.check @@ -0,0 +1,2 @@ +D with C +D with C diff --git a/test/files/run/t7045.scala b/test/files/run/t7045.scala new file mode 100644 index 0000000000..f41baca05e --- /dev/null +++ b/test/files/run/t7045.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +class C +class D { self: C => } + +object Test extends App { + val d = cm.staticClass("D") + println(d.selfType) + d.typeSignature + println(d.selfType) +}
\ No newline at end of file |