-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
347 additions
and
1 deletion.
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
342 changes: 342 additions & 0 deletions
342
src/test/groovy/com/netflix/nebula/lint/plugin/Gradle8LintReportTaskSpec.groovy
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,342 @@ | ||
package com.netflix.nebula.lint.plugin | ||
|
||
import nebula.test.IntegrationTestKitSpec | ||
import spock.lang.Issue | ||
|
||
class Gradle8LintReportTaskSpec extends IntegrationTestKitSpec { | ||
def setup() { | ||
gradleVersion = '8.0-rc-1' | ||
debug = true | ||
} | ||
|
||
def 'generate a report'() { | ||
when: | ||
buildFile.text = """ | ||
plugins { | ||
id 'nebula.lint' | ||
id 'java' | ||
} | ||
gradleLint { | ||
rules = ['dependency-parentheses'] | ||
reportFormat = 'text' | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation('com.google.guava:guava:18.0') | ||
} | ||
""" | ||
|
||
then: | ||
runTasks('generateGradleLintReport') | ||
|
||
when: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
|
||
then: | ||
report.text.contains('Violation: Rule=dependency-parentheses') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
def 'generate a report with only applied fixes'() { | ||
given: | ||
buildFile.text = """ | ||
plugins { | ||
id 'java' | ||
id 'nebula.lint' | ||
} | ||
gradleLint { | ||
rules = ['dependency-tuple', 'dependency-parentheses'] | ||
reportFormat = 'text' | ||
reportOnlyFixableViolations = true | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation(group: 'com.google.guava', name: 'guava', version: '18.0') | ||
} | ||
""" | ||
|
||
when: | ||
def result = runTasks('autoLintGradle') | ||
|
||
then: | ||
result.output.contains("dependency-tuple") | ||
result.output.contains("dependency-parentheses") | ||
|
||
then: | ||
runTasks('generateGradleLintReport') | ||
|
||
when: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
|
||
then: | ||
report.text.contains('Violation: Rule=dependency-tuple') | ||
! report.text.contains('Violation: Rule=dependency-parentheses') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
def 'generate a report with different type through parameter from cli'() { | ||
when: | ||
buildFile.text = """ | ||
plugins { | ||
id 'nebula.lint' | ||
id 'java' | ||
} | ||
gradleLint { | ||
rules = ['dependency-parentheses'] | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation('com.google.guava:guava:18.0') | ||
} | ||
""" | ||
|
||
then: | ||
runTasks('generateGradleLintReport', '-PgradleLint.reportFormat=text') | ||
|
||
when: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
|
||
then: | ||
report.text.contains('Violation: Rule=dependency-parentheses') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
def 'generate a report with only applied fixes using cli param to enable it'() { | ||
given: | ||
buildFile.text = """ | ||
plugins { | ||
id 'java' | ||
id 'nebula.lint' | ||
} | ||
gradleLint { | ||
rules = ['dependency-tuple', 'dependency-parentheses'] | ||
reportFormat = 'text' | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation(group: 'com.google.guava', name: 'guava', version: '18.0') | ||
} | ||
""" | ||
|
||
when: | ||
runTasks('generateGradleLintReport', '-PgradleLint.reportOnlyFixableViolations=true') | ||
|
||
then: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
report.text.contains('Violation: Rule=dependency-tuple') | ||
! report.text.contains('Violation: Rule=dependency-parentheses') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
def 'generate a report with all rules using cli param to disable it to override extension'() { | ||
given: | ||
buildFile.text = """ | ||
plugins { | ||
id 'java' | ||
id 'nebula.lint' | ||
} | ||
gradleLint { | ||
rules = ['dependency-tuple', 'dependency-parentheses'] | ||
reportFormat = 'text' | ||
reportOnlyFixableViolations = true | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation(group: 'com.google.guava', name: 'guava', version: '18.0') | ||
} | ||
""" | ||
|
||
when: | ||
runTasks('generateGradleLintReport', '-PgradleLint.reportOnlyFixableViolations=false') | ||
|
||
then: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
report.text.contains('Violation: Rule=dependency-tuple') | ||
report.text.contains('Violation: Rule=dependency-parentheses') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
def 'warning without autofixes are not reported if flag is enabled'() { | ||
given: | ||
buildFile.text = """ | ||
plugins { | ||
id 'nebula.lint' | ||
id 'java' | ||
} | ||
gradleLint { | ||
rules = ['duplicate-dependency-class'] | ||
reportFormat = 'text' | ||
reportOnlyFixableViolations = true | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation 'com.google.guava:guava:18.0' | ||
implementation 'com.google.collections:google-collections:1.0' | ||
} | ||
""" | ||
|
||
when: | ||
runTasks('generateGradleLintReport') | ||
|
||
then: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
! report.text.contains('Violation: Rule=duplicate-dependency-class') | ||
} | ||
|
||
def 'critical rules fail task'() { | ||
when: | ||
buildFile.text = """ | ||
plugins { | ||
id 'java' | ||
id 'nebula.lint' | ||
} | ||
gradleLint.criticalRules = ['dependency-parentheses'] | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation('com.google.guava:guava:18.0') | ||
} | ||
""" | ||
|
||
then: | ||
def results = runTasksAndFail('generateGradleLintReport') | ||
results.output.contains('FAIL') | ||
results.output.contains('Task failed with an exception') | ||
} | ||
|
||
def 'generate a report for a multi-module project'() { | ||
when: | ||
buildFile.text = """ | ||
plugins { | ||
id 'nebula.lint' | ||
} | ||
""" | ||
|
||
def sub = addSubproject('sub') | ||
new File(sub, 'build.gradle').text = """ | ||
plugins { | ||
id 'java' | ||
} | ||
gradleLint { | ||
rules = ['dependency-parentheses'] | ||
reportFormat = 'text' | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation('com.google.guava:guava:18.0') | ||
} | ||
""" | ||
|
||
then: | ||
runTasks('generateGradleLintReport') | ||
|
||
when: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
|
||
then: | ||
report.text.contains('Violation: Rule=dependency-parentheses') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
@Issue('#137') | ||
def 'generate a report for a DependencyService based rule'() { | ||
when: | ||
buildFile.text = """ | ||
plugins { | ||
id 'nebula.lint' | ||
id 'java' | ||
} | ||
gradleLint { | ||
rules = ['duplicate-dependency-class'] | ||
reportFormat = 'text' | ||
} | ||
repositories { mavenCentral() } | ||
dependencies { | ||
implementation 'com.google.guava:guava:18.0' | ||
implementation 'com.google.collections:google-collections:1.0' | ||
} | ||
""" | ||
|
||
then: | ||
runTasks('generateGradleLintReport') | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.txt') } | ||
|
||
then: | ||
report.text.contains('Violation: Rule=duplicate-dependency-class') | ||
report.text.contains('TotalFiles=1') | ||
} | ||
|
||
def 'generate a xml report for a multi-module project'() { | ||
when: | ||
buildFile.text = """ | ||
plugins { | ||
id 'java' | ||
id 'nebula.lint' | ||
} | ||
allprojects { | ||
gradleLint { | ||
rules = ['dependency-parentheses'] | ||
reportFormat = 'xml' | ||
} | ||
repositories { mavenCentral() } | ||
} | ||
dependencies { | ||
implementation('com.google.guava:guava:19.0') | ||
} | ||
""" | ||
|
||
def sub = addSubproject('sub') | ||
new File(sub, 'build.gradle').text = """ | ||
plugins { | ||
id 'java' | ||
} | ||
dependencies { | ||
implementation('com.google.guava:guava:18.0') | ||
} | ||
""" | ||
|
||
then: | ||
runTasks('generateGradleLintReport') | ||
|
||
when: | ||
def report = new File(projectDir, 'build/reports/gradleLint').listFiles().find { it.name.endsWith('.xml') } | ||
|
||
then: | ||
def reportXml = report.text | ||
reportXml.count('Violation ruleName=\'dependency-parentheses\'') == 2 | ||
reportXml.contains('implementation(\'com.google.guava:guava:19.0\')') | ||
reportXml.contains('implementation(\'com.google.guava:guava:18.0\')') | ||
reportXml.contains("<Package path='$projectDir.absolutePath'") | ||
reportXml.contains("<Package path='$projectDir.absolutePath/sub'") | ||
} | ||
} |