Skip to content

Commit c72377c

Browse files
authored
Merge pull request #9711 from igfoo/igfoo/integ
Kotlin: Add integration tests
2 parents 41b2357 + 0b312b6 commit c72377c

File tree

120 files changed

+2602
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2602
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
a.kt:
2+
# 0| [CompilationUnit] a
3+
# 1| 1: [Class] A
4+
# 0| 1: [Method] <fn>
5+
# 0| 3: [TypeAccess] int
6+
# 0| 5: [BlockStmt] { ... }
7+
# 0| 0: [ReturnStmt] return ...
8+
# 0| 0: [IntegerLiteral] 42
9+
# 1| 2: [Constructor] A
10+
# 1| 5: [BlockStmt] { ... }
11+
# 1| 0: [SuperConstructorInvocationStmt] super(...)
12+
# 1| 1: [BlockStmt] { ... }
13+
# 2| 3: [Method] f1
14+
# 2| 3: [TypeAccess] int
15+
# 2| 5: [BlockStmt] { ... }
16+
# 2| 0: [ReturnStmt] return ...
17+
# 2| 0: [IntegerLiteral] 1
18+
b.kt:
19+
# 0| [CompilationUnit] b
20+
# 1| 1: [Class] B
21+
# 0| 1: [Method] <fn>
22+
# 0| 3: [TypeAccess] int
23+
# 0| 5: [BlockStmt] { ... }
24+
# 0| 0: [ReturnStmt] return ...
25+
# 0| 0: [UnsafeCoerceExpr] <unsafe coerce>
26+
# 0| 0: [TypeAccess] int
27+
# 0| 1: [IntegerLiteral] 1
28+
# 1| 2: [Constructor] B
29+
# 1| 5: [BlockStmt] { ... }
30+
# 1| 0: [SuperConstructorInvocationStmt] super(...)
31+
# 1| 1: [BlockStmt] { ... }
32+
c.kt:
33+
# 0| [CompilationUnit] c
34+
# 1| 1: [Class] C
35+
# 0| 1: [Method] <fn>
36+
# 0| 3: [TypeAccess] Unit
37+
#-----| 4: (Parameters)
38+
# 0| 0: [Parameter] param
39+
# 0| 0: [TypeAccess] ProcessBuilder
40+
# 0| 5: [BlockStmt] { ... }
41+
# 0| 0: [ReturnStmt] return ...
42+
# 0| 0: [MethodAccess] start(...)
43+
# 0| -1: [VarAccess] param
44+
# 1| 2: [Constructor] C
45+
# 1| 5: [BlockStmt] { ... }
46+
# 1| 0: [SuperConstructorInvocationStmt] super(...)
47+
# 1| 1: [BlockStmt] { ... }
48+
d.kt:
49+
# 0| [CompilationUnit] d
50+
# 1| 1: [Class] D
51+
# 0| 1: [FieldDeclaration] String bar;
52+
# 0| -1: [TypeAccess] String
53+
# 0| 0: [StringLiteral] Foobar
54+
# 1| 3: [Constructor] D
55+
# 1| 5: [BlockStmt] { ... }
56+
# 1| 0: [SuperConstructorInvocationStmt] super(...)
57+
# 1| 1: [BlockStmt] { ... }
58+
e.kt:
59+
# 0| [CompilationUnit] e
60+
# 1| 1: [Class] E
61+
# 0| 1: [Method] <fn_ArrayListAdd>
62+
# 0| 3: [TypeAccess] boolean
63+
# 0| 5: [BlockStmt] { ... }
64+
# 0| 0: [ReturnStmt] return ...
65+
# 0| 0: [MethodAccess] add(...)
66+
# 0| -1: [ClassInstanceExpr] new ArrayList<Object>(...)
67+
# 0| -3: [TypeAccess] ArrayList<Object>
68+
# 0| 0: [IntegerLiteral] 1
69+
# 0| 0: [NullLiteral] null
70+
# 0| 1: [Method] <fn_LinkedHashMap>
71+
# 0| 3: [TypeAccess] Object
72+
# 0| 5: [BlockStmt] { ... }
73+
# 0| 0: [ReturnStmt] return ...
74+
# 0| 0: [MethodAccess] put(...)
75+
# 0| -1: [ClassInstanceExpr] new LinkedHashMap<Object,Object>(...)
76+
# 0| -3: [TypeAccess] LinkedHashMap<Object,Object>
77+
# 0| 0: [IntegerLiteral] 1
78+
# 0| 0: [NullLiteral] null
79+
# 0| 1: [NullLiteral] null
80+
# 1| 3: [Constructor] E
81+
# 1| 5: [BlockStmt] { ... }
82+
# 1| 0: [SuperConstructorInvocationStmt] super(...)
83+
# 1| 1: [BlockStmt] { ... }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
fun f1() = 1
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class B {
2+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
import shutil
5+
import os
6+
import os.path
7+
import sys
8+
import shlex
9+
10+
11+
def run_process(cmd):
12+
try:
13+
print("Running command: " + shlex.join(cmd))
14+
return subprocess.run(cmd, check=True, capture_output=True)
15+
except subprocess.CalledProcessError as e:
16+
print("In: " + os.getcwd(), file=sys.stderr)
17+
print("Command failed: " + shlex.join(cmd), file=sys.stderr)
18+
print("stdout output:\n" + e.stdout.decode(encoding='UTF-8',
19+
errors='strict'), file=sys.stderr)
20+
print("stderr output:\n" + e.stderr.decode(encoding='UTF-8',
21+
errors='strict'), file=sys.stderr)
22+
raise e
23+
24+
root = '../../../../../../../../..'
25+
26+
sys.path.append(root + '/ql/java/kotlin-extractor')
27+
import kotlin_plugin_versions
28+
defaultKotlinDependencyVersion = kotlin_plugin_versions.get_single_version()
29+
30+
builddir = 'build'
31+
dependency_dir = root + '/resources/kotlin-dependencies/'
32+
dependencies = ['kotlin-stdlib-' + defaultKotlinDependencyVersion +
33+
'.jar', 'kotlin-compiler-' + defaultKotlinDependencyVersion + '.jar']
34+
classpath = ':'.join([dependency_dir + dep for dep in dependencies])
35+
srcs = ['plugin/Plugin.kt']
36+
output = 'plugin.jar'
37+
38+
if os.path.exists(builddir):
39+
shutil.rmtree(builddir)
40+
os.makedirs(builddir)
41+
42+
run_process(['kotlinc',
43+
'-J-Xmx2G',
44+
'-d', builddir,
45+
'-module-name', 'test',
46+
'-no-reflect', '-no-stdlib',
47+
'-jvm-target', '1.8',
48+
'-classpath', classpath] + srcs)
49+
50+
run_process(['jar', '-c', '-f', output,
51+
'-C', builddir, '.',
52+
'-C', 'plugin/resources', 'META-INF'])
53+
shutil.rmtree(builddir)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class C { }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class D { }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| CodeQL Kotlin extractor | 2 | | IrProperty without a getter | d.kt:0:0:0:0 | d.kt:0:0:0:0 |
2+
| CodeQL Kotlin extractor | 2 | | Not rewriting trap file for: Boolean -1.0-0- -1.0-0-null test-db/trap/java/classes/kotlin/Boolean.members.trap.gz | file://:0:0:0:0 | file://:0:0:0:0 |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java
2+
3+
from string genBy, int severity, string tag, string msg, Location l
4+
where
5+
diagnostics(_, genBy, severity, tag, msg, _, l) and
6+
(
7+
// Different installations get different sets of these messages,
8+
// so we filter out all but one that happens everywhere.
9+
msg.matches("Not rewriting trap file for: %")
10+
implies
11+
msg.matches("Not rewriting trap file for: Boolean %")
12+
)
13+
select genBy, severity, tag, msg, l
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class E { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| a.kt:0:0:0:0 | <fn> | has body |
2+
| a.kt:2:5:2:16 | f1 | has body |
3+
| b.kt:0:0:0:0 | <fn> | has body |
4+
| c.kt:0:0:0:0 | <fn> | has body |
5+
| d.kt:0:0:0:0 | <clinit> | has body |
6+
| e.kt:0:0:0:0 | <fn_ArrayListAdd> | has body |
7+
| e.kt:0:0:0:0 | <fn_LinkedHashMap> | has body |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java
2+
3+
from Method m, string body
4+
where
5+
m.fromSource() and
6+
if exists(m.getBody()) then body = "has body" else body = "has no body"
7+
select m, body

0 commit comments

Comments
 (0)