diff options
Diffstat (limited to 'scalalib/src/test/resource/acyclic')
59 files changed, 0 insertions, 909 deletions
diff --git a/scalalib/src/test/resource/acyclic/build.sbt b/scalalib/src/test/resource/acyclic/build.sbt deleted file mode 100644 index 3fd0f8e4..00000000 --- a/scalalib/src/test/resource/acyclic/build.sbt +++ /dev/null @@ -1,49 +0,0 @@ - -organization := "com.lihaoyi" - -name := "acyclic" - -version := "0.1.7" - -scalaVersion := "2.11.8" - -crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0") - -resolvers += Resolver.sonatypeRepo("releases") - -libraryDependencies ++= Seq( - "com.lihaoyi" %% "utest" % "0.4.4" % "test", - "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided" -) - -testFrameworks += new TestFramework("utest.runner.Framework") - -unmanagedSourceDirectories in Test <+= baseDirectory(_ / "src" / "test" / "resources") - -// Sonatype -publishArtifact in Test := false - -publishTo <<= version { (v: String) => - Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") -} - -pomExtra := ( - <url>https://github.com/lihaoyi/acyclic</url> - <licenses> - <license> - <name>MIT license</name> - <url>http://www.opensource.org/licenses/mit-license.php</url> - </license> - </licenses> - <scm> - <url>git://github.com/lihaoyi/utest.git</url> - <connection>scm:git://github.com/lihaoyi/acyclic.git</connection> - </scm> - <developers> - <developer> - <id>lihaoyi</id> - <name>Li Haoyi</name> - <url>https://github.com/lihaoyi</url> - </developer> - </developers> - ) diff --git a/scalalib/src/test/resource/acyclic/project/build.properties b/scalalib/src/test/resource/acyclic/project/build.properties deleted file mode 100644 index 817bc38d..00000000 --- a/scalalib/src/test/resource/acyclic/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.13.9 diff --git a/scalalib/src/test/resource/acyclic/project/build.sbt b/scalalib/src/test/resource/acyclic/project/build.sbt deleted file mode 100644 index 7a1f37db..00000000 --- a/scalalib/src/test/resource/acyclic/project/build.sbt +++ /dev/null @@ -1,2 +0,0 @@ - -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
\ No newline at end of file diff --git a/scalalib/src/test/resource/acyclic/src/main/resources/scalac-plugin.xml b/scalalib/src/test/resource/acyclic/src/main/resources/scalac-plugin.xml deleted file mode 100644 index 7fd6e95b..00000000 --- a/scalalib/src/test/resource/acyclic/src/main/resources/scalac-plugin.xml +++ /dev/null @@ -1,4 +0,0 @@ -<plugin> - <name>acyclic</name> - <classname>acyclic.plugin.RuntimePlugin</classname> -</plugin>
\ No newline at end of file diff --git a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/package.scala b/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/package.scala deleted file mode 100644 index 0d656160..00000000 --- a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/package.scala +++ /dev/null @@ -1,23 +0,0 @@ -import scala.reflect.internal.annotations.compileTimeOnly -package object acyclic { - /** - * Import this within a file to make Acyclic verify that the file does not - * have any circular dependencies with other files. - */ - @compileTimeOnly("acyclic.file is just a marker and not a real value") - def file = () - - /** - * - */ - @compileTimeOnly("acyclic.file is just a marker and not a real value") - def skipped = () - - /** - * Import this within a package object to make Acyclic verify that the entire - * package does not have any circular dependencies with other files or - * packages. Circular dependencies *within* the package are Ok. - */ - @compileTimeOnly("acyclic.pkg is just a marker and not a real value") - def pkg = () -} diff --git a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/DependencyExtraction.scala b/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/DependencyExtraction.scala deleted file mode 100644 index 46aacc2b..00000000 --- a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/DependencyExtraction.scala +++ /dev/null @@ -1,100 +0,0 @@ -//acyclic -package acyclic.plugin -import acyclic.file -import scala.tools.nsc.Global -object DependencyExtraction{ - def apply(global: Global)(unit: global.CompilationUnit): Seq[(global.Symbol, global.Tree)] = { - import global._ - - class CollectTypeTraverser[T](pf: PartialFunction[Type, T]) extends TypeTraverser { - var collected: List[T] = Nil - def traverse(tpe: Type): Unit = { - if (pf.isDefinedAt(tpe)) - collected = pf(tpe) :: collected - mapOver(tpe) - } - } - - class ExtractDependenciesTraverser extends Traverser { - protected val depBuf = collection.mutable.ArrayBuffer.empty[(Symbol, Tree)] - protected def addDependency(sym: Symbol, tree: Tree): Unit = depBuf += ((sym, tree)) - def dependencies: collection.immutable.Set[(Symbol, Tree)] = { - // convert to immutable set and remove NoSymbol if we have one - depBuf.toSet - } - - } - - class ExtractDependenciesByMemberRefTraverser extends ExtractDependenciesTraverser { - override def traverse(tree: Tree): Unit = { - tree match { - case i @ Import(expr, selectors) => - - selectors.foreach { - case ImportSelector(nme.WILDCARD, _, null, _) => - // in case of wildcard import we do not rely on any particular name being defined - // on `expr`; all symbols that are being used will get caught through selections - case ImportSelector(name: Name, _, _, _) => - def lookupImported(name: Name) = expr.symbol.info.member(name) - // importing a name means importing both a term and a type (if they exist) - addDependency(lookupImported(name.toTermName), tree) - addDependency(lookupImported(name.toTypeName), tree) - } - case select: Select => - addDependency(select.symbol, tree) - /* - * Idents are used in number of situations: - * - to refer to local variable - * - to refer to a top-level package (other packages are nested selections) - * - to refer to a term defined in the same package as an enclosing class; - * this looks fishy, see this thread: - * https://groups.google.com/d/topic/scala-internals/Ms9WUAtokLo/discussion - */ - case ident: Ident => - addDependency(ident.symbol, tree) - case typeTree: TypeTree => - val typeSymbolCollector = new CollectTypeTraverser({ - case tpe if !tpe.typeSymbol.isPackage => tpe.typeSymbol - }) - typeSymbolCollector.traverse(typeTree.tpe) - val deps = typeSymbolCollector.collected.toSet - deps.foreach(addDependency(_, tree)) - case Template(parents, self, body) => - traverseTrees(body) - case other => () - } - super.traverse(tree) - } - } - - def byMembers(): collection.immutable.Set[(Symbol, Tree)] = { - val traverser = new ExtractDependenciesByMemberRefTraverser - if (!unit.isJava) - traverser.traverse(unit.body) - traverser.dependencies - } - - - class ExtractDependenciesByInheritanceTraverser extends ExtractDependenciesTraverser { - override def traverse(tree: Tree): Unit = tree match { - case Template(parents, self, body) => - // we are using typeSymbol and not typeSymbolDirect because we want - // type aliases to be expanded - val parentTypeSymbols = parents.map(parent => parent.tpe.typeSymbol).toSet - debuglog("Parent type symbols for " + tree.pos + ": " + parentTypeSymbols.map(_.fullName)) - parentTypeSymbols.foreach(addDependency(_, tree)) - traverseTrees(body) - case tree => super.traverse(tree) - } - } - - def byInheritence(): collection.immutable.Set[(Symbol, Tree)] = { - val traverser = new ExtractDependenciesByInheritanceTraverser - if (!unit.isJava) - traverser.traverse(unit.body) - traverser.dependencies - } - - (byMembers() | byInheritence()).toSeq - } -} diff --git a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/GraphAnalysis.scala b/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/GraphAnalysis.scala deleted file mode 100644 index bf72ce39..00000000 --- a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/GraphAnalysis.scala +++ /dev/null @@ -1,103 +0,0 @@ -package acyclic.plugin -import acyclic.file -import scala.tools.nsc.Global -import collection.mutable - -sealed trait Value{ - def pkg: List[String] - def prettyPrint: String -} -object Value{ - case class File(path: String, pkg: List[String] = Nil) extends Value{ - def prettyPrint = s"file $path" - } - case class Pkg(pkg: List[String]) extends Value{ - def prettyPrint = s"package ${pkg.mkString(".")}" - } - object Pkg{ - def apply(s: String): Pkg = apply(s.split('.').toList) - } -} - -trait GraphAnalysis{ - val global: Global - import global._ - - case class Node[+T <: Value](value: T, dependencies: Map[Value, Seq[Tree]]){ - override def toString = s"DepNode(\n $value, \n ${dependencies.keys}\n)" - } - - type DepNode = Node[Value] - type FileNode = Node[Value.File] - type PkgNode = Node[Value.Pkg] - - object DepNode{ - /** - * Does a double Breadth-First-Search to find the shortest cycle starting - * from `from` within the DepNodes in `among`. - */ - def smallestCycle(from: DepNode, among: Seq[DepNode]): Seq[DepNode] = { - val nodeMap = among.map(n => n.value -> n).toMap - val distances = mutable.Map(from -> 0) - val queue = mutable.Queue(from) - while(queue.nonEmpty){ - val next = queue.dequeue() - val children = next.dependencies - .keys - .collect(nodeMap) - .filter(!distances.contains(_)) - - children.foreach(distances(_) = distances(next) + 1) - queue.enqueue(children.toSeq:_*) - } - var route = List(from) - while(route.length == 1 || route.head != from){ - route ::= among.filter(x => x.dependencies.keySet.contains(route.head.value)) - .minBy(distances) - } - route.tail - } - - /** - * Finds the strongly-connected components of the directed DepNode graph - * by finding cycles in a Depth-First manner and collapsing any components - * whose nodes are involved in the cycle. - */ - def stronglyConnectedComponents(nodes: Seq[DepNode]): Seq[Seq[DepNode]] = { - - val nodeMap = nodes.map(n => n.value -> n).toMap - - val components = mutable.Map.empty[DepNode, Int] ++ nodes.zipWithIndex.toMap - val visited = mutable.Set.empty[DepNode] - - nodes.foreach(n => rec(n, Nil)) - - def rec(node: DepNode, path: List[DepNode]): Unit = { - if (path.exists(components(_) == components(node))) { - val cycle = path.reverse - .dropWhile(components(_) != components(node)) - - val involved = cycle.map(components) - val firstIndex = involved.head - for ((n, i) <- components.toSeq){ - if (involved.contains(i)){ - components(n) = firstIndex - } - } - } else if (!visited(node)) { - visited.add(node) - // sketchy sorting to make sure we're doing this deterministically... - for((key, lines) <- node.dependencies.toSeq.sortBy(_._1.toString)){ - rec(nodeMap(key), node :: path) - } - } - } - - components.groupBy{case (node, i) => i} - .toSeq - .sortBy(_._1) - .map(_._2.keys.toSeq) - } - } - -}
\ No newline at end of file diff --git a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/Plugin.scala b/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/Plugin.scala deleted file mode 100644 index 257894c9..00000000 --- a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/Plugin.scala +++ /dev/null @@ -1,26 +0,0 @@ -package acyclic.plugin -import acyclic.file -import tools.nsc.Global -import scala.collection.SortedSet - -class RuntimePlugin(global: Global) extends TestPlugin(global) -class TestPlugin(val global: Global, - cycleReporter: Seq[(Value, SortedSet[Int])] => Unit = _ => ()) - extends tools.nsc.plugins.Plugin { - - val name = "acyclic" - - var force = false - // Yeah processOptions is deprecated but keep using it anyway for 2.10.x compatibility - override def processOptions(options: List[String], error: String => Unit): Unit = { - if (options.contains("force")) { - force = true - } - } - val description = "Allows the developer to prohibit inter-file dependencies" - - - val components = List[tools.nsc.plugins.PluginComponent]( - new PluginPhase(this.global, cycleReporter, force) - ) -} diff --git a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/PluginPhase.scala b/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/PluginPhase.scala deleted file mode 100644 index eaee91a7..00000000 --- a/scalalib/src/test/resource/acyclic/src/main/scala/acyclic/plugin/PluginPhase.scala +++ /dev/null @@ -1,180 +0,0 @@ - -package acyclic.plugin -import acyclic.file -import scala.collection.{SortedSet, mutable} -import scala.tools.nsc.{Global, Phase} -import tools.nsc.plugins.PluginComponent - -/** - * - Break dependency graph into strongly connected components - * - Turn acyclic packages into virtual "files" in the dependency graph, as - * aggregates of all the files within them - * - Any strongly connected component which includes an acyclic.file or - * acyclic.pkg is a failure - * - Pick an arbitrary cycle and report it - * - Don't report more than one cycle per file/pkg, to avoid excessive spam - */ -class PluginPhase(val global: Global, - cycleReporter: Seq[(Value, SortedSet[Int])] => Unit, - force: => Boolean) - extends PluginComponent - with GraphAnalysis { t => - - import global._ - - val runsAfter = List("typer") - - override val runsBefore = List("patmat") - - val phaseName = "acyclic" - def pkgName(unit: CompilationUnit) = { - unit.body - .collect{case x: PackageDef => x.pid.toString} - .flatMap(_.split('.')) - } - - def units = global.currentRun - .units - .toSeq - .sortBy(_.source.content.mkString.hashCode()) - - def findAcyclics() = { - val acyclicNodePaths = for { - unit <- units - if unit.body.children.collect{ - case Import(expr, List(sel)) => - expr.symbol.toString == "package acyclic" && sel.name.toString == "file" - }.exists(x => x) - } yield { - Value.File(unit.source.path, pkgName(unit)) - } - val skipNodePaths = for { - unit <- units - if unit.body.children.collect{ - case Import(expr, List(sel)) => - expr.symbol.toString == "package acyclic" && sel.name.toString == "skipped" - }.exists(x => x) - } yield { - Value.File(unit.source.path, pkgName(unit)) - } - - val acyclicPkgNames = for { - unit <- units - pkgObject <- unit.body.collect{case x: ModuleDef if x.name.toString == "package" => x } - if pkgObject.impl.children.collect{case Import(expr, List(sel)) => - expr.symbol.toString == "package acyclic" && sel.name.toString == "pkg" - }.exists(x => x) - } yield { - Value.Pkg( - pkgObject.symbol - .enclosingPackageClass - .fullName - .split('.') - .toList - ) - } - (skipNodePaths, acyclicNodePaths, acyclicPkgNames) - } - - override def newPhase(prev: Phase): Phase = new Phase(prev) { - override def run() { - val unitMap = units.map(u => u.source.path -> u).toMap - val nodes = for (unit <- units) yield { - - val deps = DependencyExtraction(t.global)(unit) - - val connections = for{ - (sym, tree) <- deps - if sym != NoSymbol - if sym.sourceFile != null - if sym.sourceFile.path != unit.source.path - } yield (sym.sourceFile.path, tree) - - Node[Value.File]( - Value.File(unit.source.path, pkgName(unit)), - connections.groupBy(c => Value.File(c._1, pkgName(unitMap(c._1))): Value) - .mapValues(_.map(_._2)) - ) - } - - val nodeMap = nodes.map(n => n.value -> n).toMap - - val (skipNodePaths, acyclicFiles, acyclicPkgs) = findAcyclics() - - val allAcyclics = acyclicFiles ++ acyclicPkgs - - // synthetic nodes for packages, which aggregate the dependencies of - // their contents - val pkgNodes = acyclicPkgs.map{ value => - Node( - value, - nodes.filter(_.value.pkg.startsWith(value.pkg)) - .flatMap(_.dependencies.toSeq) - .groupBy(_._1) - .mapValues(_.flatMap(_._2)) - ) - } - - val linkedNodes: Seq[DepNode] = (nodes ++ pkgNodes).map{ d => - val extraLinks = for{ - (value: Value.File, pos) <- d.dependencies - acyclicPkg <- acyclicPkgs - if nodeMap(value).value.pkg.startsWith(acyclicPkg.pkg) - if !d.value.pkg.startsWith(acyclicPkg.pkg) - } yield (acyclicPkg, pos) - d.copy(dependencies = d.dependencies ++ extraLinks) - } - - // only care about cycles with size > 1 here - val components = DepNode.stronglyConnectedComponents(linkedNodes) - .filter(_.size > 1) - - val usedNodes = mutable.Set.empty[DepNode] - for{ - c <- components - n <- c - if !usedNodes.contains(n) - if (!force && allAcyclics.contains(n.value)) || (force && !skipNodePaths.contains(n.value)) - }{ - val cycle = DepNode.smallestCycle(n, c) - val cycleInfo = - (cycle :+ cycle.head).sliding(2) - .map{ case Seq(a, b) => (a.value, a.dependencies(b.value))} - .toSeq - cycleReporter( - cycleInfo.map{ case (a, b) => a -> b.map(_.pos.line).to[SortedSet]} - ) - - global.error("Unwanted cyclic dependency") - for (Seq((value, locs), (nextValue, _)) <- (cycleInfo :+ cycleInfo.head).sliding(2)){ - global.inform("") - value match{ - case Value.Pkg(pkg) => global.inform(s"package ${pkg.mkString(".")}") - case Value.File(_, _) => - } - - units.find(_.source.path == locs.head.pos.source.path) - .get - .echo(locs.head.pos, "") - - val otherLines = locs.tail - .map(_.pos.line) - .filter(_ != locs.head.pos.line) - - global.inform("symbol: " + locs.head.symbol.toString) - - if (!otherLines.isEmpty){ - global.inform("More dependencies at lines " + otherLines.mkString(" ")) - } - - } - global.inform("") - usedNodes ++= cycle - } - } - - def name: String = "acyclic" - } - - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/A.scala deleted file mode 100644 index a0ff0100..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/A.scala +++ /dev/null @@ -1,6 +0,0 @@ -package fail.cyclicgraph -import acyclic.file - -class A{ - val e = new E -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/B.scala deleted file mode 100644 index d1004f5a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/B.scala +++ /dev/null @@ -1,6 +0,0 @@ -package fail.cyclicgraph -import acyclic.file - -class B { - val a: A = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/C.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/C.scala deleted file mode 100644 index 9aebe3a0..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/C.scala +++ /dev/null @@ -1,6 +0,0 @@ -package fail.cyclicgraph -import acyclic.file - -object C extends A{ - val a: A = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/D.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/D.scala deleted file mode 100644 index 9c148b0a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/D.scala +++ /dev/null @@ -1,7 +0,0 @@ -package fail.cyclicgraph -import acyclic.file - -class D { - val b: A = null - val c = C -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/E.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/E.scala deleted file mode 100644 index 00551a06..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicgraph/E.scala +++ /dev/null @@ -1,7 +0,0 @@ -package fail.cyclicgraph -import acyclic.file - -class E { - val a: A = null - val d = new D -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/A1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/A1.scala deleted file mode 100644 index 530e7820..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/A1.scala +++ /dev/null @@ -1,7 +0,0 @@ -package fail.cyclicpackage -package a -import acyclic.file - -class A1 extends b.B1{ - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/A2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/A2.scala deleted file mode 100644 index 95606566..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/A2.scala +++ /dev/null @@ -1,4 +0,0 @@ -package fail.cyclicpackage.a -class A2 { - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/package.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/package.scala deleted file mode 100644 index 9ee69111..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/a/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package fail.cyclicpackage - -package object a { - import acyclic.pkg -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/B1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/B1.scala deleted file mode 100644 index 9b9de725..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/B1.scala +++ /dev/null @@ -1,3 +0,0 @@ -package fail.cyclicpackage.b -import acyclic.file -class B1
\ No newline at end of file diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/B2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/B2.scala deleted file mode 100644 index 87cabd93..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/B2.scala +++ /dev/null @@ -1,5 +0,0 @@ -package fail.cyclicpackage -package b -import acyclic.file - -class B2 extends a.A2
\ No newline at end of file diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/package.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/package.scala deleted file mode 100644 index 5f6d9041..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/cyclicpackage/b/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package fail.cyclicpackage - -package object b { - import acyclic.pkg -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/A.scala deleted file mode 100644 index d8d118b6..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/A.scala +++ /dev/null @@ -1,5 +0,0 @@ -package fail.halfpackagecycle - -class A { - val thing = c.C1 -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/B.scala deleted file mode 100644 index 114d6197..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/B.scala +++ /dev/null @@ -1,3 +0,0 @@ -package fail.halfpackagecycle - -class B extends A diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/C1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/C1.scala deleted file mode 100644 index be4eecf8..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/C1.scala +++ /dev/null @@ -1,3 +0,0 @@ -package fail.halfpackagecycle.c - -object C1 diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/C2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/C2.scala deleted file mode 100644 index be3e0c63..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/C2.scala +++ /dev/null @@ -1,6 +0,0 @@ -package fail.halfpackagecycle -package c - -class C2 { - lazy val b = new B -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/package.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/package.scala deleted file mode 100644 index 295a9e7a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/halfpackagecycle/c/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package fail.halfpackagecycle - -package object c { - import acyclic.pkg -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/A.scala deleted file mode 100644 index ec4fa106..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/A.scala +++ /dev/null @@ -1,7 +0,0 @@ -package fail.indirect -import acyclic.file - -object A -class A { - val b: B = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/B.scala deleted file mode 100644 index f9f8450a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/B.scala +++ /dev/null @@ -1,3 +0,0 @@ -package fail.indirect - -class B extends C diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/C.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/C.scala deleted file mode 100644 index 986baaf3..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/indirect/C.scala +++ /dev/null @@ -1,5 +0,0 @@ -package fail.indirect - -class C { - val a = A -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/simple/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/simple/A.scala deleted file mode 100644 index e1f95ae9..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/simple/A.scala +++ /dev/null @@ -1,7 +0,0 @@ -package fail.simple -import acyclic.file - - -class A { - val b: B = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/fail/simple/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/fail/simple/B.scala deleted file mode 100644 index fa9ee63f..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/fail/simple/B.scala +++ /dev/null @@ -1,6 +0,0 @@ -package fail.simple - -class B { - val a1: A = new A - val a2: A = new A -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/force/simple/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/force/simple/A.scala deleted file mode 100644 index 24a2a633..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/force/simple/A.scala +++ /dev/null @@ -1,7 +0,0 @@ -package force.simple - - - -class A { - val b: B = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/force/simple/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/force/simple/B.scala deleted file mode 100644 index 50c5d305..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/force/simple/B.scala +++ /dev/null @@ -1,6 +0,0 @@ -package force.simple - -class B { - val a1: A = new A - val a2: A = new A -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/force/skip/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/force/skip/A.scala deleted file mode 100644 index 3f2464cd..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/force/skip/A.scala +++ /dev/null @@ -1,7 +0,0 @@ -package force.skip -import acyclic.skipped - - -class A { - val b: B = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/force/skip/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/force/skip/B.scala deleted file mode 100644 index b00c6db2..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/force/skip/B.scala +++ /dev/null @@ -1,6 +0,0 @@ -package force.skip -import acyclic.skipped -class B { - val a1: A = new A - val a2: A = new A -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/cyclicunmarked/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/cyclicunmarked/A.scala deleted file mode 100644 index 902ee5fe..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/cyclicunmarked/A.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.cyclicunmarked - -class A { - val b: B = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/cyclicunmarked/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/cyclicunmarked/B.scala deleted file mode 100644 index 203707ed..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/cyclicunmarked/B.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.cyclicunmarked - -class B { - val a1: A = new A - val a2: A = new A -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/A.scala deleted file mode 100644 index c9a27490..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/A.scala +++ /dev/null @@ -1,4 +0,0 @@ -package success.dag - -class A { -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/B.scala deleted file mode 100644 index 3858e677..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/B.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.dag - -class B { - val a: A = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/C.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/C.scala deleted file mode 100644 index c4635adf..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/C.scala +++ /dev/null @@ -1,3 +0,0 @@ -package success.dag - -object C extends A diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/D.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/D.scala deleted file mode 100644 index 3ab67e39..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/D.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.dag - -class D { - val b: A = null - val c = C -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/E.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/E.scala deleted file mode 100644 index 4148d75a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/dag/E.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.dag - -class E { - val a: A = null - val d = new D -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/java/SomeJava.java b/scalalib/src/test/resource/acyclic/src/test/resources/success/java/SomeJava.java deleted file mode 100644 index cad93696..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/java/SomeJava.java +++ /dev/null @@ -1,4 +0,0 @@ - -public interface SomeJava { - -}
\ No newline at end of file diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/A1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/A1.scala deleted file mode 100644 index 3d5bc5b3..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/A1.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.halfacyclicpackage -package a - -class A1 extends b.B1{ - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/A2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/A2.scala deleted file mode 100644 index 88ee4a03..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/A2.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.halfacyclicpackage.a - -class A2 { - - } diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/package.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/package.scala deleted file mode 100644 index 54f98aff..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/a/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.halfacyclicpackage - -package object a { - import acyclic.pkg -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/b/B1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/b/B1.scala deleted file mode 100644 index 074f808a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/b/B1.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.halfacyclicpackage.b - -class B1 { - - } diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/b/B2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/b/B2.scala deleted file mode 100644 index 6e4dfdd5..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/halfacyclic/b/B2.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.halfacyclicpackage -package b - -class B2 extends a.A2{ - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/A1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/A1.scala deleted file mode 100644 index 583e6c68..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/A1.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.pkg.innercycle.a - -class A1 { - val x: A2 = null - def y = p -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/A2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/A2.scala deleted file mode 100644 index 65f656a4..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/A2.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.pkg.innercycle.a - -class A2 { - val x: A1 = null - def z = p -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/package.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/package.scala deleted file mode 100644 index 165fda66..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/innercycle/a/package.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.pkg.innercycle - -package object a { - val p: A1 with A2 = null - import acyclic.pkg -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/a/A1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/a/A1.scala deleted file mode 100644 index 3158f120..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/a/A1.scala +++ /dev/null @@ -1,7 +0,0 @@ -package success.cyclicpackage -package a - - -class A1 extends b.B1{ - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/a/A2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/a/A2.scala deleted file mode 100644 index 1c36fe2a..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/a/A2.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.cyclicpackage.a - - -class A2 { - - } diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/b/B1.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/b/B1.scala deleted file mode 100644 index 33e10fc1..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/b/B1.scala +++ /dev/null @@ -1,6 +0,0 @@ -package success.cyclicpackage.b - - -class B1 { - - } diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/b/B2.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/b/B2.scala deleted file mode 100644 index 57e324ce..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/mutualcyclic/b/B2.scala +++ /dev/null @@ -1,7 +0,0 @@ -package success.cyclicpackage -package b - - -class B2 extends a.A2{ - -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/single/pkg/package.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/single/pkg/package.scala deleted file mode 100644 index c39b5e62..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/pkg/single/pkg/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.singlepackage - -package object pkg { - import acyclic.pkg -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/simple/A.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/simple/A.scala deleted file mode 100644 index 24b9d0d3..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/simple/A.scala +++ /dev/null @@ -1,4 +0,0 @@ -package success.simple - -class A { -} diff --git a/scalalib/src/test/resource/acyclic/src/test/resources/success/simple/B.scala b/scalalib/src/test/resource/acyclic/src/test/resources/success/simple/B.scala deleted file mode 100644 index b7ca5335..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/resources/success/simple/B.scala +++ /dev/null @@ -1,5 +0,0 @@ -package success.simple - -class B { - val a: A = null -} diff --git a/scalalib/src/test/resource/acyclic/src/test/scala/acyclic/CycleTests.scala b/scalalib/src/test/resource/acyclic/src/test/scala/acyclic/CycleTests.scala deleted file mode 100644 index ff831aad..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/scala/acyclic/CycleTests.scala +++ /dev/null @@ -1,68 +0,0 @@ -package acyclic - -import utest._ -import TestUtils.{make, makeFail} -import scala.tools.nsc.util.ScalaClassLoader.URLClassLoader -import acyclic.plugin.Value.{Pkg, File} -import scala.collection.SortedSet -import acyclic.file - -object CycleTests extends TestSuite{ - - def tests = TestSuite{ - 'fail{ - 'simple-makeFail("fail/simple")(Seq( - File("B.scala") -> SortedSet(4, 5), - File("A.scala") -> SortedSet(6) - )) - - 'indirect-makeFail("fail/indirect")(Seq( - File("A.scala") -> SortedSet(6), - File("B.scala") -> SortedSet(3), - File("C.scala") -> SortedSet(4) - )) - 'cyclicgraph-makeFail("fail/cyclicgraph")( - Seq( - File("A.scala") -> SortedSet(5), - File("E.scala") -> SortedSet(6), - File("D.scala") -> SortedSet(6), - File("C.scala") -> SortedSet(4, 5) - ) - ) - 'cyclicpackage-makeFail("fail/cyclicpackage")( - Seq( - Pkg("fail.cyclicpackage.b") -> SortedSet(5), - Pkg("fail.cyclicpackage.a") -> SortedSet(5) - ) - ) - 'halfpackagecycle-makeFail("fail/halfpackagecycle")(Seq( - File("B.scala") -> SortedSet(3), - File("A.scala") -> SortedSet(4), - Pkg("fail.halfpackagecycle.c") -> SortedSet(5) - )) - } - 'success{ - 'simple-make("success/simple") - 'ignorejava-make("success/java") - 'cyclicunmarked-make("success/cyclicunmarked") - 'dag-make("success/dag") - 'pkg{ - "single" - make("success/pkg/single") - "mutualcyclic" - make("success/pkg/mutualcyclic") - "halfacyclic" - make("success/pkg/halfacyclic") - "innercycle" - make("success/pkg/innercycle") - } - } - 'self-make("../../main/scala", extraIncludes = Nil) - 'force{ - 'fail-makeFail("force/simple", force = true)(Seq( - File("B.scala") -> SortedSet(4, 5), - File("A.scala") -> SortedSet(6) - )) - 'pass-make("force/simple") - 'skip-make("force/skip", force = true) - } - } -} - - diff --git a/scalalib/src/test/resource/acyclic/src/test/scala/acyclic/TestUtils.scala b/scalalib/src/test/resource/acyclic/src/test/scala/acyclic/TestUtils.scala deleted file mode 100644 index 7bff8248..00000000 --- a/scalalib/src/test/resource/acyclic/src/test/scala/acyclic/TestUtils.scala +++ /dev/null @@ -1,92 +0,0 @@ -package acyclic - -import tools.nsc.{Global, Settings} -import tools.nsc.reporters.ConsoleReporter -import tools.nsc.plugins.Plugin - -import java.net.URLClassLoader -import scala.tools.nsc.util.ClassPath -import utest._, asserts._ -import scala.reflect.io.VirtualDirectory -import acyclic.plugin.Value -import scala.collection.SortedSet - -object TestUtils { - def getFilePaths(src: String): List[String] = { - val f = new java.io.File(src) - if (f.isDirectory) f.list.toList.flatMap(x => getFilePaths(src + "/" + x)) - else List(src) - } - - /** - * Attempts to compile a resource folder as a compilation run, in order - * to test whether it succeeds or fails correctly. - */ - def make(path: String, - extraIncludes: Seq[String] = Seq("src/main/scala/acyclic/package.scala"), - force: Boolean = false) = { - val src = "src/test/resources/" + path - val sources = getFilePaths(src) ++ extraIncludes - - val vd = new VirtualDirectory("(memory)", None) - lazy val settings = new Settings - val loader = getClass.getClassLoader.asInstanceOf[URLClassLoader] - val entries = loader.getURLs map(_.getPath) - settings.outputDirs.setSingleOutput(vd) - - // annoyingly, the Scala library is not in our classpath, so we have to add it manually - val sclpath = entries.map( - _.replaceAll("scala-compiler.jar", "scala-library.jar") - ) - - settings.classpath.value = ClassPath.join(entries ++ sclpath : _*) - - if (force) settings.pluginOptions.value = List("acyclic:force") - - var cycles: Option[Seq[Seq[(acyclic.plugin.Value, SortedSet[Int])]]] = None - lazy val compiler = new Global(settings, new ConsoleReporter(settings)){ - override protected def loadRoughPluginsList(): List[Plugin] = { - List(new plugin.TestPlugin(this, foundCycles => cycles = cycles match{ - case None => Some(Seq(foundCycles)) - case Some(oldCycles) => Some(oldCycles :+ foundCycles) - })) - } - } - val run = new compiler.Run() - run.compile(sources) - - if (vd.toList.isEmpty) throw CompilationException(cycles.get) - } - - def makeFail(path: String, force: Boolean = false)(expected: Seq[(Value, SortedSet[Int])]*) = { - def canonicalize(cycle: Seq[(Value, SortedSet[Int])]): Seq[(Value, SortedSet[Int])] = { - val startIndex = cycle.indexOf(cycle.minBy(_._1.toString)) - cycle.toList.drop(startIndex) ++ cycle.toList.take(startIndex) - } - - val ex = intercept[CompilationException]{ make(path, force = force) } - val cycles = ex.cycles - .map(canonicalize) - .map( - _.map{ - case (Value.File(p, pkg), v) => (Value.File(p, Nil), v) - case x => x - } - ) - .toSet - - def expand(v: Value) = v match{ - case Value.File(filePath, pkg) => Value.File("src/test/resources/" + path + "/" + filePath, Nil) - case v => v - } - - val fullExpected = expected.map(_.map(x => x.copy(_1 = expand(x._1)))) - .map(canonicalize) - .toSet - - assert(fullExpected.forall(cycles.contains)) - } - - case class CompilationException(cycles: Seq[Seq[(Value, SortedSet[Int])]]) extends Exception - -} |