forked from joernio/joern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gosrc2cpg] - Handling for lambda call node for invocation (joernio#3873
) 1. Handling for lambda call node for its invocation along with few more unit tests. 2. Data flow unit tests for the lambda.
- Loading branch information
1 parent
46806ac
commit fa6393b
Showing
5 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ntends/gosrc2cpg/src/test/scala/io/joern/go2cpg/dataflow/AnonymousFuncDataflowTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.joern.go2cpg.dataflow | ||
|
||
import io.joern.dataflowengineoss.language.* | ||
import io.joern.go2cpg.testfixtures.GoCodeToCpgSuite | ||
import io.shiftleft.semanticcpg.language.* | ||
|
||
class AnonymousFuncDataflowTests extends GoCodeToCpgSuite(withOssDataflow = true) { | ||
"Simple Lambda expression dataflow" should { | ||
val cpg = code(""" | ||
|package main | ||
| | ||
|import "fmt" | ||
| | ||
|func main() { | ||
| // Define a lambda function and assign it to a variable | ||
| add := func(a, b int) int { | ||
| println(a) | ||
| return a + b | ||
| } | ||
| | ||
| // Call the lambda function | ||
| result := add(3, 5) | ||
| fmt.Println("Result:", result) // Output: 8 | ||
|} | ||
|""".stripMargin) | ||
"work dataflow within lambda from parameter to println sink" in { | ||
val source = cpg.identifier("a") | ||
val sink = cpg.call("println") | ||
sink.reachableByFlows(source).size shouldBe 1 | ||
} | ||
|
||
"work dataflow from literal parameter passed to lambda invocation to println sink" in { | ||
val source = cpg.literal("3") | ||
val sink = cpg.call("println") | ||
sink.reachableByFlows(source).size shouldBe 1 | ||
} | ||
|
||
"work dataflow from literal parameter passed to lambda invocation to outside println sink" in { | ||
val source = cpg.literal("3") | ||
val sink = cpg.call("Println") | ||
sink.reachableByFlows(source).size shouldBe 1 | ||
} | ||
} | ||
|
||
} |
5 changes: 3 additions & 2 deletions
5
...-cli/frontends/gosrc2cpg/src/test/scala/io/joern/go2cpg/dataflow/ArrayDataflowTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters