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

Commit

Permalink
test: add tests for the MultipleSpaceDetector
Browse files Browse the repository at this point in the history
Add a test for the failure case and a test for the success case
  • Loading branch information
Chesire committed May 8, 2020
1 parent 5d11365 commit 1e66368
Showing 1 changed file with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ package com.chesire.lintrules.gradle.detectors

import com.android.tools.lint.checks.infrastructure.TestFiles
import com.android.tools.lint.checks.infrastructure.TestLintTask
import com.chesire.lintrules.gradle.issues.LexicographicDependencies
import com.chesire.lintrules.gradle.issues.MultipleSpace
import org.junit.Test

class MultipleSpaceDetectorTests {
@Test
fun `multiple space test`() {
fun `multipleSpace should be no issue with valid Gradle file`() {
TestLintTask
.lint()
.allowMissingSdk()
.files(
TestFiles.gradle(
"""
apply plugin: 'java-library'
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation project(path: ":lintrules-common")
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:0.0.0"
compileOnly "com.android.tools.lint:lint-api:0.0.0"
compileOnly "com.android.tools.lint:lint-api:0.0.0"
compileOnly "com.android.tools.lint:lint-checks:0.0.0"
testImplementation "com.android.tools.lint:lint:0.0.0"
Expand All @@ -42,4 +41,55 @@ jar {
.run()
.expectClean()
}

@Test
fun `multipleSpace should flag issues`() {
TestLintTask
.lint()
.allowMissingSdk()
.files(
TestFiles.gradle(
"""
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation project(path: ":lintrules-common")
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:0.0.0"
compileOnly "com.android.tools.lint:lint-api:0.0.0"
compileOnly "com.android.tools.lint:lint-checks:0.0.0"
testImplementation "com.android.tools.lint:lint:0.0.0"
testImplementation "com.android.tools.lint:lint-tests:0.0.0"
}
jar {
manifest {
attributes('Lint-Registry-v2': 'com.chesire.lintrules.gradle.GradleLintRegistry')
}
}
""".trimIndent()
).indented()
)
.issues(MultipleSpace.issue)
.run()
.expect(
"""
|build.gradle:1: Information: Multiple spaces should not be used. [MultipleSpace]
|apply plugin: 'java-library'
| ~~
|build.gradle:5: Information: Multiple spaces should not be used. [MultipleSpace]
| implementation project(path: ":lintrules-common")
| ~~
|build.gradle:9: Information: Multiple spaces should not be used. [MultipleSpace]
| compileOnly "com.android.tools.lint:lint-api:0.0.0"
| ~~
|build.gradle:17: Information: Multiple spaces should not be used. [MultipleSpace]
| manifest {
| ~~
|0 errors, 0 warnings""".trimMargin()
)
}
}

0 comments on commit 1e66368

Please sign in to comment.