-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTesting.qll
More file actions
95 lines (84 loc) · 3.15 KB
/
Testing.qll
File metadata and controls
95 lines (84 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/** Provides classes for working with tests. */
overlay[local?]
module;
import go
/**
* A program element that represents a test case.
*
* Extend this class to refine existing models of testing frameworks. If you want to model new
* frameworks, extend `TestCase::Range` instead.
*/
class TestCase extends AstNode instanceof TestCase::Range { }
/** Provides classes for working with test cases. */
module TestCase {
/**
* A program element that represents a test case.
*
* Extend this class to model new testing frameworks. If you want to refine existing models,
* extend `TestCase` instead.
*/
abstract class Range extends AstNode { }
/** A `go test` style test (including benchmarks and examples). */
private class GoTestFunction extends Range, FuncDef {
GoTestFunction() {
this.getName().regexpMatch("Test(?![a-z]).*") and
this.getNumParameter() = 1 and
this.getParameter(0).getType().(PointerType).getBaseType().hasQualifiedName("testing", "T")
or
this.getName().regexpMatch("Benchmark(?![a-z]).*") and
this.getNumParameter() = 1 and
this.getParameter(0).getType().(PointerType).getBaseType().hasQualifiedName("testing", "B")
or
this.getName().regexpMatch("Example(?![a-z]).*") and
this.getNumParameter() = 0
}
}
}
/**
* A file that contains test cases or is otherwise used for testing.
*
* Extend this class to refine existing models of testing frameworks. If you want to model new
* frameworks, extend `TestFile::Range` instead.
*/
class TestFile extends File instanceof TestFile::Range { }
/** Provides classes for working with test files. */
module TestFile {
/**
* A file that contains test cases or is otherwise used for testing.
*
* Extend this class to model new testing frameworks. If you want to refine existing models,
* extend `TestFile` instead.
*/
abstract class Range extends File { }
/** A file containing at least one test case. */
private class FileContainingTestCases extends Range {
FileContainingTestCases() { this = any(TestCase tc).getFile() }
}
/** A file that imports a well-known testing framework. */
private class FileImportingTestingFramework extends Range {
FileImportingTestingFramework() {
exists(string pkg, ImportSpec is |
is.getPath() = pkg and
is.getFile() = this
|
pkg in [
"gen/thrifttest", package("github.com/golang/mock", "gomock"), Ginkgo::packagePath(),
package("github.com/onsi/gomega", ""),
package("github.com/stretchr/testify", ["assert", "http", "mock", "require", "suite"]),
package("gotest.tools", "assert"), package("k8s.io/client-go", "testing"),
"net/http/httptest", "testing"
]
)
}
}
}
/** Provides classes modeling Ginkgo. */
module Ginkgo {
/** Gets the package path `github.com/onsi/ginkgo`. */
string packagePath() { result = package("github.com/onsi/ginkgo", "") }
/** The Ginkgo `Fail` function, which always panics. */
private class FailFunction extends Function {
FailFunction() { this.hasQualifiedName(packagePath(), "Fail") }
override predicate mustPanic() { any() }
}
}