mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Python: Add 2/3 specific query tests.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
| test.py:5:11:5:11 | x | x may have a different value in Python 3, as the $@ will not be in scope. | test.py:4:12:4:12 | x | list comprehension variable |
|
||||
| test.py:10:11:10:11 | y | y may have a different value in Python 3, as the $@ will not be in scope. | test.py:9:12:9:12 | y | list comprehension variable |
|
||||
@@ -0,0 +1 @@
|
||||
Variables/LeakingListComprehension.ql
|
||||
49
python/ql/test/2/query-tests/Variables/LeakyComp/test.py
Normal file
49
python/ql/test/2/query-tests/Variables/LeakyComp/test.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from __future__ import print_function
|
||||
|
||||
def undefined_in_3():
|
||||
[x for x in range(3)]
|
||||
print(x)
|
||||
|
||||
def different_in_3():
|
||||
y = 10
|
||||
[y for y in range(3)]
|
||||
print(y)
|
||||
|
||||
def ok():
|
||||
[z for z in range(4)]
|
||||
|
||||
#FP observed in sembuild
|
||||
def use_in_loop(seq):
|
||||
[x for x in range(3)]
|
||||
for x in seq:
|
||||
use(x) #x redefined -- fine in 2 and 3.
|
||||
|
||||
def test_6395(dev):
|
||||
ret = {}
|
||||
|
||||
res = foo(dev)
|
||||
if not res:
|
||||
return False
|
||||
|
||||
for line in res.splitlines(): # pylint: disable=no-member
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
key, val = [val.strip() for val in bar(line)]
|
||||
if not (key and val):
|
||||
continue
|
||||
|
||||
mval = None
|
||||
if ' ' in val:
|
||||
rval, mval = [val.strip() for val in bar(val)]
|
||||
mval = mval[1:-1]
|
||||
else:
|
||||
rval = val
|
||||
|
||||
return ret
|
||||
|
||||
def test_6441(seq):
|
||||
for var in seq:
|
||||
foo(var)
|
||||
[var for var in bar()]
|
||||
@@ -0,0 +1,4 @@
|
||||
| UndefinedExport.py:3:18:3:20 | Str | The name 'y' is exported by __all__ but is not defined. |
|
||||
| UndefinedExport.py:3:23:3:25 | Str | The name 'z' is exported by __all__ but is not defined. |
|
||||
| UndefinedExport.py:3:28:3:35 | Str | The name 'module' is exported by __all__ but is not defined. |
|
||||
| package/__init__.py:1:23:1:34 | Str | The name 'not_exists' is exported by __all__ but is not defined. |
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
__all__ = [ "x", "y", "z", "module" ]
|
||||
|
||||
x = 1
|
||||
if 0:
|
||||
y = 2
|
||||
|
||||
import package.module
|
||||
@@ -0,0 +1 @@
|
||||
Variables/UndefinedExport.ql
|
||||
@@ -0,0 +1 @@
|
||||
Variables/UndefinedGlobal.ql
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
def const_xrange():
|
||||
for i in xrange(4):
|
||||
x = i
|
||||
return x
|
||||
|
||||
def rec1(a):
|
||||
if a > 0:
|
||||
rec1(a - 1)
|
||||
|
||||
def rec2(b):
|
||||
[rec2(b - 1) for c in range(b)]
|
||||
@@ -0,0 +1 @@
|
||||
Variables/UninitializedLocal.ql
|
||||
1
python/ql/test/2/query-tests/Variables/undefined/options
Normal file
1
python/ql/test/2/query-tests/Variables/undefined/options
Normal file
@@ -0,0 +1 @@
|
||||
semmle-extractor-options: --max-import-depth=2
|
||||
@@ -0,0 +1 @@
|
||||
__all__ = [ "module", "not_exists" ]
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from other import setup
|
||||
|
||||
execfile('x/_version.py')
|
||||
|
||||
setup(
|
||||
name='x',
|
||||
version=__version__
|
||||
)
|
||||
Reference in New Issue
Block a user