Skip to content

Commit 758eb13

Browse files
committed
test(model): Fix the test for cyclic dependencies
There is no cycle in the originally defined depCyc2 -> depFoo -> depCyc1 dependency chain. Doing so is actually not directly possible with the recursively defined `PackageReference` class. Solve that by using a primitive `DependencyHandler` that just uses indexes to identify dependencies. The test passes thanks to the fix recently made in 80edb57. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent fbdf7cb commit 758eb13

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

model/src/test/kotlin/utils/DependencyGraphBuilderTest.kt

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,38 @@ class DependencyGraphBuilderTest : WordSpec({
199199
}
200200

201201
"deal with cycles in dependencies" {
202-
val scope = "CyclicScope"
203-
val depCyc1 = createDependency("org.cyclic", "cyclic", "77.7")
204-
val depFoo = createDependency("org.foo", "foo", "1.2.0", dependencies = setOf(depCyc1))
205-
val depCyc2 = createDependency("org.cyclic", "cyclic", "77.7", dependencies = setOf(depFoo))
202+
// A simple map of indexed nodes with their dependencies.
203+
@Suppress("NoMultipleSpaces")
204+
val dependencies = mapOf(
205+
1 to listOf(2, 3),
206+
2 to listOf(4, 5),
207+
3 to listOf(1), // Cycle: 1 -> 3 -> 1
208+
5 to listOf(6),
209+
6 to listOf(2) // Cycle: 1 -> 2 -> 5 -> 6 -> 2
210+
)
206211

207-
val graph = createGraphBuilder()
208-
.addDependency(scope, depCyc2)
209-
.build()
210-
val scopes = graph.createScopes()
212+
val handler = object : DependencyHandler<Int> {
213+
override fun identifierFor(dependency: Int) = Identifier.EMPTY.copy(name = dependency.toString())
211214

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

214-
graph.nodes shouldHaveSize 3
217+
override fun linkageFor(dependency: Int) = PackageLinkage.DYNAMIC
218+
219+
override fun createPackage(dependency: Int, issues: MutableCollection<Issue>) = null
220+
}
221+
222+
val graph = DependencyGraphBuilder(handler)
223+
.addDependency("root", 1)
224+
.build(checkReferences = false)
225+
226+
graph.nodes shouldHaveSize 6
227+
graph.edges should containExactly(
228+
DependencyGraphEdge(from = 2, to = 1),
229+
DependencyGraphEdge(from = 3, to = 0),
230+
DependencyGraphEdge(from = 3, to = 2),
231+
DependencyGraphEdge(from = 5, to = 3),
232+
DependencyGraphEdge(from = 5, to = 4)
233+
)
215234
}
216235

217236
"deal with cyclic dependency graphs" {

0 commit comments

Comments
 (0)