Skip to content

Commit

Permalink
✅ METHOD_RETURN and MEMBER tests (#55)
Browse files Browse the repository at this point in the history
* Failing tests for METHOD_RETURN nodes

* MethodReturn tests

* Add MEMBER tests
  • Loading branch information
fabsx00 authored Feb 5, 2021
1 parent 2686e57 commit 3764888
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ object SootToPlumeUtil {
.apply {
// Attach fields to the TypeDecl
cls.fields.forEachIndexed { i, field ->
projectMember(field, i).let { memberVertex ->
projectMember(field, i + 1).let { memberVertex ->
driver.addEdge(this, memberVertex, AST)
addSootToPlumeAssociation(field, memberVertex)
}
Expand Down Expand Up @@ -354,7 +354,7 @@ object SootToPlumeUtil {
childIdx: Int = 0
): NewMethodReturnBuilder =
NewMethodReturnBuilder()
.code("return ${type.toQuotedString()}")
.code("${type.toQuotedString()}")
.evaluationstrategy(determineEvaluationStrategy(type.toQuotedString(), true))
.typefullname(type.toQuotedString())
.linenumber(Option.apply(currentLine))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.plume.oss.querying

import io.github.plume.oss.PlumeCodeToCpgSuite
import io.shiftleft.semanticcpg.language._

class MemberTests extends PlumeCodeToCpgSuite {

override val code =
"""
|class Foo {
| int x;
|}
|""".stripMargin

"should contain MEMBER node with correct properties" in {
val List(x) = cpg.member.l
x.name shouldBe "x"
x.code shouldBe "int x"
x.typeFullName shouldBe "int"
x.order shouldBe 1
}

"should allow traversing from MEMBER to TYPE_DECL" in {
val List(x) = cpg.member.typeDecl.l
x.name shouldBe "Foo"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.plume.oss.querying

import io.github.plume.oss.PlumeCodeToCpgSuite
import io.shiftleft.semanticcpg.language._

class MethodReturnTests extends PlumeCodeToCpgSuite {

override val code =
"""class Foo {
| int foo() { return 1; }
|}
|""".stripMargin

"should have METHOD_RETURN node with correct fields" in {
val List(x) = cpg.methodReturn.code("int").l
x.code shouldBe "int"
x.typeFullName shouldBe "int"
// I think line 2 would be correct but close enough
// given that it's bytecode
x.lineNumber shouldBe Some(1)
// we expect the METHOD_RETURN node to be the right-most
// child so that when traversing the AST from left to
// right in CFG construction, we visit it last.
x.order shouldBe 3
}

"should allow traversing to method" in {
cpg.methodReturn.code("int").method.name.l shouldBe List("foo")
}

}

0 comments on commit 3764888

Please sign in to comment.