Skip to content

Commit b33d41c

Browse files
committed
WIP tests
1 parent 0eb6ca4 commit b33d41c

17 files changed

+77187
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
edges
2+
| tst.go:0:0:0:0 | entry | tst.go:3:1:3:12 | skip |
3+
| tst.go:3:1:3:12 | skip | tst.go:5:1:7:1 | skip |
4+
| tst.go:5:1:7:1 | skip | tst.go:9:1:11:1 | skip |
5+
| tst.go:9:1:11:1 | skip | tst.go:13:15:13:20 | skip |
6+
| tst.go:13:1:13:1 | entry | tst.go:13:7:13:7 | argument corresponding to r |
7+
| tst.go:13:1:15:1 | function declaration | tst.go:17:6:17:12 | skip |
8+
| tst.go:13:7:13:7 | argument corresponding to r | tst.go:13:7:13:7 | initialization of r |
9+
| tst.go:13:7:13:7 | initialization of r | tst.go:14:9:14:9 | r |
10+
| tst.go:13:15:13:20 | skip | tst.go:13:1:15:1 | function declaration |
11+
| tst.go:14:2:14:14 | return statement | tst.go:15:1:15:1 | exit |
12+
| tst.go:14:9:14:9 | implicit dereference | tst.go:14:9:14:14 | selection of data |
13+
| tst.go:14:9:14:9 | implicit dereference | tst.go:15:1:15:1 | exit |
14+
| tst.go:14:9:14:9 | r | tst.go:14:9:14:9 | implicit dereference |
15+
| tst.go:14:9:14:14 | selection of data | tst.go:14:2:14:14 | return statement |
16+
| tst.go:17:1:17:1 | entry | tst.go:17:14:17:19 | argument corresponding to source |
17+
| tst.go:17:1:19:1 | function declaration | tst.go:21:6:21:12 | skip |
18+
| tst.go:17:6:17:12 | skip | tst.go:17:1:19:1 | function declaration |
19+
| tst.go:17:14:17:19 | argument corresponding to source | tst.go:17:14:17:19 | initialization of source |
20+
| tst.go:17:14:17:19 | initialization of source | tst.go:18:10:18:26 | struct literal |
21+
| tst.go:18:2:18:26 | return statement | tst.go:19:1:19:1 | exit |
22+
| tst.go:18:9:18:26 | &... | tst.go:18:2:18:26 | return statement |
23+
| tst.go:18:10:18:26 | struct literal | tst.go:18:20:18:25 | source |
24+
| tst.go:18:14:18:25 | init of key-value pair | tst.go:18:9:18:26 | &... |
25+
| tst.go:18:20:18:25 | source | tst.go:18:14:18:25 | init of key-value pair |
26+
| tst.go:21:1:21:1 | entry | tst.go:21:14:21:19 | argument corresponding to source |
27+
| tst.go:21:1:28:1 | function declaration | tst.go:30:6:30:9 | skip |
28+
| tst.go:21:6:21:12 | skip | tst.go:21:1:28:1 | function declaration |
29+
| tst.go:21:14:21:19 | argument corresponding to source | tst.go:21:14:21:19 | initialization of source |
30+
| tst.go:21:14:21:19 | initialization of source | tst.go:22:2:22:2 | skip |
31+
| tst.go:22:2:22:2 | assignment to r | tst.go:23:9:23:12 | skip |
32+
| tst.go:22:2:22:2 | skip | tst.go:22:7:22:13 | getData |
33+
| tst.go:22:7:22:13 | getData | tst.go:22:15:22:20 | source |
34+
| tst.go:22:7:22:21 | call to getData | tst.go:22:2:22:2 | assignment to r |
35+
| tst.go:22:7:22:21 | call to getData | tst.go:28:1:28:1 | exit |
36+
| tst.go:22:15:22:20 | source | tst.go:22:7:22:21 | call to getData |
37+
| tst.go:23:9:23:12 | assignment to data | tst.go:24:7:24:10 | case star expression |
38+
| tst.go:23:9:23:12 | assignment to data | tst.go:27:9:27:10 | "" |
39+
| tst.go:23:9:23:12 | skip | tst.go:23:17:23:17 | r |
40+
| tst.go:23:17:23:17 | r | tst.go:23:17:23:24 | type assertion |
41+
| tst.go:23:17:23:24 | type assertion | tst.go:23:9:23:12 | assignment to data |
42+
| tst.go:24:7:24:10 | case star expression | tst.go:25:10:25:13 | data |
43+
| tst.go:24:7:24:10 | case star expression | tst.go:27:9:27:10 | "" |
44+
| tst.go:25:3:25:22 | return statement | tst.go:28:1:28:1 | exit |
45+
| tst.go:25:10:25:13 | data | tst.go:25:10:25:20 | selection of String |
46+
| tst.go:25:10:25:20 | selection of String | tst.go:25:10:25:22 | call to String |
47+
| tst.go:25:10:25:22 | call to String | tst.go:25:3:25:22 | return statement |
48+
| tst.go:25:10:25:22 | call to String | tst.go:28:1:28:1 | exit |
49+
| tst.go:27:2:27:10 | return statement | tst.go:28:1:28:1 | exit |
50+
| tst.go:27:9:27:10 | "" | tst.go:27:2:27:10 | return statement |
51+
| tst.go:30:1:30:1 | entry | tst.go:31:2:31:10 | skip |
52+
| tst.go:30:1:34:1 | function declaration | tst.go:0:0:0:0 | exit |
53+
| tst.go:30:6:30:9 | skip | tst.go:30:1:34:1 | function declaration |
54+
| tst.go:31:2:31:10 | assignment to sourceStr | tst.go:32:2:32:8 | skip |
55+
| tst.go:31:2:31:10 | skip | tst.go:31:15:31:28 | "Hellow rold!" |
56+
| tst.go:31:15:31:28 | "Hellow rold!" | tst.go:31:2:31:10 | assignment to sourceStr |
57+
| tst.go:32:2:32:8 | assignment to sinkStr | tst.go:33:2:33:12 | selection of Println |
58+
| tst.go:32:2:32:8 | skip | tst.go:32:13:32:19 | process |
59+
| tst.go:32:13:32:19 | process | tst.go:32:21:32:29 | sourceStr |
60+
| tst.go:32:13:32:30 | call to process | tst.go:32:2:32:8 | assignment to sinkStr |
61+
| tst.go:32:13:32:30 | call to process | tst.go:34:1:34:1 | exit |
62+
| tst.go:32:21:32:29 | sourceStr | tst.go:32:13:32:30 | call to process |
63+
| tst.go:33:2:33:12 | selection of Println | tst.go:33:14:33:20 | sinkStr |
64+
| tst.go:33:2:33:21 | call to Println | tst.go:34:1:34:1 | exit |
65+
| tst.go:33:14:33:20 | sinkStr | tst.go:33:2:33:21 | call to Println |
66+
#select
67+
| |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import go
2+
3+
query predicate edges(ControlFlow::Node pred, ControlFlow::Node succ) {
4+
not succ.getFile().hasBuildConstraints() and
5+
not pred.getFile().hasBuildConstraints() and
6+
succ = pred.getASuccessor()
7+
}
8+
9+
select ""
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
| tst.go:0:0:0:0 | entry | tst.go:3:1:3:12 | skip |
2+
| tst.go:3:1:3:12 | skip | tst.go:5:1:7:1 | skip |
3+
| tst.go:5:1:7:1 | skip | tst.go:9:1:11:1 | skip |
4+
| tst.go:9:1:11:1 | skip | tst.go:13:15:13:20 | skip |
5+
| tst.go:13:1:13:1 | entry | tst.go:13:7:13:7 | argument corresponding to r |
6+
| tst.go:13:1:15:1 | function declaration | tst.go:17:6:17:12 | skip |
7+
| tst.go:13:7:13:7 | argument corresponding to r | tst.go:13:7:13:7 | initialization of r |
8+
| tst.go:13:7:13:7 | initialization of r | tst.go:14:9:14:9 | r |
9+
| tst.go:13:15:13:20 | skip | tst.go:13:1:15:1 | function declaration |
10+
| tst.go:14:2:14:14 | return statement | tst.go:15:1:15:1 | exit |
11+
| tst.go:14:9:14:9 | implicit dereference | tst.go:14:9:14:14 | selection of data |
12+
| tst.go:14:9:14:9 | implicit dereference | tst.go:15:1:15:1 | exit |
13+
| tst.go:14:9:14:9 | r | tst.go:14:9:14:9 | implicit dereference |
14+
| tst.go:14:9:14:14 | selection of data | tst.go:14:2:14:14 | return statement |
15+
| tst.go:17:1:17:1 | entry | tst.go:17:14:17:19 | argument corresponding to source |
16+
| tst.go:17:1:19:1 | function declaration | tst.go:21:6:21:12 | skip |
17+
| tst.go:17:6:17:12 | skip | tst.go:17:1:19:1 | function declaration |
18+
| tst.go:17:14:17:19 | argument corresponding to source | tst.go:17:14:17:19 | initialization of source |
19+
| tst.go:17:14:17:19 | initialization of source | tst.go:18:10:18:26 | struct literal |
20+
| tst.go:18:2:18:26 | return statement | tst.go:19:1:19:1 | exit |
21+
| tst.go:18:9:18:26 | &... | tst.go:18:2:18:26 | return statement |
22+
| tst.go:18:10:18:26 | struct literal | tst.go:18:20:18:25 | source |
23+
| tst.go:18:14:18:25 | init of key-value pair | tst.go:18:9:18:26 | &... |
24+
| tst.go:18:20:18:25 | source | tst.go:18:14:18:25 | init of key-value pair |
25+
| tst.go:21:1:21:1 | entry | tst.go:21:14:21:19 | argument corresponding to source |
26+
| tst.go:21:1:28:1 | function declaration | tst.go:30:6:30:9 | skip |
27+
| tst.go:21:6:21:12 | skip | tst.go:21:1:28:1 | function declaration |
28+
| tst.go:21:14:21:19 | argument corresponding to source | tst.go:21:14:21:19 | initialization of source |
29+
| tst.go:21:14:21:19 | initialization of source | tst.go:22:2:22:2 | skip |
30+
| tst.go:22:2:22:2 | assignment to r | tst.go:23:9:23:12 | skip |
31+
| tst.go:22:2:22:2 | skip | tst.go:22:7:22:13 | getData |
32+
| tst.go:22:7:22:13 | getData | tst.go:22:15:22:20 | source |
33+
| tst.go:22:7:22:21 | call to getData | tst.go:22:2:22:2 | assignment to r |
34+
| tst.go:22:7:22:21 | call to getData | tst.go:28:1:28:1 | exit |
35+
| tst.go:22:15:22:20 | source | tst.go:22:7:22:21 | call to getData |
36+
| tst.go:23:9:23:12 | assignment to data | tst.go:24:7:24:10 | case star expression |
37+
| tst.go:23:9:23:12 | assignment to data | tst.go:27:9:27:10 | "" |
38+
| tst.go:23:9:23:12 | skip | tst.go:23:17:23:17 | r |
39+
| tst.go:23:17:23:17 | r | tst.go:23:17:23:24 | type assertion |
40+
| tst.go:23:17:23:24 | type assertion | tst.go:23:9:23:12 | assignment to data |
41+
| tst.go:24:7:24:10 | case star expression | tst.go:25:10:25:13 | data |
42+
| tst.go:24:7:24:10 | case star expression | tst.go:27:9:27:10 | "" |
43+
| tst.go:25:3:25:22 | return statement | tst.go:28:1:28:1 | exit |
44+
| tst.go:25:10:25:13 | data | tst.go:25:10:25:20 | selection of String |
45+
| tst.go:25:10:25:20 | selection of String | tst.go:25:10:25:22 | call to String |
46+
| tst.go:25:10:25:22 | call to String | tst.go:25:3:25:22 | return statement |
47+
| tst.go:25:10:25:22 | call to String | tst.go:28:1:28:1 | exit |
48+
| tst.go:27:2:27:10 | return statement | tst.go:28:1:28:1 | exit |
49+
| tst.go:27:9:27:10 | "" | tst.go:27:2:27:10 | return statement |
50+
| tst.go:30:1:30:1 | entry | tst.go:31:2:31:10 | skip |
51+
| tst.go:30:1:34:1 | function declaration | tst.go:0:0:0:0 | exit |
52+
| tst.go:30:6:30:9 | skip | tst.go:30:1:34:1 | function declaration |
53+
| tst.go:31:2:31:10 | assignment to sourceStr | tst.go:32:2:32:8 | skip |
54+
| tst.go:31:2:31:10 | skip | tst.go:31:15:31:28 | "Hellow rold!" |
55+
| tst.go:31:15:31:28 | "Hellow rold!" | tst.go:31:2:31:10 | assignment to sourceStr |
56+
| tst.go:32:2:32:8 | assignment to sinkStr | tst.go:33:2:33:12 | selection of Println |
57+
| tst.go:32:2:32:8 | skip | tst.go:32:13:32:19 | process |
58+
| tst.go:32:13:32:19 | process | tst.go:32:21:32:29 | sourceStr |
59+
| tst.go:32:13:32:30 | call to process | tst.go:32:2:32:8 | assignment to sinkStr |
60+
| tst.go:32:13:32:30 | call to process | tst.go:34:1:34:1 | exit |
61+
| tst.go:32:21:32:29 | sourceStr | tst.go:32:13:32:30 | call to process |
62+
| tst.go:33:2:33:12 | selection of Println | tst.go:33:14:33:20 | sinkStr |
63+
| tst.go:33:2:33:21 | call to Println | tst.go:34:1:34:1 | exit |
64+
| tst.go:33:14:33:20 | sinkStr | tst.go:33:2:33:21 | call to Println |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import go
2+
3+
from ControlFlow::Node nd
4+
where
5+
// exclude code with build constraints to ensure platform-independent results
6+
not nd.getFile().hasBuildConstraints()
7+
select nd, nd.getASuccessor()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
type Data interface {
4+
String() string
5+
}
6+
7+
type Req struct {
8+
data string
9+
}
10+
11+
func (r *Req) String() string {
12+
return r.data
13+
}
14+
15+
func getData(source string) Data {
16+
return &Req{data: source}
17+
}
18+
19+
func process(source string) string {
20+
r := getData(source)
21+
switch data := r.(type) {
22+
case *Req:
23+
return data.String()
24+
}
25+
return ""
26+
}
27+
28+
func source() string { return "source" }
29+
func sink(s string) {}
30+
31+
func main() {
32+
sink(process(source()))
33+
}

