@@ -27,16 +27,59 @@ module TestCase {
2727 /** A `go test` style test (including benchmarks and examples). */
2828 private class GoTestFunction extends Range , FuncDef {
2929 GoTestFunction ( ) {
30- getName ( ) .regexpMatch ( "Test[^ a-z].*" ) and
30+ getName ( ) .regexpMatch ( "Test(?![ a-z]) .*" ) and
3131 getNumParameter ( ) = 1 and
3232 getParameter ( 0 ) .getType ( ) .( PointerType ) .getBaseType ( ) .hasQualifiedName ( "testing" , "T" )
3333 or
34- getName ( ) .regexpMatch ( "Benchmark[^ a-z].*" ) and
34+ getName ( ) .regexpMatch ( "Benchmark(?![ a-z]) .*" ) and
3535 getNumParameter ( ) = 1 and
3636 getParameter ( 0 ) .getType ( ) .( PointerType ) .getBaseType ( ) .hasQualifiedName ( "testing" , "B" )
3737 or
38- getName ( ) .regexpMatch ( "Example[^ a-z].*" ) and
38+ getName ( ) .regexpMatch ( "Example(?![ a-z]) .*" ) and
3939 getNumParameter ( ) = 0
4040 }
4141 }
4242}
43+
44+ /**
45+ * A file that contains test cases or is otherwise used for testing.
46+ *
47+ * Extend this class to refine existing models of testing frameworks. If you want to model new
48+ * frameworks, extend `TestFile::Range` instead.
49+ */
50+ class TestFile extends File {
51+ TestFile:: Range self ;
52+
53+ TestFile ( ) { this = self }
54+ }
55+
56+ /** Provides classes for working with test files. */
57+ module TestFile {
58+ /**
59+ * A file that contains test cases or is otherwise used for testing.
60+ *
61+ * Extend this class to model new testing frameworks. If you want to refine existing models,
62+ * extend `TestFile` instead.
63+ */
64+ abstract class Range extends File { }
65+
66+ /** A file containing at least one test case. */
67+ private class FileContainingTestCases extends Range {
68+ FileContainingTestCases ( ) { this = any ( TestCase tc ) .getFile ( ) }
69+ }
70+
71+ /** A file that imports a well-known testing framework. */
72+ private class FileImportingTestingFramework extends Range {
73+ FileImportingTestingFramework ( ) {
74+ exists ( string pkg , ImportSpec is |
75+ is .getPath ( ) = pkg and
76+ is .getFile ( ) = this
77+ |
78+ pkg = "net/http/httptest" or
79+ pkg = "gen/thrifttest" or
80+ pkg = "github.com/onsi/ginkgo" or
81+ pkg = "github.com/onsi/gomega"
82+ )
83+ }
84+ }
85+ }
0 commit comments