Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
In order to reproduce #199, added kotlin-kapt to all kotlin test proj…
Browse files Browse the repository at this point in the history
…ects.

Added special configuration-only tests that also include kotlin projects even when the tool is Kotlin only.
  • Loading branch information
tasomaniac committed Nov 8, 2019
1 parent 4d286a9 commit 239a29e
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.novoda.staticanalysis.internal.checkstyle

import com.novoda.test.Fixtures
import com.novoda.test.TestProjectRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized.class)
class CheckstyleConfigurationTest {

@Parameterized.Parameters(name = "{0}")
static Iterable<TestProjectRule> rules() {
return [
TestProjectRule.forJavaProject(),
TestProjectRule.forKotlinProject(),
TestProjectRule.forAndroidProject(),
TestProjectRule.forAndroidKotlinProject(),
]
}

@Rule
public final TestProjectRule projectRule

CheckstyleConfigurationTest(TestProjectRule projectRule) {
this.projectRule = projectRule
}

@Test
void shouldConfigureSuccessFully() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Checkstyle.SOURCES_WITH_WARNINGS)
.withToolsConfig("checkstyle { }")
.build('check', '--dry-run')
}

@Test
void shouldNotFailBuildWhenCheckstyleIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Checkstyle.SOURCES_WITH_WARNINGS)
.withToolsConfig("""
checkstyle {
configFile new File('${Fixtures.Checkstyle.MODULES.path}')
}
checkstyle {
ignoreFailures = false
}
""")
.build('check', '--dry-run')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,6 @@ public class CheckstyleIntegrationTest {
result.buildFileUrl('reports/checkstyle/main.html'))
}

@Test
void shouldNotFailBuildWhenCheckstyleIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Checkstyle.SOURCES_WITH_WARNINGS)
.withPenalty('none')
.withToolsConfig("""
checkstyle {
configFile new File('${Fixtures.Checkstyle.MODULES.path}')
}
checkstyle {
ignoreFailures = false
}
""")
.build('check', '--dry-run')
}

private static String checkstyle(String configFile, String... configs) {
"""checkstyle {
${configFile}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.novoda.staticanalysis.internal.findbugs


import com.novoda.test.TestProjectRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

import static com.novoda.test.Fixtures.Findbugs.SOURCES_WITH_LOW_VIOLATION

@RunWith(Parameterized.class)
class FindbugsConfigurationTest {

@Parameterized.Parameters(name = "{0}")
static Iterable<TestProjectRule> rules() {
return [
TestProjectRule.forJavaProject(),
TestProjectRule.forKotlinProject(),
TestProjectRule.forAndroidProject(),
TestProjectRule.forAndroidKotlinProject(),
]
}

@Rule
public final TestProjectRule projectRule

FindbugsConfigurationTest(TestProjectRule projectRule) {
this.projectRule = projectRule
}

@Test
void shouldConfigureSuccessFully() {
projectRule.newProject()
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION)
.withToolsConfig("findbugs { }")
.build('check', '--dry-run')
}

@Test
void shouldNotFailBuildWhenFindbugsIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION)
.withToolsConfig("""
findbugs { }
findbugs {
ignoreFailures = false
}
""")
.build('check', '--dry-run')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,20 +346,6 @@ class FindbugsIntegrationTest {
Truth.assertThat(result.outcome(':checkFindbugsClasses')).isEqualTo(TaskOutcome.SUCCESS)
}

@Test
void shouldNotFailBuildWhenFindbugsIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION)
.withPenalty('none')
.withToolsConfig("""
findbugs { }
findbugs {
ignoreFailures = false
}
""")
.build('check')
}

@Test
void shouldBeUpToDateWhenCheckTaskRunsAgain() {
def project = projectRule.newProject()
Expand Down Expand Up @@ -395,7 +381,7 @@ class FindbugsIntegrationTest {
* The custom task created in the snippet below will check whether {@code Findbugs} tasks with
* empty {@code source} will have empty {@code classes} too. </p>
*/
private String addCheckFindbugsClassesTask() {
private static String addCheckFindbugsClassesTask() {
'''
project.task('checkFindbugsClasses') {
dependsOn project.tasks.findByName('evaluateViolations')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.novoda.staticanalysis.internal.pmd

import com.novoda.test.Fixtures
import com.novoda.test.TestProjectRule
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized.class)
class PmdConfigurationTest {

@Parameterized.Parameters(name = "{0}")
static Iterable<TestProjectRule> rules() {
return [
TestProjectRule.forJavaProject(),
TestProjectRule.forKotlinProject(),
TestProjectRule.forAndroidProject(),
TestProjectRule.forAndroidKotlinProject(),
]
}

@Rule
public final TestProjectRule projectRule

PmdConfigurationTest(TestProjectRule projectRule) {
this.projectRule = projectRule
}

@Test
void shouldConfigureSuccessFully() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Pmd.SOURCES_WITH_PRIORITY_1_VIOLATION)
.withToolsConfig("pmd { }")
.build('check', '--dry-run')
}

@Test
void shouldNotFailBuildWhenPmdIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Pmd.SOURCES_WITH_PRIORITY_1_VIOLATION)
.withToolsConfig("""
pmd {
}
pmd {
ignoreFailures = false
}
""")
.build('check', '--dry-run')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,6 @@ public class PmdIntegrationTest {
assertThat(result.logs).doesNotContainPmdViolations()
}

@Test
void shouldNotFailBuildWhenPmdIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Pmd.SOURCES_WITH_PRIORITY_1_VIOLATION)
.withPenalty('none')
.withToolsConfig("""
pmd {
ruleSetFiles = $DEFAULT_RULES
}
pmd {
ignoreFailures = false
}
""")
.build('check')
}

private String pmd(String rules, String... configs) {
"""pmd {
ruleSetFiles = $rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ repositories {
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt' // adding kapt since we face compat issues before
apply plugin: 'com.novoda.static-analysis'
android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt' // adding kapt since we face compat issues before
apply plugin: 'com.novoda.static-analysis'
repositories {
Expand Down
5 changes: 3 additions & 2 deletions sample-multi-module/core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'

repositories {
mavenCentral()
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

compileKotlin {
Expand Down
1 change: 1 addition & 0 deletions sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.novoda.static-analysis'

Expand Down

0 comments on commit 239a29e

Please sign in to comment.