go/ql/test/library-tests/semmle/go/dataflow/Switch/DataFlow.expected

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import go
2+
import TestUtilities.InlineFlowTest
3+
import DefaultFlowTest
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
| file://:0:0:0:0 | function String | tst.go:9:13:9:29 | selection of String |
2+
| tst.go:5:6:5:6 | function f | tst.go:18:19:18:19 | f |
3+
| tst.go:5:8:5:13 | argument corresponding to input1 | tst.go:5:8:5:13 | definition of input1 |
4+
| tst.go:5:8:5:13 | definition of input1 | tst.go:7:23:7:28 | input1 |
5+
| tst.go:6:2:6:8 | definition of output1 | tst.go:13:9:13:9 | output1 = phi(def@11:3, def@6:2, def@9:3) |
6+
| tst.go:6:13:6:14 | "" | tst.go:6:2:6:8 | definition of output1 |
7+
| tst.go:7:9:7:18 | definition of input1Type | tst.go:9:13:9:22 | input1Type |
8+
| tst.go:7:23:7:28 | input1 | tst.go:7:23:7:35 | type assertion |
9+
| tst.go:7:23:7:35 | type assertion | tst.go:7:9:7:18 | definition of input1Type |
10+
| tst.go:9:3:9:9 | definition of output1 | tst.go:13:9:13:9 | output1 = phi(def@11:3, def@6:2, def@9:3) |
11+
| tst.go:9:13:9:31 | call to String | tst.go:9:3:9:9 | definition of output1 |
12+
| tst.go:11:3:11:9 | definition of output1 | tst.go:13:9:13:9 | output1 = phi(def@11:3, def@6:2, def@9:3) |
13+
| tst.go:11:13:11:23 | "Formatter" | tst.go:11:3:11:9 | definition of output1 |
14+
| tst.go:13:9:13:9 | output1 = phi(def@11:3, def@6:2, def@9:3) | tst.go:13:9:13:15 | output1 |
15+
| tst.go:17:2:17:8 | definition of output2 | tst.go:24:9:24:9 | output2 = phi(def@17:2, def@20:3, def@22:3) |
16+
| tst.go:17:13:17:14 | "" | tst.go:17:2:17:8 | definition of output2 |
17+
| tst.go:18:9:18:14 | definition of input2 | tst.go:18:27:18:32 | input2 |
18+
| tst.go:18:9:18:14 | definition of input2 | tst.go:20:13:20:18 | input2 |
19+
| tst.go:18:19:18:24 | call to f | tst.go:18:9:18:14 | definition of input2 |
20+
| tst.go:20:3:20:9 | definition of output2 | tst.go:24:9:24:9 | output2 = phi(def@17:2, def@20:3, def@22:3) |
21+
| tst.go:20:13:20:18 | input2 | tst.go:20:3:20:9 | definition of output2 |
22+
| tst.go:22:3:22:9 | definition of output2 | tst.go:24:9:24:9 | output2 = phi(def@17:2, def@20:3, def@22:3) |
23+
| tst.go:22:13:22:15 | "c" | tst.go:22:3:22:9 | definition of output2 |
24+
| tst.go:24:9:24:9 | output2 = phi(def@17:2, def@20:3, def@22:3) | tst.go:24:9:24:15 | output2 |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import go
2+
3+
from DataFlow::Node nd, DataFlow::Node succ
4+
where DataFlow::localFlowStep(nd, succ)
5+
select nd, succ

0 commit comments

Comments
 (0)