mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
Kotlin: Add library-tests/controlflow/paths test (copied from Java)
This commit is contained in:
49
java/ql/test/kotlin/library-tests/controlflow/paths/A.kt
Normal file
49
java/ql/test/kotlin/library-tests/controlflow/paths/A.kt
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 |
|
||||
14
java/ql/test/kotlin/library-tests/controlflow/paths/paths.ql
Normal file
14
java/ql/test/kotlin/library-tests/controlflow/paths/paths.ql
Normal 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
|
||||
Reference in New Issue
Block a user