-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve hick-up when repetitive executed
- Loading branch information
Showing
8 changed files
with
148 additions
and
30 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
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
19 changes: 19 additions & 0 deletions
19
kmock-gradle/src/main/kotlin/tech/antibytes/gradle/kmock/source/KmpSharedSourceCleaner.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,19 @@ | ||
/* | ||
* Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved. | ||
* | ||
* Use of this source code is governed by Apache v2.0 | ||
*/ | ||
|
||
package tech.antibytes.gradle.kmock.source | ||
|
||
import org.gradle.api.Project | ||
import tech.antibytes.gradle.kmock.KMockPluginContract | ||
|
||
internal object KmpSharedSourceCleaner : KMockPluginContract.KmpSharedSourceCleaner { | ||
override fun cleanMetaSources(project: Project, sourceSets: Set<String>) { | ||
sourceSets.forEach { sourceSet -> | ||
val platform = sourceSet.substring(0, sourceSet.length - 4) | ||
project.file("${project.buildDir.absolutePath}/generated/ksp/$platform").deleteRecursively() | ||
} | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
...k-gradle/src/test/kotlin/tech/antibytes/gradle/kmock/source/KmpSharedSourceCleanerSpec.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,75 @@ | ||
/* | ||
* Copyright (c) 2022 Matthias Geisler (bitPogo) / All rights reserved. | ||
* | ||
* Use of this source code is governed by Apache v2.0 | ||
*/ | ||
|
||
package tech.antibytes.gradle.kmock.source | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import tech.antibytes.gradle.kmock.KMockPluginContract | ||
import tech.antibytes.util.test.fulfils | ||
import tech.antibytes.util.test.mustBe | ||
import java.io.File | ||
|
||
class KmpSharedSourceCleanerSpec { | ||
@TempDir | ||
private lateinit var buildDir: File | ||
private lateinit var file: File | ||
private lateinit var project: Project | ||
|
||
@BeforeEach | ||
fun setup() { | ||
project = ProjectBuilder.builder().build() | ||
project.buildDir = buildDir | ||
} | ||
|
||
private fun createStubs(): File { | ||
val generated = File(buildDir, "generated") | ||
generated.mkdir() | ||
|
||
val ksp = File(generated, "ksp") | ||
ksp.mkdir() | ||
|
||
val targetPlatform = File(ksp, "platform") | ||
targetPlatform.mkdir() | ||
|
||
val target = File(targetPlatform, "target") | ||
target.mkdir() | ||
|
||
val sub = File(target, "sub") | ||
sub.mkdir() | ||
|
||
val file1 = File(target, "Something.kt") | ||
file1.createNewFile() | ||
|
||
val file2 = File(sub, "SomethingElse.kt") | ||
file2.createNewFile() | ||
|
||
file1.writeText("content") | ||
file2.writeText("content") | ||
|
||
return targetPlatform | ||
} | ||
|
||
@Test | ||
fun `It fulfils KmpSharedSourceCleaner`() { | ||
KmpSharedSourceCleaner fulfils KMockPluginContract.KmpSharedSourceCleaner::class | ||
} | ||
|
||
@Test | ||
fun `Given cleanMetaSources is called, it removes the given SharedSources from the generated KSP output`() { | ||
// Given | ||
val platform = createStubs() | ||
|
||
// When | ||
KmpSharedSourceCleaner.cleanMetaSources(project, setOf("${platform.name}Test")) | ||
|
||
// Then | ||
platform.exists() mustBe false | ||
} | ||
} |
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