Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Add failing ESSA use-use test #10998

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
41 changes: 41 additions & 0 deletions python/ql/test/library-tests/essa/ssa-compute/UseUse.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import python
import semmle.python.essa.SsaCompute
import TestUtilities.InlineExpectationsTest

class UseTest extends InlineExpectationsTest {
UseTest() { this = "UseTest" }

override string getARelevantTag() { result in ["use-use", "def-use", "def"] }

override predicate hasActualResult(Location location, string element, string tag, string value) {
exists(location.getFile().getRelativePath()) and
exists(string name | name in ["x", "y"] |
exists(NameNode nodeTo, Location prevLoc |
(
exists(NameNode nodeFrom | AdjacentUses::adjacentUseUse(nodeFrom, nodeTo) |
prevLoc = nodeFrom.getLocation() and
name = nodeFrom.getId() and
tag = "use-use"
)
or
exists(EssaVariable var | AdjacentUses::firstUse(var, nodeTo) |
prevLoc = var.getLocation() and
name = var.getName() and
tag = "def-use"
)
) and
value = name + ":" + prevLoc.getStartLine() and
location = nodeTo.getLocation() and
element = nodeTo.toString()
)
or
exists(EssaVariable var | AdjacentUses::firstUse(var, _) |
value = var.getName() and
location = var.getLocation() and
element = var.getName() and
name = var.getName() and
tag = "def"
)
)
}
}
20 changes: 20 additions & 0 deletions python/ql/test/library-tests/essa/ssa-compute/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class X(object):
def foo(self, *args):
print("X.foo", args)


def func(cond=True):
x = X() # $ def=x

print(x) # $ def-use=x:7

y = x # $ def=y use-use=x:9
print(y) # $ def-use=y:11

x.foo() # $ use-use=x:11

x.foo(1 if cond else 0) # $ use-use=x:14
x.foo() # $ MISSING: use-use=x:16
print(x) # $ use-use=x:17

func()