1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

TaskManagerTest.

This commit is contained in:
Cedric Beust 2016-04-12 23:45:17 -07:00
parent c40867f85f
commit 1ffb03f660

View file

@ -0,0 +1,49 @@
package com.beust.kobalt.internal
import com.beust.kobalt.TestModule
import com.google.common.collect.TreeMultimap
import com.google.inject.Inject
import org.testng.Assert
import org.testng.annotations.Guice
import org.testng.annotations.Test
@Guice(modules = arrayOf(TestModule::class))
class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
class DryRunGraphExecutor<T>(val graph: DynamicGraph<T>) {
fun run() : List<T> {
val result = arrayListOf<T>()
while (graph.freeNodes.size > 0) {
graph.freeNodes.forEach {
result.add(it)
graph.setStatus(it, DynamicGraph.Status.FINISHED)
}
}
return result
}
}
private fun runTasks(tasks: List<String>) : List<String> {
val runBefore = TreeMultimap.create<String, String>().apply {
put("assemble", "compile")
put("compile", "clean")
}
val alwaysRunAfter = TreeMultimap.create<String, String>()
val dependencies = TreeMultimap.create<String, String>().apply {
listOf("assemble", "compile", "clean").forEach {
put(it, it)
}
}
val graph = taskManager.createGraph("", tasks, dependencies, runBefore, alwaysRunAfter,
{ it }, { t -> true })
val result = DryRunGraphExecutor(graph).run()
return result
}
@Test
fun graphTest() {
Assert.assertEquals(runTasks(listOf("assemble")), listOf("compile", "assemble"))
Assert.assertEquals(runTasks(listOf("clean", "assemble")), listOf("clean", "compile", "assemble"))
}
}