Skip to content

Commit

Permalink
Run tests on all issues to surface fallthrough errors
Browse files Browse the repository at this point in the history
  • Loading branch information
John Rodriguez committed Aug 12, 2021
1 parent 8537da2 commit 880a2e6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.google.auto.service.AutoService
@AutoService(value = [IssueRegistry::class])
class TimberIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = WrongTimberUsageDetector.issues
get() = WrongTimberUsageDetector.issues.asList()

override val api: Int
get() = CURRENT_API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ class WrongTimberUsageDetector : Detector(), UastScanner {
implementation = Implementation(WrongTimberUsageDetector::class.java, JAVA_FILE_SCOPE)
)

val issues = listOf(
val issues = arrayOf(
ISSUE_LOG, ISSUE_FORMAT, ISSUE_THROWABLE, ISSUE_BINARY, ISSUE_ARG_COUNT, ISSUE_ARG_TYPES,
ISSUE_TAG_LENGTH, ISSUE_EXCEPTION_LOGGING
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.android.tools.lint.checks.infrastructure.TestFiles.kotlin
import com.android.tools.lint.checks.infrastructure.TestFiles.manifest
import com.android.tools.lint.checks.infrastructure.TestLintTask.lint
import org.junit.Test
import timber.lint.WrongTimberUsageDetector.Companion.issues

class WrongTimberUsageDetectorTest {
private val TIMBER_STUB = kotlin("""
Expand Down Expand Up @@ -41,7 +42,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
Expand Down Expand Up @@ -91,7 +92,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
Expand Down Expand Up @@ -139,7 +140,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:4: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
Expand Down Expand Up @@ -187,7 +188,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_LOG)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:4: Warning: Using 'Log' instead of 'Timber' [LogNotTimber]
Expand Down Expand Up @@ -237,7 +238,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Warning: Using 'String#format' inside of 'Timber' [StringFormatInTimber]
Expand Down Expand Up @@ -284,7 +285,7 @@ class WrongTimberUsageDetectorTest {
// Remove when AGP 7.1.0-alpha07 is out
// https://groups.google.com/g/lint-dev/c/BigCO8sMhKU
.allowCompilationErrors()
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Using 'String#format' inside of 'Timber' [StringFormatInTimber]
Expand Down Expand Up @@ -328,7 +329,7 @@ class WrongTimberUsageDetectorTest {
| private fun id(s: String): String { return s }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Warning: Using 'String#format' inside of 'Timber' [StringFormatInTimber]
Expand All @@ -354,7 +355,7 @@ class WrongTimberUsageDetectorTest {
|}""".trimMargin())
// no kotlin equivalent, since nested assignments do not exist
)
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Using 'String#format' inside of 'Timber' [StringFormatInTimber]
Expand Down Expand Up @@ -385,7 +386,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -408,7 +409,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -429,7 +430,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_FORMAT)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -456,7 +457,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_THROWABLE)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Throwable should be first argument [ThrowableNotAtBeginning]
Expand Down Expand Up @@ -498,7 +499,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_BINARY)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -525,7 +526,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_BINARY)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Replace String concatenation with Timber's string formatting [BinaryOperationInTimber]
Expand Down Expand Up @@ -562,7 +563,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_BINARY)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Replace String concatenation with Timber's string formatting [BinaryOperationInTimber]
Expand Down Expand Up @@ -601,7 +602,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_BINARY)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:7: Warning: Replace String concatenation with Timber's string formatting [BinaryOperationInTimber]
Expand Down Expand Up @@ -638,7 +639,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_BINARY)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Replace String concatenation with Timber's string formatting [BinaryOperationInTimber]
Expand Down Expand Up @@ -667,7 +668,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_COUNT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: Wrong argument count, format string %s %s requires 2 but format call supplies 1 [TimberArgCount]
Expand Down Expand Up @@ -699,7 +700,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_COUNT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: Wrong argument count, format string %s requires 1 but format call supplies 2 [TimberArgCount]
Expand Down Expand Up @@ -731,7 +732,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_TYPES)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: Wrong argument type for formatting argument '#1' in %d: conversion is 'd', received String (argument #2 in method call) [TimberArgTypes]
Expand Down Expand Up @@ -764,7 +765,7 @@ class WrongTimberUsageDetectorTest {
|}""".trimMargin()),
manifest().minSdk(25)
)
.issues(WrongTimberUsageDetector.ISSUE_TAG_LENGTH)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: The logging tag can be at most 23 characters, was 24 (abcdefghijklmnopqrstuvwx) [TimberTagLength]
Expand Down Expand Up @@ -796,7 +797,7 @@ class WrongTimberUsageDetectorTest {
|}""".trimMargin()),
manifest().minSdk(25)
)
.issues(WrongTimberUsageDetector.ISSUE_TAG_LENGTH)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Error: The logging tag can be at most 23 characters, was 24 (abcdefghijklmnopqrstuvwx) [TimberTagLength]
Expand Down Expand Up @@ -826,7 +827,7 @@ class WrongTimberUsageDetectorTest {
|}""".trimMargin()),
manifest().minSdk(26)
)
.issues(WrongTimberUsageDetector.ISSUE_TAG_LENGTH)
.issues(*issues)
.run()
.expectClean()
}
Expand Down Expand Up @@ -854,7 +855,7 @@ class WrongTimberUsageDetectorTest {
|}""".trimMargin()),
manifest().minSdk(26)
)
.issues(WrongTimberUsageDetector.ISSUE_TAG_LENGTH)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -879,7 +880,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_COUNT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: Wrong argument count, format string %s %s requires 2 but format call supplies 1 [TimberArgCount]
Expand Down Expand Up @@ -911,7 +912,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_COUNT)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: Wrong argument count, format string %s requires 1 but format call supplies 2 [TimberArgCount]
Expand Down Expand Up @@ -943,7 +944,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_TYPES)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:5: Error: Wrong argument type for formatting argument '#1' in %d: conversion is 'd', received String (argument #2 in method call) [TimberArgTypes]
Expand Down Expand Up @@ -977,7 +978,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Explicitly logging exception message is redundant [TimberExceptionLogging]
Expand Down Expand Up @@ -1021,7 +1022,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Explicitly logging exception message is redundant [TimberExceptionLogging]
Expand Down Expand Up @@ -1067,7 +1068,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -1092,7 +1093,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand Down Expand Up @@ -1123,7 +1124,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand Down Expand Up @@ -1152,7 +1153,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand Down Expand Up @@ -1181,7 +1182,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -1208,7 +1209,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Use single-argument log method instead of null/empty message [TimberExceptionLogging]
Expand Down Expand Up @@ -1252,7 +1253,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expect("""
|src/foo/Example.java:6: Warning: Use single-argument log method instead of null/empty message [TimberExceptionLogging]
Expand Down Expand Up @@ -1296,7 +1297,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -1321,7 +1322,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_TYPES)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -1346,7 +1347,7 @@ class WrongTimberUsageDetectorTest {
| }
|}""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_TYPES)
.issues(*issues)
.run()
.expectClean()
}
Expand All @@ -1364,7 +1365,7 @@ class WrongTimberUsageDetectorTest {
|}""".trimMargin()),
// no kotlin equivalent, since primitive wrappers do not exist
)
.issues(WrongTimberUsageDetector.ISSUE_ARG_TYPES)
.issues(*issues)
.run()
.expectClean()
}
Expand Down Expand Up @@ -1399,7 +1400,7 @@ class WrongTimberUsageDetectorTest {
|}
""".trimMargin())
)
.issues(WrongTimberUsageDetector.ISSUE_EXCEPTION_LOGGING)
.issues(*issues)
.run()
.expectClean()
}
Expand Down

0 comments on commit 880a2e6

Please sign in to comment.