-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
rootProject
as a dependency (#233)
* Add support for `rootProject` as a dependency * Replace `allprojects` with `subprojects` + `rootProject` for backward compatibility * Add FullProjectRootGradleTest --------- Co-authored-by: Bruno Wieczorek <[email protected]>
- Loading branch information
Showing
3 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
plugin/src/test/kotlin/com/jraska/module/graph/assertion/FullProjectRootGradleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.jraska.module.graph.assertion | ||
|
||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import java.io.File | ||
|
||
class FullProjectRootGradleTest { | ||
@get:Rule | ||
val testProjectDir: TemporaryFolder = TemporaryFolder() | ||
|
||
@Test | ||
fun printsCorrectStatisticsForRootProjectWithDependency() { | ||
testProjectDir.newFile("settings.gradle") | ||
.writeText("include ':core'") | ||
|
||
createRoot(content = """ | ||
plugins { | ||
id 'com.jraska.module.graph.assertion' | ||
} | ||
apply plugin: 'java-library' | ||
moduleGraphAssert { | ||
maxHeight = 1 | ||
} | ||
dependencies { | ||
implementation project(":core") | ||
} | ||
""".trimIndent()) | ||
|
||
createModule( | ||
"core", content = """ | ||
apply plugin: 'java-library' | ||
""" | ||
) | ||
|
||
val output = | ||
runGradleAssertModuleGraph(testProjectDir.root, "generateModulesGraphStatistics").output | ||
|
||
assert(output.contains(("> Task :generateModulesGraphStatistics\n.*" + | ||
"GraphStatistics\\(modulesCount=2, edgesCount=1, height=1, longestPath=\'root.* -> :core\'\\)").toRegex())) | ||
} | ||
|
||
@Test | ||
fun printsCorrectStatisticsForIndependentRootProject() { | ||
testProjectDir.newFile("settings.gradle") | ||
.writeText("include ':app'") | ||
|
||
createRoot(content = """ | ||
plugins { | ||
id 'com.jraska.module.graph.assertion' | ||
} | ||
apply plugin: 'java-library' | ||
moduleGraphAssert { | ||
maxHeight = 0 | ||
} | ||
""".trimIndent()) | ||
|
||
createModule( | ||
"app", content = """ | ||
plugins { | ||
id 'com.jraska.module.graph.assertion' | ||
} | ||
apply plugin: 'java-library' | ||
moduleGraphAssert { | ||
maxHeight = 0 | ||
} | ||
""" | ||
) | ||
|
||
val output = | ||
runGradleAssertModuleGraph(testProjectDir.root, "generateModulesGraphStatistics").output | ||
|
||
assert(output.contains(("> Task :generateModulesGraphStatistics\n.*" + | ||
"GraphStatistics\\(modulesCount=1, edgesCount=0, height=0, longestPath=\'root.*\'\\)\n\n" + | ||
"> Task :app:generateModulesGraphStatistics\n+" + | ||
"GraphStatistics\\(modulesCount=1, edgesCount=0, height=0, longestPath=\':app\'\\)").toRegex())) | ||
} | ||
|
||
private fun createRoot(content: String) { | ||
File(testProjectDir.root, "build.gradle").writeText(content) | ||
} | ||
|
||
private fun createModule(dir: String, content: String) { | ||
val newFolder = testProjectDir.newFolder(dir) | ||
File(newFolder, "build.gradle").writeText(content) | ||
} | ||
} |