Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,39 @@ class DependencyGraphBuilderTest : WordSpec({
scopeDependencies(scopes, scope2) shouldBe setOf(depAcmeExclude)
}

"deal with cycles in dependencies" {
val scope = "CyclicScope"
val depCyc1 = createDependency("org.cyclic", "cyclic", "77.7")
val depFoo = createDependency("org.foo", "foo", "1.2.0", dependencies = setOf(depCyc1))
val depCyc2 = createDependency("org.cyclic", "cyclic", "77.7", dependencies = setOf(depFoo))
"break cycles in dependencies" {
// A simple map of indexed nodes with their dependencies.
@Suppress("NoMultipleSpaces")
val dependencies = mapOf(
1 to listOf(2, 3),
2 to listOf(4, 5),
3 to listOf(1), // Cycle: 1 -> 3 -> 1
5 to listOf(6),
6 to listOf(2) // Cycle: 1 -> 2 -> 5 -> 6 -> 2
)

val graph = createGraphBuilder()
.addDependency(scope, depCyc2)
.build()
val scopes = graph.createScopes()
val handler = object : DependencyHandler<Int> {
override fun identifierFor(dependency: Int) = Identifier.EMPTY.copy(name = dependency.toString())

scopeDependencies(scopes, scope) should containExactly(depCyc2)
override fun dependenciesFor(dependency: Int) = dependencies[dependency].orEmpty()

graph.nodes shouldHaveSize 3
override fun linkageFor(dependency: Int) = PackageLinkage.DYNAMIC

override fun createPackage(dependency: Int, issues: MutableCollection<Issue>) = null
}

val graph = DependencyGraphBuilder(handler)
.addDependency("root", 1)
.build(checkReferences = false)

graph.nodes shouldHaveSize 6
graph.edges should containExactly(
DependencyGraphEdge(from = 2, to = 1),
DependencyGraphEdge(from = 3, to = 0),
DependencyGraphEdge(from = 3, to = 2),
DependencyGraphEdge(from = 5, to = 3),
DependencyGraphEdge(from = 5, to = 4)
)
}

"deal with cyclic dependency graphs" {
Expand Down
Loading