|
| 1 | +/* |
| 2 | + * Scala (https://www.scala-lang.org) |
| 3 | + * |
| 4 | + * Copyright EPFL and Lightbend, Inc. |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * (http://www.apache.org/licenses/LICENSE-2.0). |
| 8 | + * |
| 9 | + * See the NOTICE file distributed with this work for |
| 10 | + * additional information regarding copyright ownership. |
| 11 | + */ |
| 12 | + |
| 13 | +package scala.tools.nsc |
| 14 | + |
| 15 | +import org.junit.Assert.assertEquals |
| 16 | +import org.junit.Test |
| 17 | + |
| 18 | +class PhaseAssemblyTest { |
| 19 | + @Test |
| 20 | + def multipleRunsRightAfter(): Unit = { |
| 21 | + val global = new Global(new Settings) |
| 22 | + case class component[G <: Global with Singleton](global: G, phaseName: String, override val runsRightAfter: Option[String], override val runsAfter: List[String], override val runsBefore: List[String]) extends SubComponent { |
| 23 | + override def newPhase(prev: Phase): Phase = ??? |
| 24 | + } |
| 25 | + val N = 16 |
| 26 | + val random = new scala.util.Random(123502L) |
| 27 | + val names = Array.fill(N)("phase_" + random.nextInt(1024)) |
| 28 | + val parserAndTerminal = List( |
| 29 | + component(global, "parser", None, Nil, Nil), |
| 30 | + component(global,"terminal", None, Nil, List(N.toString)) |
| 31 | + ) |
| 32 | + val components = List.tabulate(N)(i => component(global, names(i), Some(if (i == 0) "parser" else names(i - 1)), Nil, List("terminal"))) ::: parserAndTerminal |
| 33 | + |
| 34 | + val graph = global.phasesSetToDepGraph(components.reverse) |
| 35 | + graph.removeDanglingNodes() |
| 36 | + graph.collapseHardLinks() |
| 37 | + graph.assignLevelsAndDetectCycles(graph.getNodeByPhase("parser")) |
| 38 | + val result: List[String] =graph.compilerPhaseList().map(_.phaseName).filter(_.startsWith("phase_")) |
| 39 | + assertEquals(names.toList, result) |
| 40 | + } |
| 41 | + |
| 42 | +} |
0 commit comments