mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
More task management tests.
This commit is contained in:
parent
b6bd9e6c10
commit
95ca037845
2 changed files with 105 additions and 34 deletions
|
@ -129,10 +129,10 @@ class TaskManager @Inject constructor(val args: Args,
|
|||
*/
|
||||
@VisibleForTesting
|
||||
fun <T> createGraph(projectName: String, taskNames: List<String>, nodeMap: Multimap<String, T>,
|
||||
dependsOn: TreeMultimap<String, String>,
|
||||
reverseDependsOn: TreeMultimap<String, String>,
|
||||
runBefore: TreeMultimap<String, String>,
|
||||
runAfter: TreeMultimap<String, String>,
|
||||
dependsOn: Multimap<String, String>,
|
||||
reverseDependsOn: Multimap<String, String>,
|
||||
runBefore: Multimap<String, String>,
|
||||
runAfter: Multimap<String, String>,
|
||||
toName: (T) -> String,
|
||||
accept: (T) -> Boolean):
|
||||
DynamicGraph<T> {
|
||||
|
@ -176,10 +176,10 @@ class TaskManager @Inject constructor(val args: Args,
|
|||
}
|
||||
}
|
||||
}
|
||||
maybeAddEdge(taskName, dependsOn, true, false)
|
||||
maybeAddEdge(taskName, reverseDependsOn, true, true)
|
||||
maybeAddEdge(taskName, dependsOn, true, false)
|
||||
maybeAddEdge(taskName, runBefore, false, false)
|
||||
maybeAddEdge(taskName, runAfter, false, false)
|
||||
maybeAddEdge(taskName, runAfter, false, true)
|
||||
}
|
||||
toProcess.clear()
|
||||
toProcess.addAll(newToProcess)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.TestModule
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.common.collect.Multimap
|
||||
import com.google.common.collect.TreeMultimap
|
||||
import com.google.inject.Inject
|
||||
import org.testng.Assert
|
||||
|
@ -29,42 +31,111 @@ class TaskManagerTest @Inject constructor(val taskManager: TaskManager) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun runTasks(tasks: List<String>) : List<String> {
|
||||
val dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
private fun runCompileTasks(tasks: List<String>) : List<String> {
|
||||
val result = runTasks(tasks,
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("assemble", "compile")
|
||||
}
|
||||
val reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||
},
|
||||
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("clean", "copyVersion")
|
||||
put("compile", "postCompile")
|
||||
}
|
||||
val runBefore = TreeMultimap.create<String, String>().apply {
|
||||
}
|
||||
val runAfter = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
}
|
||||
val dependencies = TreeMultimap.create<String, String>().apply {
|
||||
listOf("assemble", "compile", "clean", "copyVersion", "postCompile").forEach {
|
||||
put(it, it)
|
||||
}
|
||||
}
|
||||
val graph = taskManager.createGraph("", tasks, dependencies, dependsOn, reverseDependsOn, runBefore, runAfter,
|
||||
{ it }, { t -> true })
|
||||
val result = DryRunGraphExecutor(graph).run()
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
@Test
|
||||
fun graphTest() {
|
||||
// KobaltLogger.LOG_LEVEL = 3
|
||||
Assert.assertEquals(runTasks(listOf("compile")), listOf("compile", "postCompile"))
|
||||
Assert.assertEquals(runTasks(listOf("postCompile")), listOf("postCompile"))
|
||||
Assert.assertEquals(runTasks(listOf("compile", "postCompile")), listOf("compile", "postCompile"))
|
||||
Assert.assertEquals(runTasks(listOf("clean")), listOf("clean", "copyVersion"))
|
||||
Assert.assertEquals(runTasks(listOf("clean", "compile")), listOf("clean", "compile", "copyVersion",
|
||||
Assert.assertEquals(runCompileTasks(listOf("compile")), listOf("compile", "postCompile"))
|
||||
Assert.assertEquals(runCompileTasks(listOf("postCompile")), listOf("postCompile"))
|
||||
Assert.assertEquals(runCompileTasks(listOf("compile", "postCompile")), listOf("compile", "postCompile"))
|
||||
Assert.assertEquals(runCompileTasks(listOf("clean")), listOf("clean", "copyVersion"))
|
||||
Assert.assertEquals(runCompileTasks(listOf("clean", "compile")), listOf("clean", "compile", "copyVersion",
|
||||
"postCompile"))
|
||||
Assert.assertEquals(runTasks(listOf("assemble")), listOf("compile", "assemble"))
|
||||
Assert.assertEquals(runTasks(listOf("clean", "assemble")), listOf("clean", "compile", "assemble",
|
||||
Assert.assertEquals(runCompileTasks(listOf("assemble")), listOf("compile", "assemble"))
|
||||
Assert.assertEquals(runCompileTasks(listOf("clean", "assemble")), listOf("clean", "compile", "assemble",
|
||||
"copyVersion"))
|
||||
}
|
||||
|
||||
val EMPTY_MULTI_MAP = ArrayListMultimap.create<String, String>()
|
||||
|
||||
private fun runTasks(tasks: List<String>, dependsOn: Multimap<String, String> = EMPTY_MULTI_MAP,
|
||||
reverseDependsOn: Multimap<String, String> = EMPTY_MULTI_MAP,
|
||||
runBefore: Multimap<String, String> = EMPTY_MULTI_MAP,
|
||||
runAfter: Multimap<String, String> = EMPTY_MULTI_MAP): List<String> {
|
||||
|
||||
val dependencies = TreeMultimap.create<String, String>().apply {
|
||||
listOf(dependsOn, reverseDependsOn, runBefore, runAfter).forEach { mm ->
|
||||
mm.keySet().forEach {
|
||||
put(it, it)
|
||||
mm[it].forEach {
|
||||
put(it, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val graph = taskManager.createGraph("", tasks, dependencies,
|
||||
dependsOn, reverseDependsOn, runBefore, runAfter,
|
||||
{ it }, { t -> true })
|
||||
val result = DryRunGraphExecutor(graph).run()
|
||||
return result
|
||||
}
|
||||
|
||||
@Test
|
||||
fun exampleInTheDocTest() {
|
||||
runTasks(listOf("compile"),
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
},
|
||||
reverseDependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "example")
|
||||
}).let { result ->
|
||||
Assert.assertEquals(result, listOf("clean", "compile", "example"))
|
||||
}
|
||||
runTasks(listOf("compile"),
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
put("compile", "example")
|
||||
}).let { result ->
|
||||
Assert.assertEquals(result, listOf("clean", "example", "compile"))
|
||||
}
|
||||
runTasks(listOf("compile"),
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
},
|
||||
runAfter = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "example")
|
||||
}).let { result ->
|
||||
Assert.assertEquals(result, listOf("clean", "compile"))
|
||||
}
|
||||
runTasks(listOf("compile"),
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
},
|
||||
runBefore = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "example")
|
||||
}).let { result ->
|
||||
Assert.assertEquals(result, listOf("clean", "compile"))
|
||||
}
|
||||
runTasks(listOf("compile", "example"),
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
},
|
||||
runBefore = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "example")
|
||||
}).let { result ->
|
||||
Assert.assertEquals(result, listOf("clean", "example", "compile"))
|
||||
}
|
||||
runTasks(listOf("compile", "example"),
|
||||
dependsOn = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "clean")
|
||||
},
|
||||
runAfter = TreeMultimap.create<String, String>().apply {
|
||||
put("compile", "example")
|
||||
}).let { result ->
|
||||
Assert.assertEquals(result, listOf("clean", "compile", "example"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue