Skip to content

Commit

Permalink
fix JakeWharton#380 Quick-Fix incorrectly applied in kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
jk-byjus authored and hannesa2 committed Nov 28, 2021
1 parent 551d958 commit 7a250e6
Showing 1 changed file with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ class WrongTimberUsageDetectorTest {
|- Log.d("TAG", "msg")
|+ Timber.d("msg")
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|import android.util.Log
|class Example {
| fun log() {
| Log.d("TAG", "msg")
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:5: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| Log.d("TAG", "msg")
| ~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
.expectFixDiffs("""
|Fix for src/foo/Example.kt line 5: Replace with Timber.tag("TAG").d("msg"):
|@@ -5 +5
|- Log.d("TAG", "msg")
|+ Timber.tag("TAG").d("msg")
|Fix for src/foo/Example.kt line 5: Replace with Timber.d("msg"):
|@@ -5 +5
|- Log.d("TAG", "msg")
|+ Timber.d("msg")""".trimMargin())
}

@Test fun usingAndroidLogWithThreeArguments() {
Expand Down Expand Up @@ -120,6 +148,25 @@ class WrongTimberUsageDetectorTest {
|- Log.d("TAG", "msg", Exception())
|+ Timber.d(Exception(), "msg")
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|import android.util.Log
|class Example {
| fun log() {
| Log.d("TAG", "msg", Exception())
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:5: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| Log.d("TAG", "msg", Exception())
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
}

@Test fun usingFullyQualifiedAndroidLogWithTwoArguments() {
Expand Down Expand Up @@ -168,6 +215,34 @@ class WrongTimberUsageDetectorTest {
|- android.util.Log.d("TAG", "msg")
|+ Timber.d("msg")
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|class Example {
| fun log() {
| android.util.Log.d("TAG", "msg")
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:4: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| android.util.Log.d("TAG", "msg")
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
.expectFixDiffs("""
|Fix for src/foo/Example.kt line 4: Replace with Timber.tag("TAG").d("msg"):
|@@ -4 +4
|- android.util.Log.d("TAG", "msg")
|+ Timber.tag("TAG").d("msg")
|Fix for src/foo/Example.kt line 4: Replace with Timber.d("msg"):
|@@ -4 +4
|- android.util.Log.d("TAG", "msg")
|+ Timber.d("msg")
|""".trimMargin())
}

@Test fun usingFullyQualifiedAndroidLogWithThreeArguments() {
Expand Down Expand Up @@ -216,6 +291,24 @@ class WrongTimberUsageDetectorTest {
|- android.util.Log.d("TAG", "msg", Exception())
|+ Timber.d(Exception(), "msg")
|""".trimMargin())

lint()
.files(
kt("""
|package foo
|class Example {
| fun log() {
| android.util.Log.d("TAG", "msg", Exception());
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.run()
.expect("""
|src/foo/Example.kt:4: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
| android.util.Log.d("TAG", "msg", Exception());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|0 errors, 1 warnings""".trimMargin())
}

@Test fun innerStringFormat() {
Expand Down

0 comments on commit 7a250e6

Please sign in to comment.