Skip to content

Commit

Permalink
Add test to ensure that #4448 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Jan 31, 2022
1 parent 414fda3 commit 5c370c3
Showing 1 changed file with 31 additions and 0 deletions.
Expand Up @@ -386,5 +386,36 @@ class ForbiddenMethodCallSpec : Spek({
assertThat(findings).isEmpty()
}
}

context("Should distinguish between runCatching - #4448") {
val code = """
package org.example
class A {
fun foo() {
kotlin.runCatching {}
runCatching {}
}
}
"""

it("forbid the one without receiver") {
val findings = ForbiddenMethodCall(
TestConfig(mapOf(METHODS to listOf("kotlin.runCatching(() -> R)")))
).compileAndLintWithContext(env, code)
assertThat(findings)
.hasSize(1)
.hasSourceLocation(5, 16)
}

it("forbid the one with receiver") {
val findings = ForbiddenMethodCall(
TestConfig(mapOf(METHODS to listOf("kotlin.runCatching(T, (T) -> R)")))
).compileAndLintWithContext(env, code)
assertThat(findings)
.hasSize(1)
.hasSourceLocation(6, 9)
}
}
}
})

0 comments on commit 5c370c3

Please sign in to comment.