Skip to content

Commit

Permalink
Add a test case to check resValue
Browse files Browse the repository at this point in the history
  • Loading branch information
tasomaniac committed Feb 26, 2022
1 parent 5d38382 commit b1fe6ac
Showing 1 changed file with 80 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,7 @@ class UnusedDependenciesPluginTest : BasePluginTest() {
@Test
fun `module with an auto-generated manifest and a string resource used in subject module should not be unused`() {

val appFile = FileSpec.builder("com.example.app", "MyApp")
.addType(
TypeSpec.classBuilder("MyApp")
.addProperty(
PropertySpec.builder("appNameRes", Int::class.asTypeName())
.getter(
FunSpec.getterBuilder()
.addCode(
"""return %T.string.app_name""",
ClassName.bestGuess("com.example.app.R")
)
.build()
)
.build()
)
.build()
)
.build()
val appFile = createAppFile()

val appProject = ProjectSpec("app") {
addBuildSpec(
Expand Down Expand Up @@ -253,4 +236,83 @@ class UnusedDependenciesPluginTest : BasePluginTest() {
// one last check to make sure the manifest wasn't generated, since that would invalidate the test
File(testProjectDir, "/lib1/src/main/AndroidManifest.xml").exists() shouldBe false
}

@Test
fun `module with generated string resource used in subject module should not be unused`() {
val appProject = ProjectSpec("app") {
addBuildSpec(
ProjectBuildSpec {
addPlugin("""id("com.android.library")""")
addPlugin("kotlin(\"android\")")
android = true
addProjectDependency("api", jvmSub1)
}
)
addSrcSpec(
ProjectSrcSpec(Path.of("src/main/java")) {
addFileSpec(createAppFile())
}
)
addSrcSpec(
ProjectSrcSpec(Path.of("src/main")) {
addRawFile(
RawFile(
"AndroidManifest.xml",
"""<manifest package="com.example.app" />
""".trimMargin()
)
)
}
)
}

val androidSub1 = ProjectSpec("lib-1") {

addBuildSpec(
ProjectBuildSpec {
addPlugin("""id("com.android.library")""")
addPlugin("kotlin(\"android\")")
android = true
addBlock(
"""
|android {
| defaultConfig {
| resValue("string", "app_name", "AppName")
| }
|}
""".trimMargin()
)
}
)
}

ProjectSpec("project") {
addSubproject(appProject)
addSubproject(androidSub1)
addSettingsSpec(projectSettings.build())
addBuildSpec(projectBuild.build())
}
.writeIn(testProjectDir.toPath())

shouldSucceed("moduleCheck")
}

fun createAppFile() = FileSpec.builder("com.example.app", "MyApp")
.addType(
TypeSpec.classBuilder("MyApp")
.addProperty(
PropertySpec.builder("appNameRes", Int::class.asTypeName())
.getter(
FunSpec.getterBuilder()
.addCode(
"""return %T.string.app_name""",
ClassName.bestGuess("com.example.app.R")
)
.build()
)
.build()
)
.build()
)
.build()
}

0 comments on commit b1fe6ac

Please sign in to comment.