Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradle-plugin: fix docs and tests for Groovy DSL #1428

Merged
merged 3 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ repositories {
}

// default value is needed for correct gradle loading in IDEA; actual value from maven is used during build
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.43.0") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.1.0"
// To debug gradle plugin, please set `diktatVersion` manually to the current maven project version.
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.46.1") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.2.1"
val junitVersion = project.properties.getOrDefault("junitVersion", "5.8.1") as String
val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.7") as String
dependencies {
Expand Down Expand Up @@ -107,7 +108,7 @@ val functionalTest = sourceSets.create("functionalTest") {
runtimeClasspath += output + compileClasspath
}
tasks.getByName<Test>("functionalTest") {
dependsOn("test")
shouldRunAfter("test")
testClassesDirs = functionalTest.output.classesDirs
classpath = functionalTest.runtimeClasspath
maxParallelForks = Runtime.getRuntime().availableProcessors()
Expand All @@ -131,7 +132,7 @@ jacocoTestKit {
applyTo("functionalTestRuntimeOnly", tasks.named("functionalTest"))
}
tasks.jacocoTestReport {
dependsOn(tasks.withType<Test>())
shouldRunAfter(tasks.withType<Test>())
executionData(
fileTree("$buildDir/jacoco").apply {
include("*.exec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ class DiktatGradlePluginGroovyFunctionalTest {
}

@Test
fun `should execute diktatCheck on default values`() {
fun `should execute diktatCheck with 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("[FILE_NAME_MATCH_CLASS]")
assertDiktatExecuted(result)
}

@Test
fun `should execute diktatCheck with explicit configuration`() {
buildFile.appendText(
"""${System.lineSeparator()}
diktat {
inputs { it.include("src/**/*.kt") }
reporter = "plain"
diktatConfigFile = file(rootDir.path + "/diktat-analysis.yml")
}
""".trimIndent()
)

val result = runDiktat(testProjectDir, shouldSucceed = false)

assertDiktatExecuted(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ 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.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.Assertions
import java.io.File
import java.util.concurrent.atomic.AtomicInteger

Expand Down Expand Up @@ -71,3 +74,12 @@ private fun GradleRunner.withJaCoCo(number: Int) = apply {
}
}
}

fun assertDiktatExecuted(result: BuildResult) {
val diktatCheckBuildResult = result.task(":${DiktatGradlePlugin.DIKTAT_CHECK_TASK}")
requireNotNull(diktatCheckBuildResult)
Assertions.assertEquals(TaskOutcome.FAILED, diktatCheckBuildResult.outcome)
Assertions.assertTrue(
result.output.contains("[FILE_NAME_MATCH_CLASS]")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ open class DiktatExtension(
var reporter: String = "plain"

/**
* Type of output
* Default: System.out
* Destination for reporter. If empty, will write to stdout.
*/
var output: String = ""

Expand Down
3 changes: 2 additions & 1 deletion examples/gradle-groovy-dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ repositories {
}

diktat {
inputs { include ("src/**/*.kt") }
inputs { it.include ("src/**/*.kt") }
diktatConfigFile = file(rootDir.path + "/diktat-analysis.yml")
}