Kotlin: Add library-tests/controlflow/paths test (copied from Java)

This commit is contained in:
Ian Lynagh
2021-10-27 13:22:23 +01:00
parent e755cc92b6
commit d05643fa88
3 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
public class A {
fun action() { }
fun always_dom1() {
action()
}
fun always_dom2(b: Boolean) {
if (b) { } else { }
action()
}
fun always_path(b: Boolean) {
if (b) {
action()
} else {
action()
}
}
fun always_w_call(b1: Boolean, b2: Boolean) {
if (b1) {
action()
} else if (b2) {
always_dom2(b1)
} else {
always_path(b2)
}
}
fun not_always_none() {
}
fun not_always_one(b: Boolean) {
if (b) {
action()
}
}
fun not_always_two(b1: Boolean, b2: Boolean) {
if (b1) {
if (b2) {
action()
} else {
action()
}
}
}
}

View File

@@ -0,0 +1,4 @@
| A.kt:4:3:6:3 | always_dom1 |
| A.kt:8:3:11:3 | always_dom2 |
| A.kt:13:3:19:3 | always_path |
| A.kt:21:3:29:3 | always_w_call |

View File

@@ -0,0 +1,14 @@
import java
import semmle.code.java.controlflow.Paths
class PathTestConf extends ActionConfiguration {
PathTestConf() { this = "PathTestConf" }
override predicate isAction(ControlFlowNode node) {
node.(MethodAccess).getMethod().hasName("action")
}
}
from Callable c, PathTestConf conf
where conf.callableAlwaysPerformsAction(c)
select c