diff options
Diffstat (limited to 'test')
17 files changed, 176 insertions, 267 deletions
diff --git a/test/files/pos/t9397.scala b/test/files/pos/t9397.scala new file mode 100644 index 0000000000..3dbc6591d3 --- /dev/null +++ b/test/files/pos/t9397.scala @@ -0,0 +1,12 @@ +package foo.scala + +import scala.reflect.runtime.universe._ + +object Foo { + + def bar[T: TypeTag]() { + } + + import foo._ + bar[String]() +} diff --git a/test/files/run/reify_printf.scala b/test/files/run/reify_printf.scala index c4ade79837..099a353e89 100644 --- a/test/files/run/reify_printf.scala +++ b/test/files/run/reify_printf.scala @@ -6,7 +6,6 @@ import scala.tools.reflect.ToolBox import scala.reflect.api._ import scala.reflect.api.Trees import scala.reflect.internal.Types -import scala.util.matching.Regex object Test extends App { //val output = new ByteArrayOutputStream() diff --git a/test/files/run/repl-implicits-nopredef.check b/test/files/run/repl-implicits-nopredef.check new file mode 100644 index 0000000000..a849801bb4 --- /dev/null +++ b/test/files/run/repl-implicits-nopredef.check @@ -0,0 +1,5 @@ + +scala> :implicits +No implicits have been imported. + +scala> :quit
\ No newline at end of file diff --git a/test/files/run/repl-implicits-nopredef.scala b/test/files/run/repl-implicits-nopredef.scala new file mode 100644 index 0000000000..8a451b0c52 --- /dev/null +++ b/test/files/run/repl-implicits-nopredef.scala @@ -0,0 +1,10 @@ +import scala.tools.partest.ReplTest +import scala.tools.nsc.Settings + +object Test extends ReplTest { + override def transformSettings(settings: Settings): Settings = { + settings.nopredef.value = true + settings + } + def code = ":implicits" +} diff --git a/test/files/run/repl-implicits.check b/test/files/run/repl-implicits.check new file mode 100644 index 0000000000..6e80cc8799 --- /dev/null +++ b/test/files/run/repl-implicits.check @@ -0,0 +1,5 @@ + +scala> :implicits +No implicits have been imported other than those in Predef. + +scala> :quit
\ No newline at end of file diff --git a/test/files/run/repl-implicits.scala b/test/files/run/repl-implicits.scala new file mode 100644 index 0000000000..ca8e16e683 --- /dev/null +++ b/test/files/run/repl-implicits.scala @@ -0,0 +1,5 @@ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = ":implicits" +} diff --git a/test/files/run/t6502.scala b/test/files/run/t6502.scala index dffb0e2f98..cb2b3ff449 100644 --- a/test/files/run/t6502.scala +++ b/test/files/run/t6502.scala @@ -1,6 +1,5 @@ import scala.tools.nsc.Settings import scala.tools.nsc.interpreter.{ ILoop, replProps } -import scala.tools.nsc.settings.ClassPathRepresentationType import scala.tools.partest._ object Test extends StoreReporterDirectTest { @@ -14,14 +13,6 @@ object Test extends StoreReporterDirectTest { compileString(newCompiler("-cp", classpath, "-d", s"${testOutput.path}/$jarFileName"))(code) } - var classPathKind: String = "" - - override def settings = { - val settings = new Settings - settings.YclasspathImpl.value = classPathKind - settings - } - def app1 = """ package test @@ -155,7 +146,7 @@ object Test extends StoreReporterDirectTest { assert(output.contains("created test6.Z"), output) } - def testAll(): Unit = { + def show(): Unit = { test1() test2() test3() @@ -163,11 +154,4 @@ object Test extends StoreReporterDirectTest { test5() test6() } - - def show(): Unit = { - classPathKind = ClassPathRepresentationType.Flat - testAll() - classPathKind = ClassPathRepresentationType.Recursive - testAll() - } } diff --git a/test/files/run/various-flat-classpath-types.scala b/test/files/run/various-flat-classpath-types.scala index d39019e885..bc54ffb6cc 100644 --- a/test/files/run/various-flat-classpath-types.scala +++ b/test/files/run/various-flat-classpath-types.scala @@ -5,7 +5,7 @@ import java.io.{File => JFile, FileInputStream, FileOutputStream} import java.util.zip.{ZipEntry, ZipOutputStream} import scala.reflect.io.{Directory, File} -import scala.tools.nsc.classpath.FlatClassPath.RootPackage +import scala.tools.nsc.util.ClassPath.RootPackage import scala.tools.nsc.classpath.PackageNameUtils import scala.tools.nsc.io.Jar @@ -80,7 +80,6 @@ object Test { private val compiler = new scala.tools.nsc.MainClass private val appRunner = new scala.tools.nsc.MainGenericRunner - private val classPathImplFlag = "-YclasspathImpl:flat" private val javaClassPath = sys.props("java.class.path") // creates a test dir in a temporary dir containing compiled files of this test @@ -166,13 +165,13 @@ object Test { val classPath = mkPath(javaClassPath, binDir.path, zipsDir.path + "/Bin.zip", jarsDir.path + "/Bin.jar") val sourcePath = mkPath(srcDir.path, zipsDir.path + "/Src.zip", jarsDir.path + "/Src.jar") - compiler.process(Array(classPathImplFlag, "-cp", classPath, "-sourcepath", sourcePath, + compiler.process(Array("-cp", classPath, "-sourcepath", sourcePath, "-d", outDir.path, s"${srcDir.path}/Main.scala")) } private def runApp(): Unit = { val classPath = mkPath(javaClassPath, outDir.path, binDir.path, zipsDir.path + "/Bin.zip", jarsDir.path + "/Bin.jar") - appRunner.process(Array(classPathImplFlag, "-cp", classPath, "Main")) + appRunner.process(Array("-cp", classPath, "Main")) } private def createStandardSrcHierarchy(baseFileName: String): Unit = @@ -200,7 +199,7 @@ object Test { private def compileSrc(baseFileName: String, destination: JFile = outDir): Unit = { val srcDirPath = srcDir.path - compiler.process(Array(classPathImplFlag, "-cp", javaClassPath, "-d", destination.path, + compiler.process(Array("-cp", javaClassPath, "-d", destination.path, s"$srcDirPath/$baseFileName.scala", s"$srcDirPath/nested/Nested$baseFileName.scala")) } diff --git a/test/junit/scala/collection/mutable/PriorityQueueTest.scala b/test/junit/scala/collection/mutable/PriorityQueueTest.scala index a14f1bf4c8..faedcf11f0 100644 --- a/test/junit/scala/collection/mutable/PriorityQueueTest.scala +++ b/test/junit/scala/collection/mutable/PriorityQueueTest.scala @@ -14,6 +14,12 @@ class PriorityQueueTest { priorityQueue.enqueue(elements :_*) @Test + def orderingReverseReverse() { + val pq = new mutable.PriorityQueue[Nothing]()((_,_)=>42) + assert(pq.ord eq pq.reverse.reverse.ord) + } + + @Test def canSerialize() { val outputStream = new ByteArrayOutputStream() new ObjectOutputStream(outputStream).writeObject(priorityQueue) @@ -27,6 +33,7 @@ class PriorityQueueTest { val objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes)) val deserializedPriorityQueue = objectInputStream.readObject().asInstanceOf[PriorityQueue[Int]] + //correct sequencing is also tested here: assert(deserializedPriorityQueue.dequeueAll == elements.sorted.reverse) } } diff --git a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala index fe43ed2f6a..389e5b2ead 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/CodeGenTools.scala @@ -206,6 +206,12 @@ object CodeGenTools { assert(actual == expected, s"\nFound : ${quote(actual)}\nExpected: ${quote(expected)}") } + def assertNoIndy(m: Method): Unit = assertNoIndy(m.instructions) + def assertNoIndy(l: List[Instruction]) = { + val indy = l collect { case i: InvokeDynamic => i } + assert(indy.isEmpty, indy) + } + def getSingleMethod(classNode: ClassNode, name: String): Method = convertMethod(classNode.methods.asScala.toList.find(_.name == name).get) diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala index 5090e9c83b..1597c75a7e 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala @@ -103,12 +103,12 @@ class InlineWarningTest extends ClearAfterClass { val warns = List( """failed to determine if bar should be inlined: |The method bar()I could not be found in the class A or any of its parents. - |Note that the following parent classes are defined in Java sources (mixed compilation), no bytecode is available: A""".stripMargin, + |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, """B::flop()I is annotated @inline but could not be inlined: |Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: |The method bar()I could not be found in the class A or any of its parents. - |Note that the following parent classes are defined in Java sources (mixed compilation), no bytecode is available: A""".stripMargin) + |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin) var c = 0 val List(b) = compile(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; warns.tail.exists(i.msg contains _)}) diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala index 1765a355fd..e2a495fb2b 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -428,7 +428,7 @@ class InlinerTest extends ClearAfterClass { """B::flop()I is annotated @inline but could not be inlined: |Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: |The method bar()I could not be found in the class A or any of its parents. - |Note that the following parent classes are defined in Java sources (mixed compilation), no bytecode is available: A""".stripMargin + |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin var c = 0 val List(b) = compile(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; i.msg contains warn}) @@ -833,7 +833,7 @@ class InlinerTest extends ClearAfterClass { val warn = """failed to determine if <init> should be inlined: |The method <init>()V could not be found in the class A$Inner or any of its parents. - |Note that the following parent classes could not be found on the classpath: A$Inner""".stripMargin + |Note that the parent class A$Inner could not be found on the classpath.""".stripMargin var c = 0 @@ -955,18 +955,12 @@ class InlinerTest extends ClearAfterClass { val List(c, _, _) = compile(code) val t1 = getSingleMethod(c, "t1") - assert(t1.instructions forall { // indy is eliminated by push-pop - case _: InvokeDynamic => false - case _ => true - }) + assertNoIndy(t1) // the indy call is inlined into t, and the closure elimination rewrites the closure invocation to the body method assertInvoke(t1, "C", "C$$$anonfun$2") val t2 = getSingleMethod(c, "t2") - assert(t2.instructions forall { // indy is eliminated by push-pop - case _: InvokeDynamic => false - case _ => true - }) + assertNoIndy(t2) assertInvoke(t2, "M$", "M$$$anonfun$1") } @@ -1492,4 +1486,31 @@ class InlinerTest extends ClearAfterClass { // the forwarder C.f is inlined, so there's no invocation assertSameSummary(getSingleMethod(c, "f"), List(ICONST_1, IRETURN)) } + + @Test + def sd140(): Unit = { + val code = + """trait T { @inline def f = 0 } + |trait U extends T { @inline override def f = 1 } + |trait V extends T { def m = 0 } + |final class K extends V with U { override def m = super[V].m } + |class C { def t = (new K).f } + """.stripMargin + val c :: _ = compile(code) + assertSameSummary(getSingleMethod(c, "t"), List(NEW, "<init>", ICONST_1, IRETURN)) // ICONST_1, U.f is inlined (not T.f) + } + + @Test + def inlineArrayForeach(): Unit = { + val code = + """class C { + | def consume(x: Int) = () + | def t(a: Array[Int]): Unit = a foreach consume + |} + """.stripMargin + val List(c) = compile(code) + val t = getSingleMethod(c, "t") + assertNoIndy(t) + assertInvoke(t, "C", "C$$$anonfun$1") + } } diff --git a/test/junit/scala/tools/nsc/classpath/AggregateFlatClassPathTest.scala b/test/junit/scala/tools/nsc/classpath/AggregateClassPathTest.scala index 9a004d5e0e..a7aca31ee3 100644 --- a/test/junit/scala/tools/nsc/classpath/AggregateFlatClassPathTest.scala +++ b/test/junit/scala/tools/nsc/classpath/AggregateClassPathTest.scala @@ -10,6 +10,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import scala.reflect.io.VirtualFile import scala.tools.nsc.io.AbstractFile +import scala.tools.nsc.util.ClassPath /** * Tests whether AggregateFlatClassPath returns correct entries taken from @@ -17,14 +18,14 @@ import scala.tools.nsc.io.AbstractFile * (in the case of the repeated entry for a class or a source it returns the first one). */ @RunWith(classOf[JUnit4]) -class AggregateFlatClassPathTest { +class AggregateClassPathTest { - private class TestFlatClassPath extends FlatClassPath { + private abstract class TestClassPathBase extends ClassPath { override def packages(inPackage: String): Seq[PackageEntry] = unsupported override def sources(inPackage: String): Seq[SourceFileEntry] = unsupported override def classes(inPackage: String): Seq[ClassFileEntry] = unsupported - override def list(inPackage: String): FlatClassPathEntries = unsupported + override def list(inPackage: String): ClassPathEntries = unsupported override def findClassFile(name: String): Option[AbstractFile] = unsupported override def asClassPathStrings: Seq[String] = unsupported @@ -32,7 +33,7 @@ class AggregateFlatClassPathTest { override def asURLs: Seq[URL] = unsupported } - private case class TestClassPath(virtualPath: String, classesInPackage: EntryNamesInPackage*) extends TestFlatClassPath { + private case class TestClassPath(virtualPath: String, classesInPackage: EntryNamesInPackage*) extends TestClassPathBase { override def classes(inPackage: String): Seq[ClassFileEntry] = for { @@ -43,10 +44,10 @@ class AggregateFlatClassPathTest { override def sources(inPackage: String): Seq[SourceFileEntry] = Nil // we'll ignore packages - override def list(inPackage: String): FlatClassPathEntries = FlatClassPathEntries(Nil, classes(inPackage)) + override def list(inPackage: String): ClassPathEntries = ClassPathEntries(Nil, classes(inPackage)) } - private case class TestSourcePath(virtualPath: String, sourcesInPackage: EntryNamesInPackage*) extends TestFlatClassPath { + private case class TestSourcePath(virtualPath: String, sourcesInPackage: EntryNamesInPackage*) extends TestClassPathBase { override def sources(inPackage: String): Seq[SourceFileEntry] = for { @@ -57,7 +58,7 @@ class AggregateFlatClassPathTest { override def classes(inPackage: String): Seq[ClassFileEntry] = Nil // we'll ignore packages - override def list(inPackage: String): FlatClassPathEntries = FlatClassPathEntries(Nil, sources(inPackage)) + override def list(inPackage: String): ClassPathEntries = ClassPathEntries(Nil, sources(inPackage)) } private case class EntryNamesInPackage(inPackage: String)(val names: String*) @@ -88,7 +89,7 @@ class AggregateFlatClassPathTest { private def virtualFile(pathPrefix: String, inPackage: String, fileName: String, extension: String) = { val packageDirs = - if (inPackage == FlatClassPath.RootPackage) "" + if (inPackage == ClassPath.RootPackage) "" else inPackage.split('.').mkString("/", "/", "") new VirtualFile(fileName + extension, s"$pathPrefix$packageDirs/$fileName$extension") } @@ -101,12 +102,12 @@ class AggregateFlatClassPathTest { TestSourcePath(dir2, EntryNamesInPackage(pkg3)("J", "K", "L")) ) - AggregateFlatClassPath(partialClassPaths) + AggregateClassPath(partialClassPaths) } @Test def testGettingPackages: Unit = { - case class ClassPathWithPackages(packagesInPackage: EntryNamesInPackage*) extends TestFlatClassPath { + case class ClassPathWithPackages(packagesInPackage: EntryNamesInPackage*) extends TestClassPathBase { override def packages(inPackage: String): Seq[PackageEntry] = packagesInPackage.find(_.inPackage == inPackage).map(_.names).getOrElse(Nil) map PackageEntryImpl } @@ -115,7 +116,7 @@ class AggregateFlatClassPathTest { ClassPathWithPackages(EntryNamesInPackage(pkg1)("pkg1.c", "pkg1.b", "pkg1.a"), EntryNamesInPackage(pkg2)("pkg2.d", "pkg2.a", "pkg2.e")) ) - val cp = AggregateFlatClassPath(partialClassPaths) + val cp = AggregateClassPath(partialClassPaths) val packagesInPkg1 = Seq("pkg1.a", "pkg1.d", "pkg1.f", "pkg1.c", "pkg1.b") assertEquals(packagesInPkg1, cp.packages(pkg1).map(_.name)) @@ -156,7 +157,7 @@ class AggregateFlatClassPathTest { TestClassPath(dir4, EntryNamesInPackage(pkg2)("A", "H", "I")), TestClassPath(dir2, EntryNamesInPackage(pkg3)("J", "K", "L")) ) - val cp = AggregateFlatClassPath(partialClassPaths) + val cp = AggregateClassPath(partialClassPaths) val sourcesInPkg1 = Seq(sourceFileEntry(dir2, pkg1, "C"), sourceFileEntry(dir2, pkg1, "B"), @@ -190,7 +191,7 @@ class AggregateFlatClassPathTest { ) assertEquals(classesAndSourcesInPkg1, cp.list(pkg1).classesAndSources) - assertEquals(FlatClassPathEntries(Nil, Nil), cp.list(nonexistingPkg)) + assertEquals(ClassPathEntries(Nil, Nil), cp.list(nonexistingPkg)) } @Test diff --git a/test/junit/scala/tools/nsc/classpath/FlatClassPathResolverTest.scala b/test/junit/scala/tools/nsc/classpath/PathResolverBaseTest.scala index 5dee488285..d3d4289d8b 100644 --- a/test/junit/scala/tools/nsc/classpath/FlatClassPathResolverTest.scala +++ b/test/junit/scala/tools/nsc/classpath/PathResolverBaseTest.scala @@ -9,20 +9,17 @@ import org.junit._ import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import scala.annotation.tailrec -import scala.tools.nsc.io.AbstractFile import scala.tools.nsc.util.ClassPath import scala.tools.nsc.Settings -import scala.tools.util.FlatClassPathResolver import scala.tools.util.PathResolver @RunWith(classOf[JUnit4]) -class FlatClassPathResolverTest { +class PathResolverBaseTest { val tempDir = new TemporaryFolder() - private val packagesToTest = List(FlatClassPath.RootPackage, "scala", "scala.reflect", "scala.reflect.io") - private val classFilesToFind = List("scala.tools.util.FlatClassPathResolver", + private val packagesToTest = List(ClassPath.RootPackage, "scala", "scala.reflect", "scala.reflect.io") + private val classFilesToFind = List("scala.tools.util.PathResolver", "scala.reflect.io.AbstractFile", "scala.collection.immutable.List", "scala.Option", @@ -60,7 +57,7 @@ class FlatClassPathResolverTest { def deleteTempDir: Unit = tempDir.delete() private def createFlatClassPath(settings: Settings) = - new FlatClassPathResolver(settings).result + new PathResolver(settings).result @Test def testEntriesFromListOperationAgainstSeparateMethods: Unit = { @@ -70,7 +67,7 @@ class FlatClassPathResolverTest { val packages = classPath.packages(inPackage) val classes = classPath.classes(inPackage) val sources = classPath.sources(inPackage) - val FlatClassPathEntries(packagesFromList, classesAndSourcesFromList) = classPath.list(inPackage) + val ClassPathEntries(packagesFromList, classesAndSourcesFromList) = classPath.list(inPackage) val packageNames = packages.map(_.name).sorted val packageNamesFromList = packagesFromList.map(_.name).sorted @@ -96,52 +93,6 @@ class FlatClassPathResolverTest { } @Test - def testCreatedEntriesAgainstRecursiveClassPath: Unit = { - val flatClassPath = createFlatClassPath(settings) - val recursiveClassPath = new PathResolver(settings).result - - def compareEntriesInPackage(inPackage: String): Unit = { - - @tailrec - def traverseToPackage(packageNameParts: Seq[String], cp: ClassPath[AbstractFile]): ClassPath[AbstractFile] = { - packageNameParts match { - case Nil => cp - case h :: t => - cp.packages.find(_.name == h) match { - case Some(nestedCp) => traverseToPackage(t, nestedCp) - case _ => throw new Exception(s"There's no package $inPackage in recursive classpath - error when searching for '$h'") - } - } - } - - val packageNameParts = if (inPackage == FlatClassPath.RootPackage) Nil else inPackage.split('.').toList - val recursiveClassPathInPackage = traverseToPackage(packageNameParts, recursiveClassPath) - - val flatCpPackages = flatClassPath.packages(inPackage).map(_.name) - val pkgPrefix = PackageNameUtils.packagePrefix(inPackage) - val recursiveCpPackages = recursiveClassPathInPackage.packages.map(pkgPrefix + _.name) - assertEquals(s"Packages in package '$inPackage' on flat cp should be the same as on the recursive cp", - recursiveCpPackages, flatCpPackages) - - val flatCpSources = flatClassPath.sources(inPackage).map(_.name).sorted - val recursiveCpSources = recursiveClassPathInPackage.classes - .filter(_.source.nonEmpty) - .map(_.name).sorted - assertEquals(s"Source entries in package '$inPackage' on flat cp should be the same as on the recursive cp", - recursiveCpSources, flatCpSources) - - val flatCpClasses = flatClassPath.classes(inPackage).map(_.name).sorted - val recursiveCpClasses = recursiveClassPathInPackage.classes - .filter(_.binary.nonEmpty) - .map(_.name).sorted - assertEquals(s"Class entries in package '$inPackage' on flat cp should be the same as on the recursive cp", - recursiveCpClasses, flatCpClasses) - } - - packagesToTest foreach compareEntriesInPackage - } - - @Test def testFindClassFile: Unit = { val classPath = createFlatClassPath(settings) classFilesToFind foreach { className => diff --git a/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala b/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala index 812c298c48..8cc7aefdd3 100644 --- a/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala +++ b/test/junit/scala/tools/nsc/symtab/SymbolTableForUnitTesting.scala @@ -3,11 +3,8 @@ package symtab import scala.reflect.ClassTag import scala.reflect.internal.{NoPhase, Phase, SomePhase} -import scala.tools.nsc.classpath.FlatClassPath -import scala.tools.nsc.settings.ClassPathRepresentationType -import scala.tools.util.FlatClassPathResolver import scala.tools.util.PathResolver -import util.{ClassFileLookup, ClassPath} +import util.ClassPath import io.AbstractFile /** @@ -30,8 +27,7 @@ class SymbolTableForUnitTesting extends SymbolTable { override def isCompilerUniverse: Boolean = true - def classPath = platform.classPath - def flatClassPath: FlatClassPath = platform.flatClassPath + def classPath: ClassPath = platform.classPath object platform extends backend.Platform { val symbolTable: SymbolTableForUnitTesting.this.type = SymbolTableForUnitTesting.this @@ -39,22 +35,12 @@ class SymbolTableForUnitTesting extends SymbolTable { def platformPhases: List[SubComponent] = Nil - lazy val classPath: ClassPath[AbstractFile] = { - assert(settings.YclasspathImpl.value == ClassPathRepresentationType.Recursive, - "It's not possible to use the recursive classpath representation, when it's not the chosen classpath scanning method") - new PathResolver(settings).result - } - - private[nsc] lazy val flatClassPath: FlatClassPath = { - assert(settings.YclasspathImpl.value == ClassPathRepresentationType.Flat, - "It's not possible to use the flat classpath representation, when it's not the chosen classpath scanning method") - new FlatClassPathResolver(settings).result - } + private[nsc] lazy val classPath: ClassPath = new PathResolver(settings).result def isMaybeBoxed(sym: Symbol): Boolean = ??? def needCompile(bin: AbstractFile, src: AbstractFile): Boolean = ??? def externalEquals: Symbol = ??? - def updateClassPath(subst: Map[ClassFileLookup[AbstractFile], ClassFileLookup[AbstractFile]]): Unit = ??? + def updateClassPath(subst: Map[ClassPath, ClassPath]): Unit = ??? } object loaders extends symtab.SymbolLoaders { @@ -69,10 +55,7 @@ class SymbolTableForUnitTesting extends SymbolTable { class GlobalMirror extends Roots(NoSymbol) { val universe: SymbolTableForUnitTesting.this.type = SymbolTableForUnitTesting.this - def rootLoader: LazyType = settings.YclasspathImpl.value match { - case ClassPathRepresentationType.Flat => new loaders.PackageLoaderUsingFlatClassPath(FlatClassPath.RootPackage, flatClassPath) - case ClassPathRepresentationType.Recursive => new loaders.PackageLoader(classPath) - } + def rootLoader: LazyType = new loaders.PackageLoader(ClassPath.RootPackage, classPath) override def toString = "compiler mirror" } diff --git a/test/junit/scala/tools/nsc/util/ClassPathImplComparator.scala b/test/junit/scala/tools/nsc/util/ClassPathImplComparator.scala deleted file mode 100644 index f2926e3e17..0000000000 --- a/test/junit/scala/tools/nsc/util/ClassPathImplComparator.scala +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2014 Contributor. All rights reserved. - */ -package scala.tools.nsc.util - -import scala.reflect.io.AbstractFile -import scala.tools.nsc.Settings -import scala.tools.nsc.settings.ClassPathRepresentationType -import scala.tools.util.PathResolverFactory - -/** - * Simple application to compare efficiency of the recursive and the flat classpath representations - */ -object ClassPathImplComparator { - - private class TestSettings extends Settings { - val checkClasses = PathSetting("-checkClasses", "Specify names of classes which should be found separated with ;", "") - val requiredIterations = IntSetting("-requiredIterations", - "Repeat tests specified number of times (to check e.g. impact of caches)", 1, Some((1, Int.MaxValue)), (_: String) => None) - val cpCreationRepetitions = IntSetting("-cpCreationRepetitions", - "Repeat tests specified number of times (to check e.g. impact of caches)", 1, Some((1, Int.MaxValue)), (_: String) => None) - val cpLookupRepetitions = IntSetting("-cpLookupRepetitions", - "Repeat tests specified number of times (to check e.g. impact of caches)", 1, Some((1, Int.MaxValue)), (_: String) => None) - } - - private class DurationStats(name: String) { - private var sum = 0L - private var iterations = 0 - - def noteMeasuredTime(millis: Long): Unit = { - sum += millis - iterations += 1 - } - - def printResults(): Unit = { - val avg = if (iterations == 0) 0 else sum.toDouble / iterations - println(s"$name - total duration: $sum ms; iterations: $iterations; avg: $avg ms") - } - } - - private lazy val defaultClassesToFind = List( - "scala.collection.immutable.List", - "scala.Option", - "scala.Int", - "scala.collection.immutable.Vector", - "scala.util.hashing.MurmurHash3" - ) - - private val oldCpCreationStats = new DurationStats("Old classpath - create") - private val oldCpSearchingStats = new DurationStats("Old classpath - search") - - private val flatCpCreationStats = new DurationStats("Flat classpath - create") - private val flatCpSearchingStats = new DurationStats("Flat classpath - search") - - def main(args: Array[String]): Unit = { - - if (args contains "-help") - usage() - else { - val oldCpSettings = loadSettings(args.toList, ClassPathRepresentationType.Recursive) - val flatCpSettings = loadSettings(args.toList, ClassPathRepresentationType.Flat) - - val classesToCheck = oldCpSettings.checkClasses.value - val classesToFind = - if (classesToCheck.isEmpty) defaultClassesToFind - else classesToCheck.split(";").toList - - def doTest(classPath: => ClassFileLookup[AbstractFile], cpCreationStats: DurationStats, cpSearchingStats: DurationStats, - cpCreationRepetitions: Int, cpLookupRepetitions: Int)= { - - def createClassPaths() = (1 to cpCreationRepetitions).map(_ => classPath).last - def testClassLookup(cp: ClassFileLookup[AbstractFile]): Boolean = (1 to cpCreationRepetitions).foldLeft(true) { - case (a, _) => a && checkExistenceOfClasses(classesToFind)(cp) - } - - val cp = withMeasuredTime("Creating classpath", createClassPaths(), cpCreationStats) - val result = withMeasuredTime("Searching for specified classes", testClassLookup(cp), cpSearchingStats) - println(s"The end of the test case. All expected classes found = $result \n") - } - - (1 to oldCpSettings.requiredIterations.value) foreach { iteration => - if (oldCpSettings.requiredIterations.value > 1) - println(s"Iteration no $iteration") - - println("Recursive (old) classpath representation:") - doTest(PathResolverFactory.create(oldCpSettings).result, oldCpCreationStats, oldCpSearchingStats, - oldCpSettings.cpCreationRepetitions.value, oldCpSettings.cpLookupRepetitions.value) - - println("Flat classpath representation:") - doTest(PathResolverFactory.create(flatCpSettings).result, flatCpCreationStats, flatCpSearchingStats, - flatCpSettings.cpCreationRepetitions.value, flatCpSettings.cpLookupRepetitions.value) - } - - if (oldCpSettings.requiredIterations.value > 1) { - println("\nOld classpath - summary") - oldCpCreationStats.printResults() - oldCpSearchingStats.printResults() - - println("\nFlat classpath - summary") - flatCpCreationStats.printResults() - flatCpSearchingStats.printResults() - } - } - } - - /** - * Prints usage information - */ - private def usage(): Unit = - println("""Use classpath and sourcepath options like in the case of e.g. 'scala' command. - | There are also two additional options: - | -checkClasses <semicolon separated class names> Specify names of classes which should be found - | -requiredIterations <int value> Repeat tests specified count of times (to check e.g. impact of caches) - | Note: Option -YclasspathImpl will be set automatically for each case. - """.stripMargin.trim) - - private def loadSettings(args: List[String], implType: String) = { - val settings = new TestSettings() - settings.processArguments(args, processAll = true) - settings.YclasspathImpl.value = implType - if (settings.classpath.isDefault) - settings.classpath.value = sys.props("java.class.path") - settings - } - - private def withMeasuredTime[T](operationName: String, f: => T, durationStats: DurationStats): T = { - val startTime = System.currentTimeMillis() - val res = f - val elapsed = System.currentTimeMillis() - startTime - durationStats.noteMeasuredTime(elapsed) - println(s"$operationName - elapsed $elapsed ms") - res - } - - private def checkExistenceOfClasses(classesToCheck: Seq[String])(classPath: ClassFileLookup[AbstractFile]): Boolean = - classesToCheck.foldLeft(true) { - case (res, classToCheck) => - val found = classPath.findClass(classToCheck).isDefined - if (!found) - println(s"Class $classToCheck not found") // of course in this case the measured time will be affected by IO operation - found - } -} diff --git a/test/junit/scala/util/matching/RegexTest.scala b/test/junit/scala/util/matching/RegexTest.scala index 5b13397d6a..06d0445e1c 100644 --- a/test/junit/scala/util/matching/RegexTest.scala +++ b/test/junit/scala/util/matching/RegexTest.scala @@ -6,6 +6,8 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import scala.tools.testing.AssertUtil._ + @RunWith(classOf[JUnit4]) class RegexTest { @Test def t8022CharSequence(): Unit = { @@ -44,4 +46,66 @@ class RegexTest { } assertEquals(List((1,2),(3,4),(5,6)), z) } + + @Test def `SI-9666: use inline group names`(): Unit = { + val r = new Regex("a(?<Bee>b*)c") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + assertEquals("abbbc", ms.next()) + assertEquals("bbb", ms group "Bee") + assertTrue(ms.hasNext) + assertEquals("abc", ms.next()) + assertEquals("b", ms group "Bee") + assertFalse(ms.hasNext) + } + + @Test def `SI-9666: use explicit group names`(): Unit = { + val r = new Regex("a(b*)c", "Bee") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + assertEquals("abbbc", ms.next()) + assertEquals("bbb", ms group "Bee") + assertTrue(ms.hasNext) + assertEquals("abc", ms.next()) + assertEquals("b", ms group "Bee") + assertFalse(ms.hasNext) + } + + @Test def `SI-9666: fall back to explicit group names`(): Unit = { + val r = new Regex("a(?<Bar>b*)c", "Bee") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + assertEquals("abbbc", ms.next()) + assertEquals("bbb", ms group "Bee") + assertEquals("bbb", ms group "Bar") + assertTrue(ms.hasNext) + assertEquals("abc", ms.next()) + assertEquals("b", ms group "Bee") + assertEquals("b", ms group "Bar") + assertFalse(ms.hasNext) + } + + //type NoGroup = NoSuchElementException + type NoGroup = IllegalArgumentException + + @Test def `SI-9666: throw on bad name`(): Unit = { + assertThrows[NoGroup] { + val r = new Regex("a(?<Bar>b*)c") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + ms group "Bee" + } + assertThrows[NoGroup] { + val r = new Regex("a(?<Bar>b*)c", "Bar") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + ms group "Bee" + } + assertThrows[NoGroup] { + val r = new Regex("a(b*)c", "Bar") + val ms = r findAllIn "stuff abbbc more abc and so on" + assertTrue(ms.hasNext) + ms group "Bee" + } + } } |