Skip to content

Commit

Permalink
Gradle plugin: use PatternSet instead of FileCollection for inputs
Browse files Browse the repository at this point in the history
### What's done:
* Fix functional test
  • Loading branch information
petertrr committed Nov 11, 2021
1 parent 8713d4d commit 5bb7885
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: gradle-test-report-${{ matrix.os }}
name: gradle-test-report-${{ runner.os }}
path: 'diktat-gradle-plugin/build/reports/'
retention-days: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DiktatGradlePluginFunctionalTest {
buildFile.appendText(
"""${System.lineSeparator()}
diktat {
inputs = files("src/**/*.kt")
inputs { include("src/**/*.kt") }
reporterType = "json"
output = "test.txt"
}
Expand All @@ -69,7 +69,7 @@ class DiktatGradlePluginFunctionalTest {
buildFile.appendText(
"""${System.lineSeparator()}
diktat {
inputs = files("src/**/*.kt")
inputs { include("src/**/*.kt") }
}
""".trimIndent()
)
Expand All @@ -88,61 +88,56 @@ class DiktatGradlePluginFunctionalTest {
buildFile.appendText(
"""${System.lineSeparator()}
diktat {
inputs = files("src/**/*.kt")
excludes = files("src/**/Test.kt")
inputs {
include("src/**/*.kt")
exclude("src/**/Test.kt")
}
}
""".trimIndent()
)
val result = runDiktat(testProjectDir)

val diktatCheckBuildResult = result.task(":$DIKTAT_CHECK_TASK")
requireNotNull(diktatCheckBuildResult)
Assertions.assertEquals(TaskOutcome.SUCCESS, diktatCheckBuildResult.outcome)
Assertions.assertEquals(TaskOutcome.NO_SOURCE, diktatCheckBuildResult.outcome)
}

@Test
fun `should not run diktat with ktlint's default includes when no files match include patterns`() {
buildFile.appendText(
"""${System.lineSeparator()}
diktat {
inputs = files("nonexistent-directory/src/**/*.kt")
inputs { include ("nonexistent-directory/src/**/*.kt") }
}
""".trimIndent()
)
val result = runDiktat(testProjectDir, arguments = listOf("--info"))

// if patterns in gradle are not checked for matching, they are passed to ktlint, which does nothing
val diktatCheckBuildResult = result.task(":$DIKTAT_CHECK_TASK")
requireNotNull(diktatCheckBuildResult)
Assertions.assertEquals(TaskOutcome.SUCCESS, diktatCheckBuildResult.outcome)
Assertions.assertEquals(TaskOutcome.NO_SOURCE, diktatCheckBuildResult.outcome)
Assertions.assertFalse(
result.output.contains("Skipping diktat execution")
)
Assertions.assertFalse(
result.output.contains("Inputs for $DIKTAT_CHECK_TASK do not exist, will not run diktat")
)
}

@Test
fun `should not run diktat with ktlint's default includes when no files match include patterns - 2`() {
buildFile.appendText(
"""${System.lineSeparator()}
diktat {
inputs = fileTree("nonexistent-directory/src").apply { include("**/*.kt") }
inputs { include("nonexistent-directory/src/**/*.kt") }
}
""".trimIndent()
)
val result = runDiktat(testProjectDir, arguments = listOf("--info"))

val diktatCheckBuildResult = result.task(":$DIKTAT_CHECK_TASK")
requireNotNull(diktatCheckBuildResult)
Assertions.assertEquals(TaskOutcome.SUCCESS, diktatCheckBuildResult.outcome)
Assertions.assertEquals(TaskOutcome.NO_SOURCE, diktatCheckBuildResult.outcome)
Assertions.assertTrue(
result.output.contains("Skipping diktat execution")
)
Assertions.assertTrue(
result.output.contains("Inputs for $DIKTAT_CHECK_TASK do not exist, will not run diktat")
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DiktatGradlePluginMultiprojectFunctionalTest {

val diktatCheckRootResult = result.task(":$DIKTAT_CHECK_TASK")
requireNotNull(diktatCheckRootResult)
Assertions.assertEquals(TaskOutcome.SUCCESS, diktatCheckRootResult.outcome) {
Assertions.assertEquals(TaskOutcome.NO_SOURCE, diktatCheckRootResult.outcome) {
"Task for root project with empty sources should succeed"
}

Expand Down

0 comments on commit 5bb7885

Please sign in to comment.