Skip to content

Commit 81e71c4

Browse files
committed
Kotlin: Add a test for double niterception
1 parent 6e75df4 commit 81e71c4

File tree

9 files changed

+43
-0
lines changed

9 files changed

+43
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import glob
4+
import re
5+
from create_database_utils import *
6+
7+
# This is a normal intercepted compilation
8+
runSuccessfully([get_cmd('kotlinc'), 'normal.kt'])
9+
10+
# Find the extractor jar that is being used
11+
trapDir = os.environ['CODEQL_EXTRACTOR_JAVA_TRAP_DIR']
12+
invocationTraps = glob.glob('invocations/*.trap', root_dir = trapDir)
13+
if len(invocationTraps) != 1:
14+
raise Exception('Expected to find 1 invocation TRAP, but found ' + str(invocationTraps))
15+
invocationTrap = trapDir + '/' + invocationTraps[0]
16+
with open(invocationTrap, 'r') as f:
17+
content = f.read()
18+
m = re.search('^// Using extractor: (.*)$', content, flags = re.MULTILINE)
19+
extractorJar = m.group(1)
20+
21+
def getManualFlags(invocationTrapName):
22+
return ['-Xplugin=' + extractorJar, '-P', 'plugin:kotlin-extractor:invocationTrapFile=' + trapDir + '/invocations/' + invocationTrapName + '.trap']
23+
24+
# This is both normally intercepted, and it has the extractor flags manually added
25+
runUnsuccessfully([get_cmd('kotlinc'), 'doubleIntercepted.kt'] + getManualFlags('doubleIntercepted'))
26+
os.environ['CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN'] = 'true'
27+
# We don't see this compilation at all
28+
runSuccessfully([get_cmd('kotlinc'), 'notSeen.kt'])
29+
# This is extracted as it has the extractor flags manually added
30+
runSuccessfully([get_cmd('kotlinc'), 'manual.kt'] + getManualFlags('manual'))

java/ql/integration-tests/all-platforms/kotlin/kotlin_double_interception/code/doubleIntercepted.kt

Whitespace-only changes.

java/ql/integration-tests/all-platforms/kotlin/kotlin_double_interception/code/manual.kt

Whitespace-only changes.

java/ql/integration-tests/all-platforms/kotlin/kotlin_double_interception/code/manuallyIntercepted.kt

Whitespace-only changes.

java/ql/integration-tests/all-platforms/kotlin/kotlin_double_interception/code/normal.kt

Whitespace-only changes.

java/ql/integration-tests/all-platforms/kotlin/kotlin_double_interception/code/notSeen.kt

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| code/manual.kt:0:0:0:0 | manual |
2+
| code/normal.kt:0:0:0:0 | normal |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import java
2+
3+
from File f
4+
select f
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
from create_database_utils import *
4+
5+
run_codeql_database_create(
6+
['"%s" build.py' % sys.executable],
7+
source="code", lang="java")

0 commit comments

Comments
 (0)