mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Test for build order.
This commit is contained in:
parent
ff7402b24f
commit
5fcffb0241
2 changed files with 43 additions and 2 deletions
|
@ -91,7 +91,7 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
* Determine which projects to run based on the request tasks. Also make sure that all the requested projects
|
* Determine which projects to run based on the request tasks. Also make sure that all the requested projects
|
||||||
* exist.
|
* exist.
|
||||||
*/
|
*/
|
||||||
private fun findProjectsToRun(taskInfos: List<TaskInfo>, projects: List<Project>) : List<Project> {
|
fun findProjectsToRun(taskInfos: List<TaskInfo>, projects: List<Project>) : List<Project> {
|
||||||
|
|
||||||
// Validate projects
|
// Validate projects
|
||||||
val result = arrayListOf<Project>()
|
val result = arrayListOf<Project>()
|
||||||
|
@ -180,7 +180,7 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
* see if that project depends on others and if it does, invoke these tasks on all of them. This
|
* see if that project depends on others and if it does, invoke these tasks on all of them. This
|
||||||
* function returns all these task names (including dependent).
|
* function returns all these task names (including dependent).
|
||||||
*/
|
*/
|
||||||
private fun calculateDependentTaskNames(taskNames: List<String>, projects: List<Project>): List<TaskInfo> {
|
fun calculateDependentTaskNames(taskNames: List<String>, projects: List<Project>): List<TaskInfo> {
|
||||||
val projectMap = hashMapOf<String, Project>().apply {
|
val projectMap = hashMapOf<String, Project>().apply {
|
||||||
projects.forEach { put(it.name, it)}
|
projects.forEach { put(it.name, it)}
|
||||||
}
|
}
|
||||||
|
|
41
src/test/kotlin/com/beust/kobalt/internal/BuildOrderTest.kt
Normal file
41
src/test/kotlin/com/beust/kobalt/internal/BuildOrderTest.kt
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.TestModule
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
|
import com.beust.kobalt.project
|
||||||
|
import org.testng.Assert
|
||||||
|
import org.testng.annotations.BeforeClass
|
||||||
|
import org.testng.annotations.DataProvider
|
||||||
|
import org.testng.annotations.Guice
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Guice(modules = arrayOf(TestModule::class))
|
||||||
|
class BuildOrderTest @Inject constructor(val taskManager: TaskManager) {
|
||||||
|
@BeforeClass
|
||||||
|
fun beforeClass() {
|
||||||
|
Kobalt.init(TestModule())
|
||||||
|
}
|
||||||
|
|
||||||
|
@DataProvider
|
||||||
|
fun tasks(): Array<Array<out Any>> {
|
||||||
|
return arrayOf(
|
||||||
|
arrayOf(listOf("p1:assemble"), listOf("p1:assemble")),
|
||||||
|
arrayOf(listOf("p2:assemble"), listOf("p1:assemble", "p2:assemble")),
|
||||||
|
arrayOf(listOf("p3:assemble"), listOf("p1:assemble", "p2:assemble", "p3:assemble"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "tasks")
|
||||||
|
fun shouldBuildInRightOrder(tasks: List<String>, expectedTasks: List<String>) {
|
||||||
|
val p1 = project { name = "p1" }
|
||||||
|
val p2 = project(p1) { name = "p2" }
|
||||||
|
val p3 = project(p2) { name = "p3" }
|
||||||
|
|
||||||
|
val allProjects = listOf(p1, p2, p3)
|
||||||
|
with(taskManager) {
|
||||||
|
val taskInfos = calculateDependentTaskNames(tasks, allProjects)
|
||||||
|
Assert.assertEquals(taskInfos.map { it.id }, expectedTasks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue