-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What's done: * Respect ignoreFailures flag * Made excludes non-nullable * Fix for file patterns * Use plugin.apply in unit tests * Use GradleVersion from gradle API instead of custom * Jacoco reports for all functional tests * Introduced Utils for runctional tests * Functional tests for Groovy DSL
- Loading branch information
Showing
10 changed files
with
294 additions
and
137 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
40 changes: 40 additions & 0 deletions
40
...tionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginGroovyFunctionalTest.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,40 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl | ||
import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
|
||
class DiktatGradlePluginGroovyFunctionalTest { | ||
private val testProjectDir = TemporaryFolder() | ||
private lateinit var buildFile: File | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
testProjectDir.create() | ||
val buildInitDsl = BuildInitDsl.GROOVY | ||
createExampleProject(testProjectDir, File("../examples/gradle-groovy-dsl"), buildInitDsl) | ||
buildFile = testProjectDir.root.resolve(buildInitDsl.fileNameFor("build")) | ||
} | ||
|
||
@AfterEach | ||
fun tearDown() { | ||
testProjectDir.delete() | ||
} | ||
|
||
@Test | ||
fun `should execute diktatCheck on default values`() { | ||
val result = runDiktat(testProjectDir, shouldSucceed = false) | ||
|
||
val diktatCheckBuildResult = result.task(":${DiktatGradlePlugin.DIKTAT_CHECK_TASK}") | ||
requireNotNull(diktatCheckBuildResult) | ||
Assertions.assertEquals(TaskOutcome.FAILED, diktatCheckBuildResult.outcome) | ||
Assertions.assertTrue( | ||
result.output.contains("[HEADER_MISSING_OR_WRONG_COPYRIGHT]") | ||
) | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/Utils.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,70 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl | ||
import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder | ||
import org.gradle.testkit.runner.GradleRunner | ||
import java.io.File | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
internal val testsCounter = AtomicInteger(0) | ||
|
||
internal fun createExampleProject(testProjectDir: TemporaryFolder, | ||
exampleProject: File, | ||
buildInitDsl: BuildInitDsl | ||
) { | ||
exampleProject.copyRecursively(testProjectDir.root) | ||
val buildFileName = buildInitDsl.fileNameFor("build") | ||
File(testProjectDir.root, buildFileName).delete() | ||
testProjectDir.newFile(buildFileName).apply { | ||
writeText( | ||
""" | ||
plugins { | ||
id("org.cqfn.diktat.diktat-gradle-plugin") | ||
} | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
""".trimIndent() | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* @param arguments additional arguments to pass to [GradleRunner] | ||
*/ | ||
internal fun runDiktat(testProjectDir: TemporaryFolder, | ||
shouldSucceed: Boolean = true, | ||
arguments: List<String> = emptyList(), | ||
configureRunner: GradleRunner.() -> GradleRunner = { this } | ||
) = GradleRunner.create() | ||
.run(configureRunner) | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments(*arguments.toTypedArray(), DiktatGradlePlugin.DIKTAT_CHECK_TASK) | ||
.withPluginClasspath() | ||
.withJaCoCo(testsCounter.incrementAndGet()) | ||
.forwardOutput() | ||
.runCatching { | ||
if (shouldSucceed) build() else buildAndFail() | ||
} | ||
.also { | ||
require(it.isSuccess) { "Running gradle returned exception ${it.exceptionOrNull()}" } | ||
} | ||
.getOrNull()!! | ||
|
||
/** | ||
* This is support for jacoco reports in tests run with gradle TestKit | ||
*/ | ||
private fun GradleRunner.withJaCoCo(number: Int) = apply { | ||
javaClass.classLoader | ||
.getResourceAsStream("testkit-gradle.properties") | ||
.also { it ?: error("properties file for testkit is not available, check build configuration") } | ||
?.use { propertiesFileStream -> | ||
val text = propertiesFileStream.reader().readText() | ||
File(projectDir, "gradle.properties").createNewFile() | ||
File(projectDir, "gradle.properties").writer().use { | ||
it.write(text.replace("functionalTest.exec", "functionalTest-$number.exec")) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
f74d7ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: