Skip to content

Commit 5e8185a

Browse files
committed
Port test to inline expectations test
1 parent 704cd8a commit 5e8185a

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.go:6:2:6:33 | ... := ...[0] |
2-
| test.go:15:2:15:51 | ... := ...[0] |
3-
| test.go:24:2:24:37 | ... := ...[0] |
1+
testFailures
2+
invalidModelRow
3+
failures

go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/file/test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package test
33
import "os"
44

55
func open() {
6-
file, err := os.Open("file.txt")
6+
file, err := os.Open("file.txt") // $ source
77
if err != nil {
88
return
99
}
@@ -12,7 +12,7 @@ func open() {
1212
}
1313

1414
func openFile() {
15-
file, err := os.OpenFile("file.txt", os.O_RDWR, 0)
15+
file, err := os.OpenFile("file.txt", os.O_RDWR, 0) // $source
1616
if err != nil {
1717
return
1818
}
@@ -21,7 +21,7 @@ func openFile() {
2121
}
2222

2323
func readFile() {
24-
data, err := os.ReadFile("file.txt")
24+
data, err := os.ReadFile("file.txt") // $source
2525
if err != nil {
2626
return
2727
}
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import go
2+
import ModelValidation
3+
import TestUtilities.InlineExpectationsTest
24

3-
from DataFlow::Node source
4-
where source instanceof ThreatModelFlowSource
5-
select source
5+
module SourceTest implements TestSig {
6+
string getARelevantTag() { result = "source" }
7+
8+
predicate hasActualResult(Location location, string element, string tag, string value) {
9+
exists(ThreatModelFlowSource s |
10+
s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
11+
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
12+
element = s.toString() and
13+
value = "" and
14+
tag = "source"
15+
)
16+
}
17+
}
18+
19+
import MakeTest<SourceTest>

0 commit comments

Comments
 (0)